Skip to content

Commit

Permalink
Refactor playlist / library playlist making
Browse files Browse the repository at this point in the history
  • Loading branch information
Polochon-street committed Jul 8, 2024
1 parent 511aed6 commit d23742e
Show file tree
Hide file tree
Showing 6 changed files with 369 additions and 209 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Changelog

## bliss 0.8.0
* Remove the `number_songs` option from `Library::playlist_from_custom`.
Since it now returns an Iterator, `number_songs` can just be replaced by `take`.
* `Library::playlist_from_custom` now returns an Iterator instead of a Vec.
* `Library::playlist_from_custom` now also returns the song(s) the playlist
was built from.

Expand Down
4 changes: 3 additions & 1 deletion examples/library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,9 @@ fn main() -> Result<()> {
.unwrap_or("20")
.parse::<usize>()?;
let library: Library<Config, Decoder> = Library::from_config_path(config_path)?;
let songs = library.playlist_from::<()>(&[song_path], playlist_length)?;
let songs = library
.playlist_from::<()>(&[song_path])?
.take(playlist_length);
let song_paths = songs
.into_iter()
.map(|s| s.bliss_song.path.to_string_lossy().to_string())
Expand Down
5 changes: 3 additions & 2 deletions examples/library_extra_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,10 @@ fn main() -> Result<()> {
.unwrap_or("20")
.parse::<usize>()?;
let library: Library<Config, Decoder> = Library::from_config_path(config_path)?;
let songs = library.playlist_from::<ExtraInfo>(&[song_path], playlist_length)?;
let songs = library
.playlist_from::<ExtraInfo>(&[song_path])?
.take(playlist_length);
let playlist = songs
.into_iter()
.map(|s| {
(
s.bliss_song.path.to_string_lossy().to_string(),
Expand Down
11 changes: 7 additions & 4 deletions examples/playlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,18 @@ fn main() -> Result<()> {
}
analyzed_songs.extend_from_slice(&songs);
let serialized = serde_json::to_string(&analyzed_songs).unwrap();
let mut songs_to_chose_from: Vec<_> = analyzed_songs
let songs_to_chose_from: Vec<_> = analyzed_songs
.into_iter()
.filter(|x| x == &first_song || paths.contains(&x.path.to_string_lossy().to_string()))
.collect();
closest_to_songs(&[first_song], &mut songs_to_chose_from, &euclidean_distance);
dedup_playlist(&mut songs_to_chose_from, None);
let playlist = dedup_playlist(
closest_to_songs(&[first_song], &songs_to_chose_from, &euclidean_distance),
None,
)
.collect::<Vec<_>>();

fs::write(analysis_path, serialized)?;
let playlist = songs_to_chose_from
let playlist = playlist
.iter()
.map(|s| s.path.to_string_lossy().to_string())
.collect::<Vec<String>>()
Expand Down
Loading

0 comments on commit d23742e

Please sign in to comment.