summaryrefslogtreecommitdiffstats
path: root/src/detection/media/media.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/detection/media/media.c')
-rw-r--r--src/detection/media/media.c45
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;
+}