[grilo-plugins] magnatune: Add cover art support
- From: Victor Toso de Carvalho <victortoso src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [grilo-plugins] magnatune: Add cover art support
- Date: Sat, 31 Mar 2018 19:39:44 +0000 (UTC)
commit 81076c6da54599acd814e2ce628fb6e2208cbed5
Author: Jean Felder <jfelder src gnome org>
Date: Sat Mar 31 13:41:57 2018 +0200
magnatune: Add cover art support
It follows the specifications defined at:
http://magnatune.com/info/sqlite-normalized
https://bugzilla.gnome.org/show_bug.cgi?id=794845
Signed-off-by: Victor Toso <me victortoso com>
src/magnatune/grl-magnatune.c | 42 ++++++++++++++++++++++++++++++++++++----
1 files changed, 37 insertions(+), 5 deletions(-)
---
diff --git a/src/magnatune/grl-magnatune.c b/src/magnatune/grl-magnatune.c
index ebd7239..8bd381b 100644
--- a/src/magnatune/grl-magnatune.c
+++ b/src/magnatune/grl-magnatune.c
@@ -107,10 +107,16 @@ GRL_LOG_DOMAIN_STATIC(magnatune_log_domain);
/* --- URLs --- */
-#define URL_GET_DB "http://he3.magnatune.com/info/sqlite_normalized.db"
-#define URL_GET_CRC "http://magnatune.com/info/changed.txt"
+#define URL_GET_DB "http://he3.magnatune.com/info/sqlite_normalized.db"
+#define URL_GET_CRC "http://magnatune.com/info/changed.txt"
-#define URL_SONG_PLAY "http://he3.magnatune.com/all"
+#define URL_SONG_PLAY "http://he3.magnatune.com/all"
+#define URL_SONG_COVER "http://he3.magnatune.com/music"
+
+/* --- Cover Art --- */
+
+#define URL_SONG_COVER_FORMAT URL_SONG_COVER "/%s/%s/cover_%d.jpg"
+static gint cover_art_sizes[] = { 50, 75, 100, 160, 200, 300, 600, 1400 };
/* --- Other --- */
@@ -592,6 +598,12 @@ magnatune_check_update(void)
g_free(new_db_path);
}
+static void
+add_cover (gpointer url_to_cover, gpointer media)
+{
+ grl_media_add_thumbnail((GrlMedia *) media, url_to_cover);
+}
+
static GrlMedia *
build_media(gint track_id,
@@ -600,7 +612,8 @@ build_media(gint track_id,
const gchar *track_name,
gint track_number,
gint duration,
- const gchar *url_to_mp3)
+ const gchar *url_to_mp3,
+ GPtrArray *url_to_covers)
{
GrlMedia *media = NULL;
gchar *str_track_id = NULL;
@@ -613,6 +626,8 @@ build_media(gint track_id,
grl_media_set_duration(media, duration);
grl_media_set_title(media, track_name);
+ g_ptr_array_foreach(url_to_covers, add_cover, media);
+
str_track_id = g_strdup_printf("%d", track_id);
grl_media_set_id(media, str_track_id);
g_free(str_track_id);
@@ -625,6 +640,7 @@ build_media_track_from_stmt(sqlite3_stmt *sql_stmt)
{
GrlMedia *media = NULL;
+ gint i;
gint track_id;
gint duration;
gint track_number;
@@ -634,6 +650,9 @@ build_media_track_from_stmt(sqlite3_stmt *sql_stmt)
const gchar *raw_url;
gchar *encoded_url;
gchar *url_to_mp3;
+ gchar *encoded_artist;
+ gchar *encoded_album;
+ GPtrArray *url_to_covers;
track_id = (guint) sqlite3_column_int(sql_stmt, MAGNATUNE_TRACK_ID);
artist_name = (gchar *) sqlite3_column_text(sql_stmt, MAGNATUNE_ARTIST_NAME);
@@ -645,11 +664,24 @@ build_media_track_from_stmt(sqlite3_stmt *sql_stmt)
encoded_url = g_uri_escape_string(raw_url, "", FALSE);
url_to_mp3 = g_strdup_printf("%s/%s", URL_SONG_PLAY, encoded_url);
+
+ encoded_artist = g_uri_escape_string(artist_name, "", FALSE);
+ encoded_album = g_uri_escape_string(album_name, "", FALSE);
+ url_to_covers = g_ptr_array_new();
+ for (i = 0; i < G_N_ELEMENTS(cover_art_sizes); i++) {
+ gchar *cover = g_strdup_printf(URL_SONG_COVER_FORMAT, encoded_artist,
+ encoded_album, cover_art_sizes[i]);
+ g_ptr_array_add(url_to_covers, cover);
+ }
+
media = build_media(track_id, artist_name, album_name, track_name,
- track_number, duration, url_to_mp3);
+ track_number, duration, url_to_mp3, url_to_covers);
g_free(encoded_url);
g_free(url_to_mp3);
+ g_free(encoded_artist);
+ g_free(encoded_album);
+ g_ptr_array_free(url_to_covers, TRUE);
return media;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]