diff --git a/src/lyrics_fetcher.cpp b/src/lyrics_fetcher.cpp index 6eb0add9..77600897 100644 --- a/src/lyrics_fetcher.cpp +++ b/src/lyrics_fetcher.cpp @@ -18,6 +18,7 @@ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ +#include "config.h" #include "curl_handle.h" #ifdef HAVE_CURL_CURL_H @@ -26,6 +27,7 @@ #include #include #include +#include #include "charset.h" #include "lyrics_fetcher.h" @@ -35,16 +37,10 @@ LyricsFetcher *lyricsPlugins[] = { new LyricwikiFetcher(), - new LyricsvipFetcher(), new Sing365Fetcher(), - new LoloLyricsFetcher(), - new LyriczzFetcher(), - new SonglyricsFetcher(), new LyricsmaniaFetcher(), - new LyricstimeFetcher(), new MetrolyricsFetcher(), new JustSomeLyricsFetcher(), - new LyrcComArFetcher(), new InternetLyricsFetcher(), 0 }; @@ -56,7 +52,7 @@ LyricsFetcher::Result LyricsFetcher::fetch(const std::string &artist, const std: Result result; result.first = false; - std::string url = getURL(); + std::string url = this->url(); boost::replace_all(url, "%artist%", artist.c_str()); boost::replace_all(url, "%title%", title.c_str()); @@ -69,35 +65,40 @@ LyricsFetcher::Result LyricsFetcher::fetch(const std::string &artist, const std: return result; } - bool parse_ok = getContent(getOpenTag(), getCloseTag(), data); + auto lyrics = getContent(regex(), data); - if (!parse_ok || notLyrics(data)) + if (lyrics.empty() || notLyrics(data)) { result.second = msgNotFound; return result; } - postProcess(data); + data.clear(); + for (auto it = lyrics.begin(); it != lyrics.end(); ++it) + { + postProcess(*it); + if (!it->empty()) + { + data += *it; + if (it != lyrics.end()-1) + data += "\n\n----------\n\n"; + } + } result.second = data; result.first = true; return result; } -bool LyricsFetcher::getContent(const char *open_tag, const char *close_tag, std::string &data) +std::vector LyricsFetcher::getContent(const char *regex, const std::string &data) { - size_t a, b; - if ((a = data.find(open_tag)) != std::string::npos) - { - a += strlen(open_tag); - if ((b = data.find(close_tag, a)) != std::string::npos) - data = data.substr(a, b-a); - else - return false; - } - else - return false; - return true; + std::vector result; + boost::regex rx(regex); + auto first = boost::sregex_iterator(data.begin(), data.end(), rx); + auto last = boost::sregex_iterator(); + for (; first != last; ++first) + result.push_back(first->str(1)); + return result; } void LyricsFetcher::postProcess(std::string &data) @@ -124,23 +125,36 @@ LyricsFetcher::Result LyricwikiFetcher::fetch(const std::string &artist, const s return result; } - bool parse_ok = getContent("'17'/>", "