renamed xml to itunes

This commit is contained in:
MrDulfin 2024-01-19 22:35:19 -05:00
parent 0f5eda5d1d
commit 097cc1147e
3 changed files with 19 additions and 51 deletions

View file

@ -18,18 +18,18 @@ use crate::music_storage::utils;
use urlencoding::decode; use urlencoding::decode;
#[derive(Debug, Default, Clone)] #[derive(Debug, Default, Clone)]
pub struct XmlLibrary { pub struct ITunesLibrary {
tracks: Vec<XMLSong>, tracks: Vec<ITunesSong>,
} }
impl XmlLibrary { impl ITunesLibrary {
fn new() -> Self { fn new() -> Self {
Default::default() Default::default()
} }
pub fn tracks(self) -> Vec<XMLSong> { pub fn tracks(self) -> Vec<ITunesSong> {
self.tracks self.tracks
} }
} }
impl ExternalLibrary for XmlLibrary { impl ExternalLibrary for ITunesLibrary {
fn from_file(file: &Path) -> Self { fn from_file(file: &Path) -> Self {
let mut reader = Reader::from_file(file).unwrap(); let mut reader = Reader::from_file(file).unwrap();
reader.trim_text(true); reader.trim_text(true);
@ -45,7 +45,7 @@ impl ExternalLibrary for XmlLibrary {
let mut buf = Vec::new(); let mut buf = Vec::new();
let mut skip = false; let mut skip = false;
let mut converted_songs: Vec<XMLSong> = Vec::new(); let mut converted_songs: Vec<ITunesSong> = Vec::new();
let mut song_tags: HashMap<String, String> = HashMap::new(); let mut song_tags: HashMap<String, String> = HashMap::new();
let mut key: String = String::new(); let mut key: String = String::new();
@ -63,7 +63,7 @@ impl ExternalLibrary for XmlLibrary {
tagvalue.clear(); tagvalue.clear();
key_selected = false; key_selected = false;
//end the song to start a new one, and turn turn current song map into XMLSong //end the song to start a new one, and turn turn current song map into iTunesSong
if song_tags.contains_key(&"Location".to_string()) { if song_tags.contains_key(&"Location".to_string()) {
count3 += 1; count3 += 1;
//check for skipped IDs //check for skipped IDs
@ -73,7 +73,7 @@ impl ExternalLibrary for XmlLibrary {
count3 += 1; count3 += 1;
count4 += 1; count4 += 1;
} }
converted_songs.push(XMLSong::from_hashmap(&mut song_tags).unwrap()); converted_songs.push(ITunesSong::from_hashmap(&mut song_tags).unwrap());
song_tags.clear(); song_tags.clear();
skip = true; skip = true;
} }
@ -117,8 +117,8 @@ impl ExternalLibrary for XmlLibrary {
buf.clear(); buf.clear();
} }
let elasped = now.elapsed(); let elasped = now.elapsed();
println!("\n\nXMLReader grabbed {} songs in {:#?} seconds\nIDs Skipped: {}", count3, elasped.as_secs(), count4); println!("\n\niTunesReader grabbed {} songs in {:#?} seconds\nIDs Skipped: {}", count3, elasped.as_secs(), count4);
let mut lib = XmlLibrary::new(); let mut lib = ITunesLibrary::new();
lib.tracks.append(converted_songs.as_mut()); lib.tracks.append(converted_songs.as_mut());
lib lib
} }
@ -253,7 +253,7 @@ fn get_art(file: &Path) -> Result<Vec<AlbumArt>, LoftyError> {
} }
#[derive(Debug, Clone, Default)] #[derive(Debug, Clone, Default)]
pub struct XMLSong { pub struct ITunesSong {
pub id: i32, pub id: i32,
pub plays: i32, pub plays: i32,
pub favorited: bool, pub favorited: bool,
@ -268,13 +268,13 @@ pub struct XMLSong {
pub location: String, pub location: String,
} }
impl XMLSong { impl ITunesSong {
pub fn new() -> XMLSong { pub fn new() -> ITunesSong {
Default::default() Default::default()
} }
fn from_hashmap(map: &mut HashMap<String, String>) -> Result<XMLSong, LoftyError> { fn from_hashmap(map: &mut HashMap<String, String>) -> Result<ITunesSong, LoftyError> {
let mut song = XMLSong::new(); let mut song = ITunesSong::new();
//get the path with the first bit chopped off //get the path with the first bit chopped off
let path_: String = map.get_key_value("Location").unwrap().1.clone(); let path_: String = map.get_key_value("Location").unwrap().1.clone();
let track_type: String = map.get_key_value("Track Type").unwrap().1.clone(); let track_type: String = map.get_key_value("Track Type").unwrap().1.clone();
@ -320,36 +320,4 @@ impl XMLSong {
// println!("{:.2?}", song); // println!("{:.2?}", song);
Ok(song) Ok(song)
} }
} }
// fn get_folder(file: &PathBuf) -> String {
// let mut reader = Reader::from_file(file).unwrap();
// reader.trim_text(true);
// //count every event, for fun ig?
// let mut count = 0;
// let mut buf = Vec::new();
// let mut folder = String::new();
// loop {
// match reader.read_event_into(&mut buf) {
// Ok(Event::Start(_)) => {
// count += 1;
// }
// Ok(Event::Text(e)) => {
// if count == 10 {
// folder = String::from(
// e.unescape()
// .unwrap()
// .to_string()
// .strip_prefix("file://localhost/")
// .unwrap(),
// );
// return folder;
// }
// }
// Err(_e) => {
// panic!("oh no! something happened in the public function `get_reader_from_xml()!`")
// }
// _ => (),
// }
// }
// }

View file

@ -6,7 +6,7 @@ pub mod musicbee {
pub mod reader; pub mod reader;
pub mod utils; pub mod utils;
} }
pub mod xml { pub mod itunes {
pub mod reader; pub mod reader;
} }
pub mod common; pub mod common;

View file

@ -6,7 +6,7 @@ use walkdir::Error;
use super::{ use super::{
library::{AlbumArt, Song, Tag}, library::{AlbumArt, Song, Tag},
music_collection::MusicCollection, db_reader::{ music_collection::MusicCollection, db_reader::{
xml::reader::XmlLibrary, itunes::reader::ITunesLibrary,
extern_library::ExternalLibrary extern_library::ExternalLibrary
}, },
}; };
@ -136,7 +136,7 @@ impl Default for Playlist<'_> {
#[test] #[test]
fn list_to_m3u8() { fn list_to_m3u8() {
let lib = XmlLibrary::from_file(Path::new( let lib = ITunesLibrary::from_file(Path::new(
"F:\\Music\\Mp3\\Music Main\\iTunes Music Library.xml", "F:\\Music\\Mp3\\Music Main\\iTunes Music Library.xml",
)); ));
let mut a = Playlist::new(); let mut a = Playlist::new();