102 lines
4.2 KiB
Rust
102 lines
4.2 KiB
Rust
use std::{fs::File, io::{Read, Write}};
|
|
use env_logger::Builder;
|
|
use log::{error, info, LevelFilter};
|
|
use rand::Rng;
|
|
use xobjects::{XArgument, XPlArgument, XSomeList};
|
|
|
|
mod objects;
|
|
mod xobjects;
|
|
mod deserializer;
|
|
mod serializer;
|
|
|
|
/*
|
|
[lib]
|
|
crate-type = ["staticlib", "cdylib", "lib"]
|
|
*/
|
|
|
|
/*fn main() {
|
|
|
|
// Initialize the logger with 'info' as the default level
|
|
Builder::new()
|
|
.filter(None, LevelFilter::Info)
|
|
.init();
|
|
|
|
// /Users/michael/Documents/ipod/iTunes/iTunesDB
|
|
let mut f = File::open("/Users/michael/Documents/ipod/iTunes/iTunesDB").unwrap(); // D:\\Documents\\iTunes\\iTunesDB
|
|
let mut buf = Vec::new();
|
|
match f.read_to_end(&mut buf) {
|
|
Ok(n) => {
|
|
let data = &buf[..n];
|
|
let mut xdb = deserializer::parse_bytes(data);
|
|
//info!("XDB: {:#?}", xdb);
|
|
|
|
let unique_id = rand::thread_rng().gen_range(10..999);
|
|
|
|
if let XSomeList::TrackList(tracks) = &mut xdb.find_dataset(1).child {
|
|
let mut item = (*tracks.last().unwrap()).clone();
|
|
let mut xargs = Vec::new();
|
|
xargs.push(XArgument { arg_type: 1, val: String::from("They beat you") });
|
|
xargs.push(XArgument { arg_type: 6, val: String::from("MPEG audio file")});
|
|
xargs.push(XArgument { arg_type: 2, val: String::from(":iPod_Control:Music:F38:ZXXX.mp3") });
|
|
item.args = xargs;
|
|
item.data.number_of_strings = 3;
|
|
item.data.unique_id = unique_id;
|
|
item.data.dbid = rand::thread_rng().gen_range(10000..100000);
|
|
item.data.dbid2 = item.data.dbid;
|
|
xdb.add_track(item);
|
|
}
|
|
|
|
/*if let XSomeList::TrackList(tracks) = &mut xdb.find_dataset(1).child {
|
|
let mut item = (*tracks.last().unwrap()).clone();
|
|
let mut xargs = Vec::new();
|
|
xargs.push(XArgument { arg_type: 1, val: String::from("They beat you") });
|
|
xargs.push(XArgument { arg_type: 6, val: String::from("MPEG audio file")});
|
|
xargs.push(XArgument { arg_type: 2, val: String::from(":iPod_Control:Music:F38:ZXXX.mp3") });
|
|
item.args = xargs;
|
|
item.data.number_of_strings = 3;
|
|
item.data.unique_id = unique_id;
|
|
item.data.dbid = rand::thread_rng().gen_range(10000..100000);
|
|
item.data.dbid2 = item.data.dbid;
|
|
tracks.push(item);
|
|
}
|
|
|
|
if let XSomeList::Playlists(playlists) = &mut xdb.find_dataset(2).child {
|
|
let playlist = playlists.last_mut().unwrap();
|
|
playlist.data.playlist_item_count = playlist.data.playlist_item_count + 1;
|
|
let elem = playlist.elems.last().unwrap();
|
|
let mut pl_item = elem.0.clone();
|
|
pl_item.track_id = unique_id;
|
|
|
|
pl_item.group_id = rand::thread_rng().gen_range(10..255);
|
|
let mut args = elem.1.clone();
|
|
if let XPlArgument::RawArgument(raw) = args.last_mut().unwrap() {
|
|
raw[24] = pl_item.group_id as u8;
|
|
}
|
|
|
|
playlist.elems.push((pl_item, args));
|
|
}
|
|
|
|
if let XSomeList::Playlists(playlists) = &mut xdb.find_dataset(3).child {
|
|
let playlist = playlists.last_mut().unwrap();
|
|
playlist.data.playlist_item_count = playlist.data.playlist_item_count + 1;
|
|
let elem = playlist.elems.last().unwrap();
|
|
let mut pl_item = elem.0.clone();
|
|
pl_item.track_id = unique_id;
|
|
pl_item.group_id = rand::thread_rng().gen_range(10..255);
|
|
let mut args = elem.1.clone();
|
|
if let XPlArgument::RawArgument(raw) = args.last_mut().unwrap() {
|
|
raw[24] = pl_item.group_id as u8;
|
|
}
|
|
|
|
playlist.elems.push((pl_item, args));
|
|
}*/
|
|
|
|
let mut op = File::create("outdb").unwrap();
|
|
info!("Write res: {:?}", op.write(&serializer::to_bytes(xdb)));
|
|
},
|
|
Err(e) => {
|
|
error!("Error: {}",e);
|
|
}
|
|
}
|
|
}
|
|
*/ |