diff --git a/Cargo.toml b/Cargo.toml index de78b26..3343eca 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "itunesdb" -version = "0.1.71" +version = "0.1.72" edition = "2021" authors = ["alterwain"] diff --git a/src/artworkdb.rs b/src/artworkdb.rs index b91bf7a..04dc4be 100644 --- a/src/artworkdb.rs +++ b/src/artworkdb.rs @@ -232,7 +232,14 @@ pub mod aobjects { self.children.iter_mut().find(|d| d.data.data_type == p0).unwrap() } + fn get_last_cor_id(&mut self) -> u32{ + let files = self.find_dataset(3); + let image_files = &mut files.child; + image_files.iter().map(|p| p.file.as_ref().unwrap().correlation_id).max().unwrap_or(1028) + } + pub fn add_images(&mut self, small_image_path: &str, large_image_path: &str, song_dbid: u64) { + let last_cor_id = self.get_last_cor_id(); let ds = self.find_dataset(1); let image_items = &mut ds.child; let image_item = crate::artworkdb::objects::ImageItem { @@ -246,7 +253,7 @@ pub mod aobjects { digitized_date: 0, source_image_size: 0 }; - + let small_tag = SecondTypeTag { data: LocationTag { tag_type: 2, @@ -258,7 +265,7 @@ pub mod aobjects { AImageName { iname: ImageName { number_of_children: 1, - correlation_id: 1028, // TODO: make iterable corr_id + correlation_id: last_cor_id + 1, ithmb_offset: 0, image_size: 20000, vertical_padding: 0, @@ -295,7 +302,7 @@ pub mod aobjects { AImageName { iname: ImageName { number_of_children: 1, - correlation_id: 1029, // TODO: make iterable corr_id + correlation_id: last_cor_id + 2, ithmb_offset: 80000, image_size: 80000, vertical_padding: 0, @@ -338,7 +345,7 @@ pub mod aobjects { file: Some( ImageFile { unknown1: 0, - correlation_id: 1028, // TODO: make corr_id iterable + correlation_id: last_cor_id + 1, image_size: 20000, }, ), @@ -349,7 +356,7 @@ pub mod aobjects { file: Some( ImageFile { unknown1: 0, - correlation_id: 1029, // TODO: make corr_id iterable + correlation_id: last_cor_id + 2, image_size: 80000, }, ),