diff options
| author | sumuel <samuel@yakubos.org> | 2026-08-17 20:44:55 +0000 |
|---|---|---|
| committer | sumuel <samuel@yakubos.org> | 2026-08-17 20:44:55 +0000 |
| commit | 76424950e373d3b04ac3dd13019151bfba3e8423 (patch) | |
| tree | 4c3cfdbda039e592b9186be3e28f8d7cfd439e8a /src/detection/media/media.c | |
Add the files
Diffstat (limited to 'src/detection/media/media.c')
| -rw-r--r-- | src/detection/media/media.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/detection/media/media.c b/src/detection/media/media.c new file mode 100644 index 0000000..7adfb99 --- /dev/null +++ b/src/detection/media/media.c @@ -0,0 +1,45 @@ +#include "media.h" +#include "common/io.h" + +void ffDetectMediaImpl(FFMediaResult* media, bool saveCover); + +static FFMediaResult result; + +static void removeMediaCoverFile(void) { + if (result.cover.length > 0) { + ffRemoveFile(result.cover.chars); + ffStrbufDestroy(&result.cover); + } +} + +const FFMediaResult* ffDetectMedia(bool saveCover) { + if (result.error.chars == NULL) { + ffStrbufInit(&result.error); + ffStrbufInit(&result.playerId); + ffStrbufInit(&result.player); + ffStrbufInit(&result.song); + ffStrbufInit(&result.artist); + ffStrbufInit(&result.album); + ffStrbufInit(&result.url); + ffStrbufInit(&result.status); + ffStrbufInit(&result.cover); + result.length = 0; + result.position = 0; + result.removeCoverAfterUse = false; + ffDetectMediaImpl(&result, saveCover); + + if (result.song.length == 0 && result.error.length == 0) { + ffStrbufAppendS(&result.error, "No media found"); + } + ffStrbufTrimRightSpace(&result.song); + ffStrbufTrimRightSpace(&result.artist); + ffStrbufTrimRightSpace(&result.album); + ffStrbufTrimRightSpace(&result.player); + + if (saveCover && result.removeCoverAfterUse) { + atexit(removeMediaCoverFile); + } + } + + return &result; +} |