diff --git a/NEWS b/NEWS index 0b61a430..7c6be54f 100644 --- a/NEWS +++ b/NEWS @@ -10,6 +10,7 @@ ncmpcpp-0.8 (????-??-??) * Lyrics can now be fetched for songs with no tags. * libcurl dependency is no longer optional. * When an attempt to write tags fails, show detailed error message. +* Support for fetching lyrics for selected items in background was added. ncmpcpp-0.7.7 (2016-10-31) * Fixed compilation on 32bit platforms. diff --git a/doc/bindings b/doc/bindings index db132cc7..468f5ad3 100644 --- a/doc/bindings +++ b/doc/bindings @@ -520,6 +520,9 @@ # toggle_lyrics_fetcher # #def_key "F" +# fetch_lyrics_in_background +# +#def_key "alt-l" # toggle_fetching_lyrics_in_background # #def_key "ctrl-l" diff --git a/src/actions.cpp b/src/actions.cpp index fb338445..5ee283f7 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -2273,6 +2273,20 @@ void ToggleMediaLibrarySortMode::run() myLibrary->toggleSortMode(); } +bool FetchLyricsInBackground::canBeRun() +{ + m_hs = dynamic_cast(myScreen); + return m_hs != nullptr && m_hs->itemAvailable(); +} + +void FetchLyricsInBackground::run() +{ + auto songs = m_hs->getSelectedSongs(); + for (const auto &s : songs) + myLyrics->fetchInBackground(s, true); + Statusbar::print("Selected songs queued for lyrics fetching"); +} + bool RefetchLyrics::canBeRun() { return myScreen == myLyrics; @@ -2785,6 +2799,7 @@ void populateActions() insert_action(new Actions::ToggleBrowserSortMode()); insert_action(new Actions::ToggleLibraryTagType()); insert_action(new Actions::ToggleMediaLibrarySortMode()); + insert_action(new Actions::FetchLyricsInBackground()); insert_action(new Actions::RefetchLyrics()); insert_action(new Actions::SetSelectedItemsPriority()); insert_action(new Actions::ToggleOutput()); diff --git a/src/actions.h b/src/actions.h index 18141313..bfe32934 100644 --- a/src/actions.h +++ b/src/actions.h @@ -137,6 +137,7 @@ enum class Type ToggleBrowserSortMode, ToggleLibraryTagType, ToggleMediaLibrarySortMode, + FetchLyricsInBackground, RefetchLyrics, SetSelectedItemsPriority, ToggleOutput, @@ -1163,6 +1164,18 @@ private: virtual void run() override; }; +struct FetchLyricsInBackground: BaseAction +{ + FetchLyricsInBackground() + : BaseAction(Type::FetchLyricsInBackground, "fetch_lyrics_in_background") { } + +private: + virtual bool canBeRun() override; + virtual void run() override; + + HasSongs *m_hs; +}; + struct RefetchLyrics: BaseAction { RefetchLyrics(): BaseAction(Type::RefetchLyrics, "refetch_lyrics") { } diff --git a/src/bindings.cpp b/src/bindings.cpp index 7642406f..b1765fa1 100644 --- a/src/bindings.cpp +++ b/src/bindings.cpp @@ -721,6 +721,8 @@ void BindingsConfiguration::generateDefaults() if (notBound(k = stringToKey("L"))) bind(k, Actions::Type::ToggleLyricsFetcher); if (notBound(k = stringToKey("F"))) + bind(k, Actions::Type::FetchLyricsInBackground); + if (notBound(k = stringToKey("alt-l"))) bind(k, Actions::Type::ToggleFetchingLyricsInBackground); if (notBound(k = stringToKey("ctrl-l"))) bind(k, Actions::Type::ToggleScreenLock); diff --git a/src/help.cpp b/src/help.cpp index 065a74bb..e7d9fafd 100644 --- a/src/help.cpp +++ b/src/help.cpp @@ -230,6 +230,7 @@ void write_bindings(NC::Scrollpad &w) key(w, Type::JumpToPositionInSong, "Jump to given position in playing song (formats: mm:ss, x%)"); key(w, Type::ShowSongInfo, "Show song info"); key(w, Type::ShowArtistInfo, "Show artist info"); + key(w, Type::FetchLyricsInBackground, "Fetch lyrics for selected songs"); key(w, Type::ToggleLyricsFetcher, "Toggle lyrics fetcher"); key(w, Type::ToggleFetchingLyricsInBackground, "Toggle fetching lyrics for playing songs in background"); key(w, Type::ShowLyrics, "Show/hide song lyrics");