[tracker-miners/sam/libav-testing: 7/12] tracker-extract-libav: Fix missing audio info




commit 52a7acbbab81177680c1c316468038899e48de52
Author: Sam Thursfield <sam thursfield codethink co uk>
Date:   Wed Aug 31 11:43:49 2022 +0200

    tracker-extract-libav: Fix missing audio info
    
    The extractor tests were failing with the ffmpeg/libav backend as
    nie:title wasn't extracted from Vorbis files. The issue is the TITLE
    tag is part of the audio stream metadata, but the extractor only looked
    on the container metadata.
    
    Resolved, with a separate codepath for music vs video.

 src/tracker-extract/tracker-extract-libav.c | 90 ++++++++++++++++++-----------
 1 file changed, 57 insertions(+), 33 deletions(-)
---
diff --git a/src/tracker-extract/tracker-extract-libav.c b/src/tracker-extract/tracker-extract-libav.c
index 61db416e5..2dabcdd1c 100644
--- a/src/tracker-extract/tracker-extract-libav.c
+++ b/src/tracker-extract/tracker-extract-libav.c
@@ -54,12 +54,14 @@ extract_audio_info(TrackerResource *metadata,
 }
 
 static void
-extract_video_info(TrackerResource *metadata,
+extract_video_info(gchar           *uri,
+                   TrackerResource *metadata,
                    AVFormatContext *format,
                    AVStream        *video_stream)
 {
        g_autofree char *content_created = NULL;
        AVDictionaryEntry *tag = NULL;
+       const char *title = NULL;
 
        tracker_resource_add_uri(metadata, "rdf:type", "nmm:Video");
 
@@ -108,16 +110,40 @@ extract_video_info(TrackerResource *metadata,
                        tracker_resource_set_string (metadata, "nie:contentCreated", content_created);
                }
        }
+
+       if ((tag = av_dict_get (format->metadata, "comment", NULL, 0))) {
+               tracker_resource_set_string (metadata, "nie:comment", tag->value);
+       }
+
+       if ((tag = av_dict_get (format->metadata, "copyright", NULL, 0))) {
+               tracker_resource_set_string (metadata, "nie:copyright", tag->value);
+       }
+
+       if ((tag = av_dict_get (format->metadata, "description", NULL, 0))) {
+               tracker_resource_set_string (metadata, "nie:description", tag->value);
+       }
+
+       if ((tag = av_dict_get (format->metadata, "genre", NULL, 0))) {
+               tracker_resource_set_string (metadata, "nfo:genre", tag->value);
+       }
+
+       if ((tag = av_dict_get (format->metadata, "title", NULL, 0))) {
+               title = tag->value;
+       }
+
+       tracker_guarantee_resource_title_from_file (metadata, "nie:title", title, uri, NULL);
 }
 
 static void
-extract_music_piece_info(TrackerResource *metadata,
-                         AVFormatContext *format,
-                         AVStream        *audio_stream)
+extract_music_piece_info (const gchar     *uri,
+                          TrackerResource *metadata,
+                          AVFormatContext *format,
+                          AVStream        *audio_stream)
 {
        g_autoptr(TrackerResource) album_artist = NULL, artist = NULL, performer = NULL;
-       char *album_artist_name = NULL;
-       char *album_title = NULL;
+       const char *album_artist_name = NULL;
+       const char *album_title = NULL;
+       const char *title = NULL;
        g_autofree char *content_created = NULL;
        AVDictionaryEntry *tag = NULL;
 
@@ -154,7 +180,7 @@ extract_music_piece_info(TrackerResource *metadata,
                performer = tracker_extract_new_artist (tag->value);
        }
 
-       if ((tag = av_dict_get (format->metadata, "date", NULL, 0))) {
+       if ((tag = find_tag (format, audio_stream, "date"))) {
                content_created = tracker_date_guess (tag->value);
                if (content_created) {
                        tracker_resource_set_string (metadata, "nie:contentCreated", content_created);
@@ -188,6 +214,28 @@ extract_music_piece_info(TrackerResource *metadata,
                tracker_resource_set_relation (metadata, "nmm:musicAlbumDisc", album_disc);
                tracker_resource_set_relation (metadata, "nmm:musicAlbum", 
tracker_resource_get_first_relation (album_disc, "nmm:albumDiscAlbum"));
        }
+
+       if ((tag = find_tag (format, audio_stream, "comment"))) {
+               tracker_resource_set_string (metadata, "nie:comment", tag->value);
+       }
+
+       if ((tag = find_tag (format, audio_stream, "copyright"))) {
+               tracker_resource_set_string (metadata, "nie:copyright", tag->value);
+       }
+
+       if ((tag = find_tag (format, audio_stream, "description"))) {
+               tracker_resource_set_string (metadata, "nie:description", tag->value);
+       }
+
+       if ((tag = find_tag (format, audio_stream, "genre"))) {
+               tracker_resource_set_string (metadata, "nfo:genre", tag->value);
+       }
+
+       if ((tag = find_tag (format, audio_stream, "title"))) {
+               title = tag->value;
+       }
+
+       tracker_guarantee_resource_title_from_file (metadata, "nie:title", title, uri, NULL);
 }
 
 G_MODULE_EXPORT gboolean
@@ -203,8 +251,6 @@ tracker_extract_get_metadata (TrackerExtractInfo  *info,
        AVStream *video_stream = NULL;
        int audio_stream_index;
        int video_stream_index;
-       AVDictionaryEntry *tag = NULL;
-       const char *title = NULL;
 
        file = tracker_extract_info_get_file (info);
 
@@ -245,37 +291,15 @@ tracker_extract_get_metadata (TrackerExtractInfo  *info,
        }
 
        if (video_stream && !(video_stream->disposition & AV_DISPOSITION_ATTACHED_PIC)) {
-               extract_video_info (metadata, format, video_stream);
+               extract_video_info (uri, metadata, format, video_stream);
        } else if (audio_stream) {
-               extract_music_piece_info (metadata, format, audio_stream);
+               extract_music_piece_info (uri, metadata, format, audio_stream);
        }
 
        if (format->bit_rate > 0) {
                tracker_resource_set_int64 (metadata, "nfo:averageBitrate", format->bit_rate);
        }
 
-       if ((tag = av_dict_get (format->metadata, "comment", NULL, 0))) {
-               tracker_resource_set_string (metadata, "nie:comment", tag->value);
-       }
-
-       if ((tag = av_dict_get (format->metadata, "copyright", NULL, 0))) {
-               tracker_resource_set_string (metadata, "nie:copyright", tag->value);
-       }
-
-       if ((tag = av_dict_get (format->metadata, "description", NULL, 0))) {
-               tracker_resource_set_string (metadata, "nie:description", tag->value);
-       }
-
-       if ((tag = av_dict_get (format->metadata, "genre", NULL, 0))) {
-               tracker_resource_set_string (metadata, "nfo:genre", tag->value);
-       }
-
-       if ((tag = av_dict_get (format->metadata, "title", NULL, 0))) {
-               title = tag->value;
-       }
-
-       tracker_guarantee_resource_title_from_file (metadata, "nie:title", title, uri, NULL);
-
        g_free (uri);
 
        avformat_close_input (&format);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]