Skip to content

Commit

Permalink
Add a "--from-song" option
Browse files Browse the repository at this point in the history
  • Loading branch information
Polochon-street committed Jun 14, 2024
1 parent 6e909db commit 1f32210
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## blissify 0.4.0
* Add a "--from-song" option to select a specific song from the command-line.
* Default to deduplicating songs when making playlist; add a "--no-deduplication" option.

## blissify 0.3.12
Expand Down
64 changes: 58 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,43 @@ impl MPDLibrary {
Ok(())
}

/// Make a playlist from a given song, queuing the songs founds.
/// Does not do any "stop random, empty playlist", etc magic.
///
/// song_path can be either a path relative to the MPD folder or the full path.
fn queue_from_song_custom<F>(
&self,
song_path: String,
number_songs: usize,
distance: &dyn DistanceMetricBuilder,
mut sort_by: F,
dedup: bool,
) -> Result<()>
where
F: FnMut(&[LibrarySong<()>], &mut [LibrarySong<()>], &dyn DistanceMetricBuilder),
{
let mut mpd_conn = self.mpd_conn.lock().unwrap();
let path =
if song_path.contains(self.library.config.mpd_base_path.to_string_lossy().as_ref()) {
PathBuf::from(song_path)
} else {
self.library.config.mpd_base_path.join(song_path)
};
let playlist = self.library.playlist_from_custom(
&[&path.to_string_lossy().clone()],
number_songs,
distance,
&mut sort_by,
dedup,
)?;

for song in &playlist[1..] {
let mpd_song = self.bliss_song_to_mpd(song)?;
mpd_conn.push(mpd_song)?;
}
Ok(())
}

/// Get the song's paths from the MPD database.
///
/// Instead of returning one filename per CUE track (file.cue/track0001,
Expand Down Expand Up @@ -683,6 +720,11 @@ Useful to avoid a too heavy load on a machine.")
)
.default_value("euclidean")
)
.arg(Arg::with_name("from-song")
.long("from-song")
.value_name("song path")
.help("Instead of making a playlist from the current playing song, make a playlist from 'song path', and adds the corresponding songs to the queue.")
)
.arg(Arg::with_name("seed")
.long("seed-song")
.help(
Expand Down Expand Up @@ -802,12 +844,22 @@ Defaults to 3, cannot be more than 9."
true => song_to_song,
};
let no_dedup = sub_m.is_present("no-dedup");
library.queue_from_current_song_custom(
number_songs,
&distance_metric,
sort,
!no_dedup,
)?;
if let Some(song_path) = sub_m.value_of("from-song") {
library.queue_from_song_custom(
song_path.to_string(),
number_songs,
&distance_metric,
sort,
!no_dedup,
)?;
} else {
library.queue_from_current_song_custom(
number_songs,
&distance_metric,
sort,
!no_dedup,
)?;
}
}
} else if let Some(sub_m) = matches.subcommand_matches("interactive-playlist") {
let number_choices: usize = sub_m.value_of("choices").unwrap_or("3").parse()?;
Expand Down

0 comments on commit 1f32210

Please sign in to comment.