### Manage Chapters in MP4 Files Source: https://github.com/saecki/mp4ameta/blob/main/README.md Handle chapters stored in either a chapter list or a chapter track. This example demonstrates reading chapter titles and times, clearing existing chapters, and adding new ones. ```rust use mp4ameta::{Chapter, Tag}; use std::time::Duration; let mut tag = Tag::read_from_path("audiobook.m4b").unwrap(); for chapter in tag.chapter_track() { let mins = chapter.start.as_secs() / 60; let secs = chapter.start.as_secs() % 60; println!("{mins:02}:{secs:02} {}", chapter.title); } tag.chapter_track_mut().clear(); tag.chapter_list_mut().extend([ Chapter::new(Duration::ZERO, "first chapter"), Chapter::new(Duration::from_secs(3 * 60 + 42), "second chapter"), Chapter::new(Duration::from_secs(7 * 60 + 13), "third chapter"), ]); tag.write_to_path("audiobook.m4b").unwrap(); ``` -------------------------------- ### Read and Write Basic Metadata Source: https://github.com/saecki/mp4ameta/blob/main/README.md Use this for straightforward reading and writing of common metadata like artist. Ensure the file exists and is accessible. ```rust let mut tag = mp4ameta::Tag::read_from_path("music.m4a").unwrap(); println!("{}", tag.artist().unwrap()); tag.set_artist("artist"); tag.write_to_path("music.m4a").unwrap(); ``` -------------------------------- ### Configure Metadata Reading and Writing Source: https://github.com/saecki/mp4ameta/blob/main/README.md Customize which metadata is read or written to optimize performance and control data modification. Use `ReadConfig` to specify desired metadata types and `WriteConfig` to select fields for overwriting. ```rust use mp4ameta::{ChplTimescale, ReadConfig, Tag, WriteConfig}; // Only read the metadata item list, not chapters or audio information let read_cfg = ReadConfig { read_meta_items: true, read_image_data: false, read_chapter_list: false, read_chapter_track: false, read_audio_info: false, chpl_timescale: ChplTimescale::DEFAULT, }; let mut tag = Tag::read_with_path("music.m4a", &read_cfg).unwrap(); println!("{tag}"); tag.clear_meta_items(); // Only overwrite the metadata item list, leave chapters intact let write_cfg = WriteConfig { write_meta_items: true, write_chapter_list: false, write_chapter_track: false, chpl_timescale: ChplTimescale::DEFAULT, }; tag.write_with_path("music.m4a", &write_cfg).unwrap(); ``` -------------------------------- ### Read and Write Metadata Using Freeform Identifiers Source: https://github.com/saecki/mp4ameta/blob/main/README.md Utilize Freeform Identifiers for custom metadata fields, often used by specific applications like iTunes. Ensure the identifier and namespace are correct. ```rust use mp4ameta::{Data, FreeformIdent, Tag}; let mut tag = Tag::read_from_path("music.m4a").unwrap(); let isrc_ident = FreeformIdent::new_static("com.apple.iTunes", "ISRC"); let isrc = tag.strings_of(&isrc_ident).next().unwrap(); println!("{}", isrc); tag.set_data(isrc_ident, Data::Utf8("isrc".to_owned())); tag.write_to_path("music.m4a").unwrap(); ``` -------------------------------- ### Read and Write Metadata Using Fourcc Identifiers Source: https://github.com/saecki/mp4ameta/blob/main/README.md Access metadata using Fourcc identifiers for more granular control. This is useful for non-standard or specific metadata fields. ```rust use mp4ameta::{Data, Fourcc, Tag}; let mut tag = Tag::read_from_path("music.m4a").unwrap(); let artist_ident = Fourcc(*b"\xa9ART"); let artist = tag.strings_of(&artist_ident).next().unwrap(); println!("{}", artist); tag.set_data(artist_ident, Data::Utf8("artist".to_owned())); tag.write_to_path("music.m4a").unwrap(); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.