diff --git a/src/detection/media/media.c b/src/detection/media/media.c index 1e5a38bc5..3c1288fe1 100644 --- a/src/detection/media/media.c +++ b/src/detection/media/media.c @@ -1,11 +1,21 @@ #include "media.h" +#include "common/io/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) { - static FFMediaResult result; - if (result.error.chars == NULL) { ffStrbufInit(&result.error); @@ -26,6 +36,9 @@ const FFMediaResult* ffDetectMedia(bool saveCover) ffStrbufTrimRightSpace(&result.artist); ffStrbufTrimRightSpace(&result.album); ffStrbufTrimRightSpace(&result.player); + + if (saveCover && result.removeCoverAfterUse) + atexit(removeMediaCoverFile); } return &result; diff --git a/src/logo/logo.c b/src/logo/logo.c index 02ff36c9c..f1b89e1d6 100644 --- a/src/logo/logo.c +++ b/src/logo/logo.c @@ -475,16 +475,6 @@ static bool logoPrintData(bool doColorReplacement, FFstrbuf* source) return true; } -static void removeMediaCoverFile(void) -{ - const FFMediaResult* media = ffDetectMedia(true); - if (media->cover.length > 0) - { - ffRemoveFile(media->cover.chars); - ffStrbufDestroy((FFstrbuf*) &media->cover); - } -} - static bool updateLogoPath(void) { FFOptionsLogo* options = &instance.config.logo; @@ -501,7 +491,6 @@ static bool updateLogoPath(void) if (media->cover.length == 0) return false; ffStrbufSet(&options->source, &media->cover); - if (media->removeCoverAfterUse) atexit(removeMediaCoverFile); return true; }