Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
for potentially improved bottom part of the spectrum visualizer in terminals
with transparent background.
* Add support for fetching lyrics from tags.
* Add `exclude_pattern` option to a configuration file.

# ncmpcpp-0.9.2 (2021-01-24)
* Revert suppression of output of all external commands as that makes e.g album
Expand Down
9 changes: 7 additions & 2 deletions doc/config
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,15 @@
#
#mpd_crossfade_time = 5
#
# Exclude pattern for random song action
# http://www.boost.org/doc/libs/1_46_1/libs/regex/doc/html/boost_regex/syntax/perl_syntax.html
# Exclude pattern for random song action. Applied to song's file path.
# http://www.boost.org/doc/libs/1_83_0/libs/regex/doc/html/boost_regex/syntax/perl_syntax.html
#random_exclude_pattern = "^(temp|midi_songs).*"
#
# Exclude pattern for random song/tag action, search engine, media library (but not browser!)
# Applied to song's file path.
# http://www.boost.org/doc/libs/1_83_0/libs/regex/doc/html/boost_regex/syntax/perl_syntax.html
#exclude_pattern = "^(temp|incoming)/.*"
#
##### music visualizer #####
##
## In order to make music visualizer work with MPD you need to use the fifo
Expand Down
4 changes: 2 additions & 2 deletions src/actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2250,9 +2250,9 @@ void AddRandomItems::run()
{
bool success;
if (rnd_type == 's')
success = Mpd.AddRandomSongs(number, Config.random_exclude_pattern, Global::RNG);
success = Mpd.AddRandomSongs(number, Config.random_exclude_pattern, Config.exclude_pattern, Global::RNG);
else
success = Mpd.AddRandomTag(tag_type, number, Global::RNG);
success = Mpd.AddRandomTag(tag_type, number, Config.exclude_pattern, Global::RNG);
if (success)
Statusbar::printf("%1% random %2%%3% added to playlist", number, tag_type_str, number == 1 ? "" : "s");
}
Expand Down
14 changes: 9 additions & 5 deletions src/mpdpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ bool Connection::Add(const std::string &path)
return result;
}

bool Connection::AddRandomTag(mpd_tag_type tag, size_t number, std::mt19937 &rng)
bool Connection::AddRandomTag(mpd_tag_type tag, size_t number, const std::string &exclude_pattern, std::mt19937 &rng)
{
std::vector<std::string> tags(
std::make_move_iterator(GetList(tag)),
Expand All @@ -592,6 +592,7 @@ bool Connection::AddRandomTag(mpd_tag_type tag, size_t number, std::mt19937 &rng

std::shuffle(tags.begin(), tags.end(), rng);
auto it = tags.begin();
boost::regex re(exclude_pattern);
for (size_t i = 0; i < number && it != tags.end(); ++i)
{
StartSearch(true);
Expand All @@ -602,13 +603,14 @@ bool Connection::AddRandomTag(mpd_tag_type tag, size_t number, std::mt19937 &rng
paths.push_back(s->getURI());
StartCommandsList();
for (const auto &path : paths)
AddSong(path);
if (exclude_pattern.empty() || !boost::regex_match(path, re))
AddSong(path);
CommitCommandsList();
}
return true;
}

bool Connection::AddRandomSongs(size_t number, const std::string &random_exclude_pattern, std::mt19937 &rng)
bool Connection::AddRandomSongs(size_t number, const std::string &random_exclude_pattern, const std::string &exclude_pattern, std::mt19937 &rng)
{
prechecksNoCommandsList();
std::vector<std::string> files;
Expand All @@ -620,7 +622,7 @@ bool Connection::AddRandomSongs(size_t number, const std::string &random_exclude
}
mpd_response_finish(m_connection.get());
checkErrors();

if (number > files.size())
{
//if (itsErrorHandler)
Expand All @@ -633,8 +635,10 @@ bool Connection::AddRandomSongs(size_t number, const std::string &random_exclude
StartCommandsList();
auto it = files.begin();
boost::regex re(random_exclude_pattern);
boost::regex re2(exclude_pattern);
for (size_t i = 0; i < number && it != files.end(); ++it) {
if (random_exclude_pattern.empty() || !boost::regex_match((*it), re)) {
if ((random_exclude_pattern.empty() || !boost::regex_match((*it), re))
&& (exclude_pattern.empty() || !boost::regex_match((*it), re2))) {
AddSong(*it);
i++;
}
Expand Down
4 changes: 2 additions & 2 deletions src/mpdpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -558,8 +558,8 @@ struct Connection

int AddSong(const std::string &, int = -1); // returns id of added song
int AddSong(const Song &, int = -1); // returns id of added song
bool AddRandomTag(mpd_tag_type, size_t, std::mt19937 &rng);
bool AddRandomSongs(size_t number, const std::string &random_exclude_pattern, std::mt19937 &rng);
bool AddRandomTag(mpd_tag_type, size_t, const std::string &exclude_pattern, std::mt19937 &rng);
bool AddRandomSongs(size_t number, const std::string &random_exclude_pattern, const std::string &exclude_pattern, std::mt19937 &rng);
bool Add(const std::string &path);
void Delete(unsigned int pos);
void DeleteRange(unsigned begin, unsigned end);
Expand Down
4 changes: 3 additions & 1 deletion src/screens/media_library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,13 +468,15 @@ void MediaLibrary::update()
sunfilter_songs.set(ReapplyFilter::Yes, true);
auto &album = Albums.current()->value();
size_t idx = 0;
boost::regex re(Config.exclude_pattern);
for (MPD::SongIterator s = getSongsFromAlbum(album), end;
s != end; ++s, ++idx)
{
if (idx < Songs.size())
Songs[idx].value() = std::move(*s);
else
Songs.addItem(std::move(*s));
if (Config.exclude_pattern.empty() || !boost::regex_match(s->getURI(), re))
Songs.addItem(std::move(*s));
};
if (idx < Songs.size())
Songs.resizeList(idx);
Expand Down
8 changes: 6 additions & 2 deletions src/screens/search_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,8 +470,10 @@ void SearchEngine::Search()
Mpd.AddSearch(MPD_TAG_DATE, itsConstraints[9]);
if (!itsConstraints[10].empty())
Mpd.AddSearch(MPD_TAG_COMMENT, itsConstraints[10]);
boost::regex re(Config.exclude_pattern);
for (MPD::SongIterator s = Mpd.CommitSearchSongs(), end; s != end; ++s)
w.addItem(std::move(*s));
if (Config.exclude_pattern.empty() || !boost::regex_match(s->getURI(), re))
w.addItem(std::move(*s));
return;
}

Expand Down Expand Up @@ -510,6 +512,7 @@ void SearchEngine::Search()
}

LocaleStringComparison cmp(std::locale(), Config.ignore_leading_the);
boost::regex re(Config.exclude_pattern);
for (; s != end; ++s)
{
bool any_found = true, found = true;
Expand Down Expand Up @@ -587,7 +590,8 @@ void SearchEngine::Search()
}

if (any_found && found)
w.addItem(*s);
if (Config.exclude_pattern.empty() || !boost::regex_match(s->getURI(), re))
w.addItem(*s);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ bool Configuration::read(const std::vector<std::string> &config_paths, bool igno
p.add("mpd_connection_timeout", &mpd_connection_timeout, "5");
p.add("mpd_crossfade_time", &crossfade_time, "5");
p.add("random_exclude_pattern", &random_exclude_pattern, "");
p.add("exclude_pattern", &exclude_pattern, "");
p.add("visualizer_data_source", &visualizer_data_source, "/tmp/mpd.fifo", adjust_path);
p.add("visualizer_output_name", &visualizer_output_name, "Visualizer feed");
p.add("visualizer_in_stereo", &visualizer_in_stereo, "yes", yes_no);
Expand Down
1 change: 1 addition & 0 deletions src/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ struct Configuration
std::vector<ScreenType> screen_sequence;

std::string random_exclude_pattern;
std::string exclude_pattern;
SortMode browser_sort_mode;

LyricsFetchers lyrics_fetchers;
Expand Down