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 d585d81
Show file tree
Hide file tree
Showing 6 changed files with 373 additions and 219 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
6 changes: 3 additions & 3 deletions examples/library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +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 song_paths = songs
.into_iter()
let song_paths = library
.playlist_from::<()>(&[song_path])?
.take(playlist_length)
.map(|s| s.bliss_song.path.to_string_lossy().to_string())
.collect::<Vec<String>>();
for song in song_paths {
Expand Down
6 changes: 3 additions & 3 deletions examples/library_extra_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,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::<ExtraInfo>(&[song_path], playlist_length)?;
let playlist = songs
.into_iter()
let playlist = library
.playlist_from::<ExtraInfo>(&[song_path])?
.take(playlist_length)
.map(|s| {
(
s.bliss_song.path.to_string_lossy().to_string(),
Expand Down
22 changes: 11 additions & 11 deletions examples/playlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,21 +73,21 @@ fn main() -> Result<()> {
Err(e) => println!("error analyzing {}: {}", path.display(), e),
};
}
analyzed_songs.extend_from_slice(&songs);
let serialized = serde_json::to_string(&analyzed_songs).unwrap();
let mut songs_to_chose_from: Vec<_> = analyzed_songs
fs::write(analysis_path, serialized)?;

analyzed_songs.extend_from_slice(&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);

fs::write(analysis_path, serialized)?;
let playlist = songs_to_chose_from
.iter()
.map(|s| s.path.to_string_lossy().to_string())
.collect::<Vec<String>>()
.join("\n");
let playlist = dedup_playlist(
closest_to_songs(&[first_song], &songs_to_chose_from, &euclidean_distance),
None,
)
.map(|s| s.path.to_string_lossy().to_string())
.collect::<Vec<String>>()
.join("\n");
if let Some(m) = matches.value_of("output-playlist") {
fs::write(m, playlist)?;
} else {
Expand Down
Loading

0 comments on commit d585d81

Please sign in to comment.