diff --git a/doc/config b/doc/config index 6de2890d..7922f1f6 100644 --- a/doc/config +++ b/doc/config @@ -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 diff --git a/doc/ncmpcpp.1 b/doc/ncmpcpp.1 index 9c640378..7fe42739 100644 --- a/doc/ncmpcpp.1 +++ b/doc/ncmpcpp.1 @@ -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 diff --git a/src/lyrics.cpp b/src/lyrics.cpp index a681a9e1..5cd3a5b6 100644 --- a/src/lyrics.cpp +++ b/src/lyrics.cpp @@ -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 diff --git a/src/lyrics.h b/src/lyrics.h index 066fdc71..c2922ad6 100644 --- a/src/lyrics.h +++ b/src/lyrics.h @@ -63,8 +63,9 @@ class Lyrics : public Screen private: void Load(); + void SetFilename(); std::string itsFilename; - static const std::string Folder; + std::string itsFolder; # ifdef HAVE_CURL_CURL_H void *Download(); diff --git a/src/settings.cpp b/src/settings.cpp index 54c00887..c297bf47 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -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"; diff --git a/src/settings.h b/src/settings.h index 8954484e..b1a7700a 100644 --- a/src/settings.h +++ b/src/settings.h @@ -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;