lyrics: restore database selector
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -24,13 +24,14 @@
|
||||
#include "ncmpcpp.h"
|
||||
#include "mpdpp.h"
|
||||
#include "screen.h"
|
||||
#include "lyrics_fetcher.h"
|
||||
|
||||
class Lyrics : public Screen<Scrollpad>
|
||||
{
|
||||
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<Scrollpad>
|
||||
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<Scrollpad>
|
||||
bool ReadyToTake;
|
||||
bool DownloadInProgress;
|
||||
pthread_t Downloader;
|
||||
LyricsFetcher **Fetcher;
|
||||
# endif // HAVE_CURL_CURL_H
|
||||
|
||||
size_t itsScrollBegin;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user