Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use new iterators #65

Merged
merged 1 commit into from
Jul 8, 2024
Merged
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## blissify 0.4.1
* Make the "--seed-song" option return faster.

## blissify 0.4.0
* Add a "--keep-current-queue" flag that keeps the current queue while making playlists,
instead of automatically cropping it.
Expand Down
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "blissify"
version = "0.4.0"
version = "0.4.1"
authors = ["Polochon-street <[email protected]>"]
edition = "2021"
license = "GPL-3.0-only"
Expand All @@ -17,7 +17,7 @@ default = ["bliss-audio/library"]
rpi = ["bliss-audio/rpi"]

[dependencies]
bliss-audio = "0.7.0"
bliss-audio = "0.8.0"
mpd = "0.0.12"
dirs = "3.0.1"
tempdir = "0.3.7"
Expand Down
32 changes: 18 additions & 14 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,18 +439,19 @@ impl MPDLibrary {
/// the playlist after the current song, but will keep the queue intact.
// TODO do we want a flag to toggle "random" off automatically here? And a flag to keep /
// exclude the current song from the playlist?
fn queue_from_song<F>(
fn queue_from_song<'a, F, I>(
&self,
song_path: Option<&str>,
number_songs: usize,
distance: &dyn DistanceMetricBuilder,
mut sort_by: F,
distance: &'a dyn DistanceMetricBuilder,
sort_by: F,
dedup: bool,
dry_run: bool,
keep_queue: bool,
) -> Result<()>
where
F: FnMut(&[LibrarySong<()>], &mut [LibrarySong<()>], &dyn DistanceMetricBuilder),
F: Fn(&[LibrarySong<()>], &[LibrarySong<()>], &'a dyn DistanceMetricBuilder) -> I,
I: Iterator<Item = LibrarySong<()>> + 'a,
{
let mut mpd_conn = self.mpd_conn.lock().unwrap();
if mpd_conn.status()?.random {
Expand Down Expand Up @@ -480,13 +481,11 @@ impl MPDLibrary {
} else {
number_songs + 1
};
let playlist = self.library.playlist_from_custom(
&[&path.to_string_lossy().clone()],
number_songs,
distance,
&mut sort_by,
dedup,
)?;
let playlist: Vec<LibrarySong<_>> = self
.library
.playlist_from_custom(&[&path.to_string_lossy().clone()], distance, sort_by, dedup)?
.take(number_songs)
.collect();

if dry_run {
for song in &playlist {
Expand Down Expand Up @@ -967,9 +966,14 @@ Defaults to 3, cannot be more than 9."
euclidean_distance
};

let sort = match sub_m.is_present("seed") {
false => closest_to_songs,
true => song_to_song,
let sort = |x: &[LibrarySong<()>],
y: &[LibrarySong<()>],
z|
-> Box<dyn Iterator<Item = LibrarySong<()>>> {
match sub_m.is_present("seed") {
false => Box::new(closest_to_songs(x, y, z)),
true => Box::new(song_to_song(x, y, z)),
}
};
library.queue_from_song(
sub_m.value_of("from-song"),
Expand Down
Loading