From bdc06ca5655ba187ba7d398297dcb15dd162d9b1 Mon Sep 17 00:00:00 2001 From: "alterwain@protonmail.com" Date: Sat, 15 Feb 2025 17:16:51 +0300 Subject: [PATCH] 0.1.18 upd --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/objects.rs | 77 +++++++++++++++++++++++++++++++++++++++++++++++-- src/xobjects.rs | 19 +++++++++++- 4 files changed, 94 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cafe23b..ae0460b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -90,7 +90,7 @@ checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674" [[package]] name = "itunesdb" -version = "0.1.16" +version = "0.1.18" dependencies = [ "bincode", "env_logger", diff --git a/Cargo.toml b/Cargo.toml index 84e2c74..43987f6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "itunesdb" -version = "0.1.17" +version = "0.1.18" edition = "2021" authors = ["alterwain"] diff --git a/src/objects.rs b/src/objects.rs index cf9e0a0..b4f8bbf 100644 --- a/src/objects.rs +++ b/src/objects.rs @@ -307,23 +307,78 @@ pub struct JumpTable { #[derive(Serialize, Deserialize, PartialEq, Debug, Clone)] pub struct Playlist { - data_object_child_count: u32, + pub data_object_child_count: u32, pub playlist_item_count: u32, pub is_master_playlist_flag: u8, unk: [u8; 3], pub timestamp: u32, pub persistent_playlist_id: u64, unk3: u32, - string_mhod_count: u16, + pub string_mhod_count: u16, podcast_flag: u16, list_sort_order: u32, unk1: [u8; 22], unk2: [u8; 22], } +impl Playlist { + pub fn new(persistent_playlist_id: u64, sort_order: ListSortOrder) -> Self { + Self { + data_object_child_count: 0, + playlist_item_count: 0, + is_master_playlist_flag: 0, + unk: [0; 3], + timestamp: 0, + persistent_playlist_id, + unk3: 0, + string_mhod_count: 0, + podcast_flag: 0, + list_sort_order: sort_order.into(), + unk1: [0; 22], + unk2: [0; 22], + } + } +} + +pub enum ListSortOrder { + Manual, + SongTitle, + Album, + Artist, + Bitrate, + Genre, + Size, + Year, + SampleRate, + PlayCount, + LastPlayed, + MyRating, + BPM +} + +impl From for u32 { + fn from(value: ListSortOrder) -> Self { + match value { + ListSortOrder::Manual => 1, + ListSortOrder::SongTitle => 3, + ListSortOrder::Album => 4, + ListSortOrder::Artist => 5, + ListSortOrder::Bitrate => 6, + ListSortOrder::Genre => 7, + ListSortOrder::Size => 11, + ListSortOrder::Year => 13, + ListSortOrder::SampleRate => 14, + ListSortOrder::PlayCount => 20, + ListSortOrder::LastPlayed => 21, + ListSortOrder::MyRating => 23, + ListSortOrder::BPM => 25 + } + } +} + #[derive(Serialize, Deserialize, PartialEq, Debug, Clone)] pub struct PlaylistItem { - data_object_child_count: u32, + pub data_object_child_count: u32, podcast_grouping_flag: u16, unk4: u16, pub group_id: u32, @@ -333,3 +388,19 @@ pub struct PlaylistItem { unk: [u8; 30], unk1: [u8; 10], } + +impl PlaylistItem { + pub fn new(track_id: u32, group_id: u32) -> Self { + Self { + data_object_child_count: 0, + podcast_grouping_flag: 0, + unk4: 0, + group_id, + track_id, + timestamp: 0, + podcast_grouping_reference: 0, + unk: [0; 30], + unk1: [0; 10], + } + } +} \ No newline at end of file diff --git a/src/xobjects.rs b/src/xobjects.rs index bc709b9..3e307b7 100644 --- a/src/xobjects.rs +++ b/src/xobjects.rs @@ -1,6 +1,6 @@ use rand::Rng; -use crate::objects::{AlbumItem, ChunkHeader, DataSet, Database, JumpTable, LetterJumpEntry, Playlist, PlaylistIndexEntry, PlaylistItem, TrackItem}; +use crate::objects::{AlbumItem, ChunkHeader, DataSet, Database, JumpTable, LetterJumpEntry, ListSortOrder, Playlist, PlaylistIndexEntry, PlaylistItem, TrackItem}; #[derive(Debug, serde::Serialize)] @@ -102,6 +102,23 @@ impl XPlaylist { true }); self.args.push(XPlArgument::String(XArgument { arg_type: id, val })); + self.data.string_mhod_count = self.args.len() as u16; + self.data.data_object_child_count = self.args.len() as u32; + } + + pub fn new(persistent_playlist_id: u64, sort_order: ListSortOrder) -> Self { + Self { + header: ChunkHeader::empty(), + data: Playlist::new(persistent_playlist_id, sort_order), + args: vec![], + elems: vec![], + } + } + + pub fn add_elem(&mut self, track_id: u32) { + let group_id: u32 = rand::random(); + self.elems.push((PlaylistItem::new(track_id, group_id), Vec::new())); + self.data.playlist_item_count += 1; } }