[vlc-devel] [PATCH 1/2] Differentiate between song and album art cover in fetcher

Samo Golež samo.golez at outlook.com
Fri Feb 19 13:34:47 UTC 2021


---
 src/preparser/fetcher.c | 36 ++++++++++++++++++++++++++----------
 src/preparser/fetcher.h |  6 ++++++
 2 files changed, 32 insertions(+), 10 deletions(-)

diff --git a/src/preparser/fetcher.c b/src/preparser/fetcher.c
index 6fe6036..b34b438 100644
--- a/src/preparser/fetcher.c
+++ b/src/preparser/fetcher.c
@@ -144,7 +144,7 @@ Submit(input_fetcher_t *fetcher, vlc_executor_t *executor, input_item_t *item,
     return VLC_SUCCESS;
 }
 
-static char* CreateCacheKey( input_item_t* item )
+static char* CreateCacheKey( input_item_t* item, enum artType atype )
 {
     vlc_mutex_lock( &item->lock );
 
@@ -169,6 +169,18 @@ static char* CreateCacheKey( input_item_t* item )
     {
         key = NULL;
     }
+
+    if (key && atype == SONG)
+    {
+        char const *arturl = vlc_meta_Get( item->p_meta, vlc_meta_ArtworkURL );
+        char const *title = vlc_meta_Get( item->p_meta, vlc_meta_Title );
+
+        if( !arturl || !title || asprintf( &key, "%s:%zu:%s:%zu",
+            arturl, strlen( arturl ), title, strlen( title ) ) < 0 )
+        {
+            key = NULL;
+        }
+    }
     vlc_mutex_unlock( &item->lock );
 
     return key;
@@ -180,9 +192,9 @@ static void FreeCacheEntry( void* data, void* obj )
     VLC_UNUSED( obj );
 }
 
-static int ReadAlbumCache( input_fetcher_t* fetcher, input_item_t* item )
+static int ReadCache( input_fetcher_t* fetcher, input_item_t* item, enum artType atype )
 {
-    char* key = CreateCacheKey( item );
+    char* key = CreateCacheKey( item, atype );
 
     if( key == NULL )
         return VLC_EGENERIC;
@@ -198,11 +210,11 @@ static int ReadAlbumCache( input_fetcher_t* fetcher, input_item_t* item )
     return art ? VLC_SUCCESS : VLC_EGENERIC;
 }
 
-static void AddAlbumCache( input_fetcher_t* fetcher, input_item_t* item,
-                           bool overwrite )
+static void AddCache( input_fetcher_t* fetcher, input_item_t* item,
+                           enum artType atype, bool overwrite )
 {
     char* art = input_item_GetArtURL( item );
-    char* key = CreateCacheKey( item );
+    char* key = CreateCacheKey( item, atype );
 
     if( key && art && strncasecmp( art, "attachment://", 13 ) )
     {
@@ -278,12 +290,14 @@ static int SearchByScope(struct task *task, int scope)
     }
 
     if( ! CheckArt( item )                         ||
-        ! ReadAlbumCache( fetcher, item )          ||
+        ! ReadCache( fetcher, item, ALBUM )        ||
++       ! ReadCache( fetcher, item, SONG )         ||
         ! input_FindArtInCacheUsingItemUID( item ) ||
         ! input_FindArtInCache( item )             ||
         ! SearchArt( fetcher, item, scope ) )
     {
-        AddAlbumCache( fetcher, task->item, false );
+        AddCache( fetcher, task->item, SONG, false );
+        AddCache( fetcher, task->item, ALBUM, false );
         int ret = Submit(fetcher, fetcher->executor_downloader, item,
                          task->options, task->cbs, task->userdata);
         if (ret == VLC_SUCCESS)
@@ -306,7 +320,8 @@ static void RunDownloader(void *userdata)
 
     vlc_interrupt_set(&task->interrupt);
 
-    ReadAlbumCache( fetcher, task->item );
+    if ( ReadCache( fetcher, task->item, SONG ) != VLC_SUCCESS )
+        ReadCache( fetcher, task->item, ALBUM );
 
     char *psz_arturl = input_item_GetArtURL( task->item );
     if( !psz_arturl )
@@ -351,7 +366,8 @@ static void RunDownloader(void *userdata)
                    output_stream.length, NULL );
 
     free( output_stream.ptr );
-    AddAlbumCache( fetcher, task->item, true );
+    AddCache( fetcher, task->item, SONG, true );
+    AddCache( fetcher, task->item, ALBUM, true );
 
 out:
     vlc_interrupt_set(NULL);
diff --git a/src/preparser/fetcher.h b/src/preparser/fetcher.h
index 680386a..92dd306 100644
--- a/src/preparser/fetcher.h
+++ b/src/preparser/fetcher.h
@@ -26,6 +26,12 @@
 
 #include <vlc_input_item.h>
 
+enum artType
+{
+    ALBUM,
+    SONG,
+};
+
 /**
  * Fetcher opaque structure.
  *
-- 
2.27.0



More information about the vlc-devel mailing list