From e1b1cf838ae0860ce39a1901e8c3c1ad1f081a95 Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Tue, 10 Aug 2010 20:39:08 +0200 Subject: [PATCH] lyrics: restore database selector --- src/lyrics.cpp | 25 ++++++++++++++++++++++--- src/lyrics.h | 7 ++++++- src/ncmpcpp.cpp | 6 ++++++ 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/lyrics.cpp b/src/lyrics.cpp index 20af43eb..a19d51ff 100644 --- a/src/lyrics.cpp +++ b/src/lyrics.cpp @@ -33,7 +33,6 @@ #include "global.h" #include "helpers.h" #include "lyrics.h" -#include "lyrics_fetcher.h" #include "playlist.h" #include "settings.h" #include "song.h" @@ -145,7 +144,10 @@ void *Lyrics::Download() LyricsFetcher::Result result; - for (LyricsFetcher **plugin = lyricsPlugins; *plugin != 0; ++plugin) + // if one of plugins is selected, try only this one, + // otherwise try all of them until one of them succeeds + bool fetcher_defined = Fetcher && *Fetcher; + for (LyricsFetcher **plugin = fetcher_defined ? Fetcher : lyricsPlugins; *plugin != 0; ++plugin) { *w << "Fetching lyrics from " << fmtBold << (*plugin)->name() << fmtBoldEnd << "... "; result = (*plugin)->fetch(artist, title); @@ -153,6 +155,8 @@ void *Lyrics::Download() *w << clRed << result.second << clEnd << "\n"; else break; + if (fetcher_defined) + break; } if (result.first == true) @@ -261,7 +265,10 @@ void Lyrics::Save(const std::string &lyrics) void Lyrics::Refetch() { - std::string path = Folder + "/" + locale_to_utf_cpy(itsSong.GetArtist()) + " - " + locale_to_utf_cpy(itsSong.GetTitle()) + ".txt"; + std::string file = locale_to_utf_cpy(itsSong.GetArtist()) + " - " + locale_to_utf_cpy(itsSong.GetTitle()) + ".txt"; + EscapeUnallowedChars(file); + std::string path = Folder + "/" + file; + if (!remove(path.c_str())) { Load(); @@ -274,6 +281,18 @@ void Lyrics::Refetch() } #ifdef HAVE_CURL_CURL_H +void Lyrics::ToggleFetcher() +{ + if (Fetcher && *Fetcher) + ++Fetcher; + else + Fetcher = &lyricsPlugins[0]; + if (*Fetcher) + ShowMessage("Using lyrics database: %s", (*Fetcher)->name()); + else + ShowMessage("Using all lyrics databases"); +} + void Lyrics::Take() { assert(ReadyToTake); diff --git a/src/lyrics.h b/src/lyrics.h index 3b440ced..6105c18e 100644 --- a/src/lyrics.h +++ b/src/lyrics.h @@ -24,13 +24,14 @@ #include "ncmpcpp.h" #include "mpdpp.h" #include "screen.h" +#include "lyrics_fetcher.h" class Lyrics : public Screen { public: Lyrics() : ReloadNP(0), # ifdef HAVE_CURL_CURL_H - ReadyToTake(0), DownloadInProgress(0), + ReadyToTake(0), DownloadInProgress(0), Fetcher(0), # endif // HAVE_CURL_CURL_H itsScrollBegin(0) { } @@ -53,6 +54,9 @@ class Lyrics : public Screen void Edit(); void Save(const std::string &lyrics); void Refetch(); +# ifdef HAVE_CURL_CURL_H + void ToggleFetcher(); +# endif // HAVE_CURL_CURL_H bool ReloadNP; @@ -73,6 +77,7 @@ class Lyrics : public Screen bool ReadyToTake; bool DownloadInProgress; pthread_t Downloader; + LyricsFetcher **Fetcher; # endif // HAVE_CURL_CURL_H size_t itsScrollBegin; diff --git a/src/ncmpcpp.cpp b/src/ncmpcpp.cpp index 05de53c4..75168ff6 100644 --- a/src/ncmpcpp.cpp +++ b/src/ncmpcpp.cpp @@ -1334,6 +1334,12 @@ int main(int argc, char *argv[]) Config.playlist_separate_albums = !Config.playlist_separate_albums; ShowMessage("Separators between albums in playlist: %s", Config.playlist_separate_albums ? "On" : "Off"); } +# ifdef HAVE_CURL_CURL_H + else if (Keypressed(input, Key.ToggleLyricsDB)) + { + myLyrics->ToggleFetcher(); + } +# endif // HAVE_CURL_CURL_H else if (Keypressed(input, Key.ToggleAutoCenter)) { Config.autocenter_mode = !Config.autocenter_mode;