Skip to content

Commit

Permalink
feat: Playlist Update - update all/one import(s)
Browse files Browse the repository at this point in the history
  • Loading branch information
justjokiing committed Jul 23, 2023
1 parent 955ad4e commit 1476951
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
43 changes: 22 additions & 21 deletions spotify_player/src/cli/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -744,26 +744,6 @@ async fn playlist_import(

let mut result = String::new();

// This is meant to prompt for deletion,
// May not be able to do input/output because of
// client and cli structure
// Might add command option to automatically delete
let mut xtra_nl = false;
let deleted_tracks = old_ids.difference(&new_ids);
for track in deleted_tracks {
if result.is_empty() {
result.push_str("The import has deleted these tracks:\n");
xtra_nl = true;
}

result.push_str(format!("{}:{}\n", track.id.id(), track.name).as_str());
//client.spotify.playlist_remove_all_occurrences_of_items(to.id, [PlayableId::Track(track.id.to_owned())], None).await?;
}
// Formatting if there is any deletion
if xtra_nl {
result.push('\n');
}

// Add all new tracks
let new_tracks = new_ids.difference(&old_ids);
let mut new_tracks_count = 0;
Expand All @@ -787,10 +767,31 @@ async fn playlist_import(
)
.as_str(),
);

// This is meant to prompt for deletion,
// May not be able to do input/output because of
// client and cli structure
// Might add command option to automatically delete
let mut have_removed = false;
let deleted_tracks = old_ids.difference(&new_ids);
for track in deleted_tracks {
if !have_removed {
result.push_str("The import has deleted these tracks:\n");
have_removed = true;
}

result.push_str(format!("{}:{}\n", track.id.id(), track.name).as_str());
//client.spotify.playlist_remove_all_occurrences_of_items(to.id, [PlayableId::Track(track.id.to_owned())], None).await?;
}

if !have_removed {
result.push('\n');
}

Ok(result)
} else {
Ok(format!(
"No updates to the import '{}' for '{}'",
"No updates to the import '{}' for '{}'\n",
from.name, to.name
))
}
Expand Down
2 changes: 1 addition & 1 deletion spotify_player/src/cli/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ pub fn init_playlist_subcommand() -> Command {
.subcommand(Command::new("fork").about("Creates a copy of a playlist and imports it.")
.arg(Arg::new("id")
.value_parser(clap::builder::NonEmptyStringValueParser::new())))
.subcommand(Command::new("update").about("Updates all imported playlists.")
.subcommand(Command::new("update").about("Updates all imported playlists or a single individual import.")
.arg(Arg::new("id")
.required(false)
.value_parser(clap::builder::NonEmptyStringValueParser::new())))
Expand Down

0 comments on commit 1476951

Please sign in to comment.