From b2f29c67568dd126a5d364fea6ff020f090c271d Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Sat, 28 Jan 2017 16:33:09 +0100 Subject: [PATCH] lastfm: fix fetching artist info in language other than English --- NEWS | 3 ++- src/lastfm_service.cpp | 12 ++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index 3d8c1069..060cef97 100644 --- a/NEWS +++ b/NEWS @@ -19,7 +19,8 @@ ncmpcpp-0.8 (????-??-??) * Lyrics and last_fm can now be startup screens and are lockable. * Action 'update_environment' now also synchronizes status with MPD. * Fixed an issue that could cause some MPD events to be missed. -* ACtion 'jump_to_playing_song' is not runnable now if there is no playing song. +* Action 'jump_to_playing_song' is not runnable now if there is no playing song. +* Fixed fetching artist info in language other than English. ncmpcpp-0.7.7 (2016-10-31) * Fixed compilation on 32bit platforms. diff --git a/src/lastfm_service.cpp b/src/lastfm_service.cpp index 59d4941c..57b96cd1 100644 --- a/src/lastfm_service.cpp +++ b/src/lastfm_service.cpp @@ -20,6 +20,7 @@ #include "lastfm_service.h" +#include #include #include #include @@ -52,7 +53,7 @@ Service::Result Service::fetch() url += "="; url += Curl::escape(arg.second); } - + std::string data; CURLcode code = Curl::perform(data, url); @@ -63,7 +64,7 @@ Service::Result Service::fetch() else { result = processData(data); - + // if relevant part of data was not found and one of arguments // was language, try to fetch it again without that parameter. // otherwise just report failure. @@ -118,6 +119,10 @@ Service::Result ArtistInfo::processData(const std::string &data) std::string url = what[1], wiki; // unescape &s unescapeHtmlEntities(url); + // fill in language info since url points to english version. + const auto &lang = m_arguments["lang"]; + if (!lang.empty()) + boost::replace_first(url, "last.fm/music/", "last.fm/" + lang + "/music/"); // ...try to get the content of it... CURLcode code = Curl::perform(wiki, url, "", true); @@ -145,7 +150,10 @@ Service::Result ArtistInfo::processData(const std::string &data) result.second += desc; } else + { result.second += "No description available for this artist."; + return result; + } } else {