|
@ -1,7 +1,20 @@ |
|
|
use clap::{Arg, Error, ErrorKind};
|
|
|
use clap::{Arg, Error, ErrorKind};
|
|
|
use clap_nested::{Command};
|
|
|
use clap_nested::{Command};
|
|
|
|
|
|
|
|
|
use crate::lib::m3u::{Playlist};
|
|
|
|
|
|
|
|
|
use crate::lib::m3u::{Playlist, PlaylistTrack};
|
|
|
|
|
|
use std::collections::HashSet;
|
|
|
|
|
|
|
|
|
|
|
|
fn dedupe(playlist_tracks: Vec<PlaylistTrack>) -> Vec<PlaylistTrack> {
|
|
|
|
|
|
let mut seen_tracks: HashSet<String> = HashSet::new();
|
|
|
|
|
|
let mut dedupe_playlist_tracks = Vec::new();
|
|
|
|
|
|
for track in playlist_tracks {
|
|
|
|
|
|
if ! seen_tracks.contains(&track.track) {
|
|
|
|
|
|
seen_tracks.insert(String::from(&track.track));
|
|
|
|
|
|
dedupe_playlist_tracks.push(track);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
dedupe_playlist_tracks
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
pub fn get_command<'a>() -> Command<'a, str>{
|
|
|
pub fn get_command<'a>() -> Command<'a, str>{
|
|
|
Command::new("dedupe")
|
|
|
Command::new("dedupe")
|
|
@ -20,10 +33,12 @@ pub fn get_command<'a>() -> Command<'a, str>{ |
|
|
Some(playlists) => {
|
|
|
Some(playlists) => {
|
|
|
for path in playlists {
|
|
|
for path in playlists {
|
|
|
let playlist = Playlist::read(path)?;
|
|
|
let playlist = Playlist::read(path)?;
|
|
|
|
|
|
let dedupe_playlist_tracks: Vec<PlaylistTrack> = dedupe(*playlist.tracks);
|
|
|
|
|
|
let dedupe_playlist = Playlist::new(&path, dedupe_playlist_tracks);
|
|
|
if ! dry_run {
|
|
|
if ! dry_run {
|
|
|
playlist.write(path)?
|
|
|
|
|
|
|
|
|
dedupe_playlist.write(path)?
|
|
|
} else {
|
|
|
} else {
|
|
|
println!("{:?}", playlist);
|
|
|
|
|
|
|
|
|
println!("{:?}", dedupe_playlist);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
Ok(())
|
|
|
Ok(())
|
|
|