[spotify] Set missing values for year, artwork, type, codectype,

description and improve logging
This commit is contained in:
chme 2017-01-07 07:22:40 +01:00
parent ab3582dd69
commit f632789f8b
3 changed files with 42 additions and 3 deletions

View File

@ -2155,6 +2155,11 @@ map_track_to_mfi(const struct spotify_track *track, struct media_file_info* mfi)
mfi->song_length = track->duration_ms;
mfi->track = track->track_number;
mfi->compilation = track->is_compilation;
mfi->artwork = ARTWORK_SPOTIFY;
mfi->type = strdup("spotify");
mfi->codectype = strdup("wav");
mfi->description = strdup("Spotify audio");
}
static void
@ -2164,6 +2169,7 @@ map_album_to_mfi(const struct spotify_album *album, struct media_file_info* mfi)
mfi->album_artist = safe_strdup(album->artist);
mfi->genre = safe_strdup(album->genre);
mfi->compilation = album->is_compilation;
mfi->year = album->release_year;
}
/* Thread: library */
@ -2178,8 +2184,10 @@ scan_saved_albums()
struct media_file_info mfi;
int dir_id;
int i;
int count;
int ret;
count = 0;
memset(&request, 0, sizeof(struct spotify_request));
while (0 == spotifywebapi_request_next(&request, SPOTIFY_WEBAPI_SAVED_ALBUMS))
@ -2215,6 +2223,10 @@ scan_saved_albums()
}
db_transaction_end();
count++;
if (count >= request.total || (count % 10 == 0))
DPRINTF(E_LOG, L_SPOTIFY, "Scanned %d of %d saved albums\n", count, request.total);
}
}
@ -2273,14 +2285,16 @@ scan_playlists()
struct spotify_playlist playlist;
char virtual_path[PATH_MAX];
int plid;
int count;
count = 0;
memset(&request, 0, sizeof(struct spotify_request));
while (0 == spotifywebapi_request_next(&request, SPOTIFY_WEBAPI_SAVED_PLAYLISTS))
{
while (0 == spotifywebapi_playlists_fetch(&request, &playlist))
{
DPRINTF(E_DBG, L_SPOTIFY, "Got playlist: '%s' (%s) \n", playlist.name, playlist.uri);
DPRINTF(E_DBG, L_SPOTIFY, "Got playlist: '%s' with %d tracks (%s) \n", playlist.name, playlist.tracks_count, playlist.uri);
db_transaction_begin();
@ -2301,6 +2315,10 @@ scan_playlists()
DPRINTF(E_LOG, L_SPOTIFY, "Error adding playlist: '%s' (%s) \n", playlist.name, playlist.uri);
db_transaction_end();
count++;
if (count >= request.total || (count % 10 == 0))
DPRINTF(E_LOG, L_SPOTIFY, "Scanned %d of %d saved playlists\n", count, request.total);
}
}
@ -2328,7 +2346,7 @@ scan_playlist(const char *uri)
}
else
{
DPRINTF(E_DBG, L_SPOTIFY, "Got playlist: '%s' (%s) \n", playlist.name, playlist.uri);
DPRINTF(E_DBG, L_SPOTIFY, "Got playlist: '%s' with %d tracks (%s) \n", playlist.name, playlist.tracks_count, playlist.uri);
db_transaction_begin();

View File

@ -414,7 +414,7 @@ spotifywebapi_request_uri(struct spotify_request *request, const char *uri)
return -1;
}
//DPRINTF(E_DBG, L_SPOTIFY, "Wep api response for '%s'\n%s\n", uri, request->response_body);
// DPRINTF(E_DBG, L_SPOTIFY, "Wep api response for '%s'\n%s\n", uri, request->response_body);
request->haystack = json_tokener_parse(request->response_body);
if (!request->haystack)
@ -510,6 +510,22 @@ track_metadata(json_object* jsontrack, struct spotify_track* track)
track->id = jparse_str_from_obj(jsontrack, "id");
}
static int
get_year_from_releasdate(const char *release_date)
{
char tmp[5];
uint32_t year = 0;
if (release_date && strlen(release_date) >= 4)
{
strncpy(tmp, release_date, sizeof(tmp));
tmp[4] = '\0';
safe_atou32(tmp, &year);
}
return year;
}
void
album_metadata(json_object *jsonalbum, struct spotify_album *album)
{
@ -527,7 +543,10 @@ album_metadata(json_object *jsonalbum, struct spotify_album *album)
album->is_compilation = (album->album_type && 0 == strcmp(album->album_type, "compilation"));
album->label = jparse_str_from_obj(jsonalbum, "label");
album->release_date = jparse_str_from_obj(jsonalbum, "release_date");
album->release_date_precision = jparse_str_from_obj(jsonalbum, "release_date_precision");
album->release_year = get_year_from_releasdate(album->release_date);
// TODO Genre is an array of strings ('genres'), but it is always empty (https://github.com/spotify/web-api/issues/157)
//album->genre = jparse_str_from_obj(jsonalbum, "genre");

View File

@ -47,6 +47,8 @@ struct spotify_album
const char *label;
const char *name;
const char *release_date;
const char *release_date_precision;
int release_year;
const char *uri;
};