lyrics: add support for storing lyrics in song's directory

This commit is contained in:
Andrzej Rybczak
2010-08-17 16:58:48 +02:00
parent c97f4fac59
commit c0e558f04b
6 changed files with 53 additions and 7 deletions

View File

@@ -287,6 +287,8 @@
#
#follow_now_playing_lyrics = "no"
#
#store_lyrics_in_song_dir = "no"
#
##
## Note: If you set this variable, ncmpcpp will try to
## get info from last.fm in language you set and if it

View File

@@ -219,6 +219,9 @@ If enabled, seek time will increment by one each second of seeking.
.B follow_now_playing_lyrics = yes/no
If enabled, lyrics will be switched at song's change to currently playing one's (Note: this works only if you are viewing lyrics of item from Playlist).
.TP
.B store_lyrics_in_song_dir = yes/no
If enabled, lyrics will be saved in song's directory, otherwise in ~/.lyrics. Note that it needs properly set mpd_music_dir.
.TP
.B lastfm_preferred_language = ISO 639 alpha-2 language code
If set, ncmpcpp will try to get info from last.fm in language you set and if it fails, it will fall back to english. Otherwise it will use english the first time.
.TP

View File

@@ -48,13 +48,12 @@ using Global::MainStartY;
using Global::myScreen;
using Global::myOldScreen;
const std::string Lyrics::Folder = home_path + LYRICS_FOLDER;
Lyrics *myLyrics = new Lyrics;
void Lyrics::Init()
{
w = new Scrollpad(0, MainStartY, COLS, MainHeight, "", Config.main_color, brNone);
itsFolder = home_path + LYRICS_FOLDER;
isInitialized = 1;
}
@@ -180,6 +179,37 @@ void *Lyrics::Download()
}
#endif // HAVE_CURL_CURL_H
void Lyrics::SetFilename()
{
if (Config.store_lyrics_in_song_dir)
{
if (itsSong.isFromDB())
{
itsFilename = Config.mpd_music_dir;
itsFilename += "/";
itsFilename += itsSong.GetFile();
}
else
itsFilename = itsSong.GetFile();
// replace song's extension with .txt
size_t dot = itsFilename.rfind('.');
assert(dot != std::string::npos);
itsFilename.resize(dot);
itsFilename += ".txt";
}
else
{
std::string file = locale_to_utf_cpy(itsSong.GetArtist());
file += " - ";
file += locale_to_utf_cpy(itsSong.GetTitle());
file += ".txt";
EscapeUnallowedChars(file);
itsFilename = itsFolder;
itsFilename += "/";
itsFilename += file;
}
}
void Lyrics::Load()
{
# ifdef HAVE_CURL_CURL_H
@@ -191,11 +221,9 @@ void Lyrics::Load()
assert(!itsSong.GetTitle().empty());
itsSong.Localize();
std::string file = locale_to_utf_cpy(itsSong.GetArtist()) + " - " + locale_to_utf_cpy(itsSong.GetTitle()) + ".txt";
EscapeUnallowedChars(file);
itsFilename = Folder + "/" + file;
SetFilename();
mkdir(Folder.c_str()
mkdir(itsFolder.c_str()
# ifndef WIN32
, 0755
# endif // !WIN32

View File

@@ -63,8 +63,9 @@ class Lyrics : public Screen<Scrollpad>
private:
void Load();
void SetFilename();
std::string itsFilename;
static const std::string Folder;
std::string itsFolder;
# ifdef HAVE_CURL_CURL_H
void *Download();

View File

@@ -410,6 +410,7 @@ void NcmpcppConfig::SetDefaults()
media_library_display_date = true;
media_library_disable_two_column_mode = false;
discard_colors_if_item_is_selected = true;
store_lyrics_in_song_dir = false;
set_window_title = true;
mpd_port = 6600;
mpd_connection_timeout = 15;
@@ -1047,6 +1048,16 @@ void NcmpcppConfig::Read()
{
discard_colors_if_item_is_selected = v == "yes";
}
else if (cl.find("store_lyrics_in_song_dir") != std::string::npos)
{
if (mpd_music_dir.empty())
{
std::cout << "Warning: store_lyrics_in_song_dir = \"yes\" is ";
std::cout << "not allowed without mpd_music_dir set, discarding.\n";
}
else
store_lyrics_in_song_dir = v == "yes";
}
else if (cl.find("enable_window_title") != std::string::npos)
{
set_window_title = v == "yes";

View File

@@ -248,6 +248,7 @@ struct NcmpcppConfig
bool media_library_display_date;
bool media_library_disable_two_column_mode;
bool discard_colors_if_item_is_selected;
bool store_lyrics_in_song_dir;
int mpd_port;
int mpd_connection_timeout;