From 1ee40116ece90a5504cd33a23d6bc7002d00b68a Mon Sep 17 00:00:00 2001
From: Ian Whyman <ian.whyman@spin.pm>
Date: Tue, 8 Mar 2022 17:36:37 +0000
Subject: [PATCH] Fix default tag matches with ffmpeg_handler

Some of the keys were uppercase e.g. ARTIST when returned from the FLAC
parser, so lowercase the keys first.

Fixes: https://github.com/gerbera/gerbera/issues/2176
---
 src/metadata/ffmpeg_handler.cc | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

--- a/src/metadata/ffmpeg_handler.cc
+++ b/src/metadata/ffmpeg_handler.cc
@@ -93,8 +93,9 @@ void FfmpegHandler::addFfmpegMetadataFie
     auto sc = StringConverter::m2i(CFG_IMPORT_LIBOPTS_FFMPEG_CHARSET, item->getLocation(), config);
 
     while ((e = av_dict_get(pFormatCtx->metadata, "", e, AV_DICT_IGNORE_SUFFIX))) {
-        std::string key = e->key;
+        std::string key = toLower(e->key);
         std::string value = e->value;
+        log_debug("FFMpeg tag: {}: {}", key, value);
         auto it = specialPropertyMap.find(e->key);
         if (it != specialPropertyMap.end()) {
             // only use ffmpeg meta data if not found by other handler
@@ -105,7 +106,9 @@ void FfmpegHandler::addFfmpegMetadataFie
             }
         }
         auto pIt = std::find_if(propertyMap.begin(), propertyMap.end(),
-            [&](auto&& p) { return p.second == key && item->getMetaData(p.first).empty(); });
+            [&](auto&& p) {
+                return p.second == key && item->getMetaData(p.first).empty();
+            });
         if (pIt != propertyMap.end()) {
             log_debug("Identified default metadata '{}': {}", pIt->second, value);
             const auto field = pIt->first;
@@ -128,7 +131,7 @@ void FfmpegHandler::addFfmpegMetadataFie
             constexpr auto field = M_CREATION_DATE;
             if (item->getMetaData(field).empty()) {
                 log_debug("Identified metadata 'creation_time': {}", e->value);
-                std::tm tmWork;
+                std::tm tmWork {};
                 if (strptime(e->value, "%Y-%m-%dT%T.000000%Z", &tmWork)) {
                     // convert creation_time to local time
                     auto utcTime = timegm(&tmWork);
