Struct id3::Tag
[−]
[src]
pub struct Tag { /* fields omitted */ }
An ID3 tag containing metadata frames.
Methods
impl<'a> Tag
[src]
fn new() -> Tag
Creates a new ID3v2.3 tag with no frames.
fn with_version(version: u8) -> Tag
Creates a new ID3 tag with the specified version.
ID3v2 versions 2 to 4 are supported. Passing any other version will cause a panic.
fn is_candidate_v1<R: Read + Seek>(reader: &mut R) -> bool
Returns true if the reader might contain a valid ID3v1 tag.
fn read_from_v1<R: Read + Seek>(reader: &mut R) -> Result<Tag>
Attempts to read an ID3v1 tag from the reader. Since the structure of ID3v1 is so different from ID3v2, the tag will be converted and stored internally as an ID3v2.3 tag.
fn read_from_path_v1<P: AsRef<Path>>(path: P) -> Result<Tag>
Attempts to read an ID3v1 tag from the file at the specified path. The tag will be converted into an ID3v2.3 tag upon success.
fn version(&self) -> u8
Returns the version of the tag.
Example
use id3::Tag; let tag = Tag::with_version(3); assert_eq!(tag.version(), 3);Run
fn set_version(&mut self, version: u8)
Sets the version of this tag.
ID3v2 versions 2 to 4 can be set. Trying to set any other version will cause a panic.
Any frames that could not be converted to the new version will be dropped.
Example
use id3::Tag; let mut tag = Tag::with_version(4); assert_eq!(tag.version(), 4); tag.set_version(3); assert_eq!(tag.version(), 3);Run
fn default_encoding(&self) -> Encoding
Returns the default unicode text encoding that should be used for this tag.
Example
use id3::Tag; use id3::frame::Encoding::{UTF16, UTF8}; let mut tag_v3 = Tag::with_version(3); assert_eq!(tag_v3.default_encoding(), UTF16); let mut tag_v4 = Tag::with_version(4); assert_eq!(tag_v4.default_encoding(), UTF8);Run
fn frames(&'a self) -> &'a Vec<Frame>
Returns a vector of references to all frames in the tag.
Example
use id3::{Tag, Frame}; let mut tag = Tag::new(); tag.push(Frame::new("TPE1")); tag.push(Frame::new("APIC")); assert_eq!(tag.frames().len(), 2);Run
fn get(&'a self, id: &str) -> Option<&'a Frame>
Returns a reference to the first frame with the specified identifier.
Example
use id3::{Tag, Frame}; let mut tag = Tag::new(); tag.push(Frame::new("TIT2")); assert!(tag.get("TIT2").is_some()); assert!(tag.get("TCON").is_none());Run
fn get_all(&'a self, id: &str) -> Vec<&'a Frame>
Returns a vector of references to frames with the specified identifier.
Example
use id3::{Tag, Frame}; let mut tag = Tag::new(); tag.push(Frame::new("TXXX")); tag.push(Frame::new("TXXX")); tag.push(Frame::new("TALB")); assert_eq!(tag.get_all("TXXX").len(), 2); assert_eq!(tag.get_all("TALB").len(), 1);Run
fn push(&mut self, frame: Frame) -> bool
Adds the frame to the tag. The frame identifier will attempt to be converted into the corresponding identifier for the tag version.
Returns whether the frame was added to the tag. The only reason the frame would not be added to the tag is if the frame identifier could not be converted from the frame version to the tag version.
Example
use id3::{Tag, Frame}; let mut tag = Tag::new(); tag.push(Frame::new("TALB")); assert_eq!(&tag.frames()[0].id[..], "TALB");Run
fn add_text_frame<K: Into<String>, V: Into<String>>(&mut self, id: K, text: V)
Adds a text frame using the default text encoding.
Example
use id3::Tag; let mut tag = Tag::new(); tag.add_text_frame("TCON", "Metal"); assert_eq!(&tag.get("TCON").unwrap().content.text()[..], "Metal");Run
fn add_text_frame_enc<K: Into<String>, V: Into<String>>(&mut self, id: K, text: V, encoding: Encoding)
Adds a text frame using the specified text encoding.
Example
use id3::Tag; use id3::frame::Encoding::UTF16; let mut tag = Tag::new(); tag.add_text_frame_enc("TRCK", "1/13", UTF16); assert_eq!(&tag.get("TRCK").unwrap().content.text()[..], "1/13");Run
fn remove_uuid(&mut self, uuid: &[u8])
Removes the frame with the specified uuid.
Example
use id3::{Tag, Frame}; let mut tag = Tag::new(); tag.push(Frame::new("TPE2")); assert_eq!(tag.frames().len(), 1); let uuid = tag.frames()[0].uuid.clone(); tag.remove_uuid(&uuid[..]); assert_eq!(tag.frames().len(), 0);Run
fn remove(&mut self, id: &str)
Removes all frames with the specified identifier.
Example
use id3::{Tag, Frame}; let mut tag = Tag::new(); tag.push(Frame::new("TXXX")); tag.push(Frame::new("TXXX")); tag.push(Frame::new("USLT")); assert_eq!(tag.frames().len(), 3); tag.remove("TXXX"); assert_eq!(tag.frames().len(), 1); tag.remove("USLT"); assert_eq!(tag.frames().len(), 0);Run
fn txxx(&self) -> Vec<(&str, &str)>
Returns a vector of the extended text (TXXX) key/value pairs.
Example
use id3::{Tag, Frame}; use id3::frame::{self, Content}; let mut tag = Tag::new(); let mut frame = Frame::new("TXXX"); frame.content = Content::ExtendedText(frame::ExtendedText { key: "key1".to_owned(), value: "value1".to_owned() }); tag.push(frame); let mut frame = Frame::new("TXXX"); frame.content = Content::ExtendedText(frame::ExtendedText { key: "key2".to_owned(), value: "value2".to_owned() }); tag.push(frame); assert_eq!(tag.txxx().len(), 2); assert!(tag.txxx().contains(&("key1", "value1"))); assert!(tag.txxx().contains(&("key2", "value2")));Run
fn add_txxx<K: Into<String>, V: Into<String>>(&mut self, key: K, value: V)
Adds a user defined text frame (TXXX).
Example
use id3::Tag; let mut tag = Tag::new(); tag.add_txxx("key1", "value1"); tag.add_txxx("key2", "value2"); assert_eq!(tag.txxx().len(), 2); assert!(tag.txxx().contains(&("key1", "value1"))); assert!(tag.txxx().contains(&("key2", "value2")));Run
fn add_txxx_enc<K: Into<String>, V: Into<String>>(&mut self, key: K, value: V, encoding: Encoding)
Adds a user defined text frame (TXXX) using the specified text encoding.
Example
use id3::Tag; use id3::frame::Encoding::UTF16; let mut tag = Tag::new(); tag.add_txxx_enc("key1", "value1", UTF16); tag.add_txxx_enc("key2", "value2", UTF16); assert_eq!(tag.txxx().len(), 2); assert!(tag.txxx().contains(&("key1", "value1"))); assert!(tag.txxx().contains(&("key2", "value2")));Run
fn remove_txxx(&mut self, key: Option<&str>, value: Option<&str>)
Removes the user defined text frame (TXXX) with the specified key and value.
A key or value may be None
to specify a wildcard value.
Example
use id3::Tag; let mut tag = Tag::new(); tag.add_txxx("key1", "value1"); tag.add_txxx("key2", "value2"); tag.add_txxx("key3", "value2"); tag.add_txxx("key4", "value3"); tag.add_txxx("key5", "value4"); assert_eq!(tag.txxx().len(), 5); tag.remove_txxx(Some("key1"), None); assert_eq!(tag.txxx().len(), 4); tag.remove_txxx(None, Some("value2")); assert_eq!(tag.txxx().len(), 2); tag.remove_txxx(Some("key4"), Some("value3")); assert_eq!(tag.txxx().len(), 1); tag.remove_txxx(None, None); assert_eq!(tag.txxx().len(), 0);Run
fn pictures(&self) -> Vec<&Picture>
Returns a vector of references to the pictures in the tag.
Example
use id3::{Tag, Frame}; use id3::frame::{Content, Picture}; let mut tag = Tag::new(); let mut frame = Frame::new("APIC"); frame.content = Content::Picture(Picture::new()); tag.push(frame); let mut frame = Frame::new("APIC"); frame.content = Content::Picture(Picture::new()); tag.push(frame); assert_eq!(tag.pictures().len(), 2);Run
fn add_picture<T: Into<String>>(&mut self, mime_type: T, picture_type: PictureType, data: Vec<u8>)
Adds a picture frame (APIC). Any other pictures with the same type will be removed from the tag.
Example
use id3::Tag; use id3::frame::PictureType::Other; let mut tag = Tag::new(); tag.add_picture("image/jpeg", Other, vec!()); tag.add_picture("image/png", Other, vec!()); assert_eq!(tag.pictures().len(), 1); assert_eq!(&tag.pictures()[0].mime_type[..], "image/png");Run
fn add_picture_enc<S: Into<String>, T: Into<String>>(&mut self, mime_type: S, picture_type: PictureType, description: T, data: Vec<u8>, encoding: Encoding)
Adds a picture frame (APIC) using the specified text encoding. Any other pictures with the same type will be removed from the tag.
Example
use id3::Tag; use id3::frame::PictureType::Other; use id3::frame::Encoding::UTF16; let mut tag = Tag::new(); tag.add_picture_enc("image/jpeg", Other, "", vec!(), UTF16); tag.add_picture_enc("image/png", Other, "", vec!(), UTF16); assert_eq!(tag.pictures().len(), 1); assert_eq!(&tag.pictures()[0].mime_type[..], "image/png");Run
fn remove_picture_type(&mut self, picture_type: PictureType)
Removes all pictures of the specified type.
Example
use id3::Tag; use id3::frame::PictureType::{CoverFront, Other}; let mut tag = Tag::new(); tag.add_picture("image/jpeg", CoverFront, vec!()); tag.add_picture("image/png", Other, vec!()); assert_eq!(tag.pictures().len(), 2); tag.remove_picture_type(CoverFront); assert_eq!(tag.pictures().len(), 1); assert_eq!(tag.pictures()[0].picture_type, Other);Run
fn comments(&self) -> Vec<(&str, &str)>
Returns a vector of comment (COMM) key/value pairs.
Example
use id3::{Tag, Frame}; use id3::frame::{Content, Comment}; let mut tag = Tag::new(); let mut frame = Frame::new("COMM"); frame.content = Content::Comment(Comment { lang: "eng".to_owned(), description: "key1".to_owned(), text: "value1".to_owned() }); tag.push(frame); let mut frame = Frame::new("COMM"); frame.content = Content::Comment(Comment { lang: "eng".to_owned(), description: "key2".to_owned(), text: "value2".to_owned() }); tag.push(frame); assert_eq!(tag.comments().len(), 2); assert!(tag.comments().contains(&("key1", "value1"))); assert!(tag.comments().contains(&("key2", "value2")));Run
fn add_comment<K: Into<String>, V: Into<String>>(&mut self, description: K, text: V)
Adds a comment (COMM).
Example
use id3::Tag; let mut tag = Tag::new(); tag.add_comment("key1", "value1"); tag.add_comment("key2", "value2"); assert_eq!(tag.comments().len(), 2); assert!(tag.comments().contains(&("key1", "value1"))); assert!(tag.comments().contains(&("key2", "value2")));Run
fn add_comment_enc<L: Into<String>, K: Into<String>, V: Into<String>>(&mut self, lang: L, description: K, text: V, encoding: Encoding)
Adds a comment (COMM) using the specified text encoding.
Example
use id3::Tag; use id3::frame::Encoding::UTF16; let mut tag = Tag::new(); tag.add_comment_enc("eng", "key1", "value1", UTF16); tag.add_comment_enc("eng", "key2", "value2", UTF16); assert_eq!(tag.comments().len(), 2); assert!(tag.comments().contains(&("key1", "value1"))); assert!(tag.comments().contains(&("key2", "value2")));Run
fn remove_comment(&mut self, description: Option<&str>, text: Option<&str>)
Removes the comment (COMM) with the specified key and value.
A key or value may be None
to specify a wildcard value.
Example
use id3::Tag; let mut tag = Tag::new(); tag.add_comment("key1", "value1"); tag.add_comment("key2", "value2"); tag.add_comment("key3", "value2"); tag.add_comment("key4", "value3"); tag.add_comment("key5", "value4"); assert_eq!(tag.comments().len(), 5); tag.remove_comment(Some("key1"), None); assert_eq!(tag.comments().len(), 4); tag.remove_comment(None, Some("value2")); assert_eq!(tag.comments().len(), 2); tag.remove_comment(Some("key4"), Some("value3")); assert_eq!(tag.comments().len(), 1); tag.remove_comment(None, None); assert_eq!(tag.comments().len(), 0);Run
fn year(&self) -> Option<usize>
Returns the year (TYER).
Returns None
if the year frame could not be found or if it could not be parsed.
Example
use id3::{Tag, Frame}; use id3::frame::Content; let mut tag = Tag::new(); assert!(tag.year().is_none()); let mut frame_valid = Frame::new("TYER"); frame_valid.content = Content::Text("2014".to_owned()); tag.push(frame_valid); assert_eq!(tag.year().unwrap(), 2014); tag.remove("TYER"); let mut frame_invalid = Frame::new("TYER"); frame_invalid.content = Content::Text("nope".to_owned()); tag.push(frame_invalid); assert!(tag.year().is_none());Run
fn set_year(&mut self, year: usize)
Sets the year (TYER).
Example
use id3::Tag; let mut tag = Tag::new(); tag.set_year(2014); assert_eq!(tag.year().unwrap(), 2014);Run
fn set_year_enc(&mut self, year: usize, encoding: Encoding)
Sets the year (TYER) using the specified text encoding.
Example
use id3::Tag; use id3::frame::Encoding::UTF16; let mut tag = Tag::new(); tag.set_year_enc(2014, UTF16); assert_eq!(tag.year().unwrap(), 2014);Run
fn date_recorded(&self) -> Option<Timestamp>
Return the content of the TRDC frame, if any
Example
use id3::Tag; use id3::Timestamp; let mut tag = Tag::new(); tag.set_date_recorded(Timestamp{ year: Some(2014), month: None, day: None, hour: None, minute: None, second: None }); assert_eq!(tag.date_recorded().unwrap().year, Some(2014));Run
fn set_date_recorded(&mut self, timestamp: Timestamp)
Sets the content of the TDRC frame
Example
use id3::Tag; use id3::Timestamp; let mut tag = Tag::new(); tag.set_date_recorded(Timestamp{ year: Some(2014), month: None, day: None, hour: None, minute: None, second: None }); assert_eq!(tag.date_recorded().unwrap().year, Some(2014));Run
fn date_released(&self) -> Option<Timestamp>
Return the content of the TDRL frame, if any
Example
use id3::Tag; use id3::Timestamp; let mut tag = Tag::new(); tag.set_date_released(Timestamp{ year: Some(2014), month: None, day: None, hour: None, minute: None, second: None }); assert_eq!(tag.date_released().unwrap().year, Some(2014));Run
fn set_date_released(&mut self, timestamp: Timestamp)
Sets the content of the TDRL frame
Example
use id3::Tag; use id3::Timestamp; let mut tag = Tag::new(); tag.set_date_released(Timestamp{ year: Some(2014), month: None, day: None, hour: None, minute: None, second: None }); assert_eq!(tag.date_released().unwrap().year, Some(2014));Run
fn artist(&self) -> Option<&str>
Returns the artist (TPE1).
Example
use id3::{Frame, Tag}; use id3::frame::Content; let mut tag = Tag::new(); let mut frame = Frame::new("TPE1"); frame.content = Content::Text("artist".to_owned()); tag.push(frame); assert_eq!(tag.artist().unwrap(), "artist");Run
fn set_artist<T: Into<String>>(&mut self, artist: T)
Sets the artist (TPE1).
Example
use id3::Tag; let mut tag = Tag::new(); tag.set_artist("artist"); assert_eq!(tag.artist().unwrap(), "artist");Run
fn set_artist_enc<T: Into<String>>(&mut self, artist: T, encoding: Encoding)
Sets the artist (TPE1) using the specified text encoding.
Example
use id3::Tag; use id3::frame::Encoding::UTF16; let mut tag = Tag::new(); tag.set_artist_enc("artist", UTF16); assert_eq!(tag.artist().unwrap(), "artist");Run
fn remove_artist(&mut self)
Removes the artist (TPE1).
Example
use id3::Tag; let mut tag = Tag::new(); tag.set_artist("artist"); assert!(tag.artist().is_some()); tag.remove_artist(); assert!(tag.artist().is_none());Run
fn album_artist(&self) -> Option<&str>
Sets the album artist (TPE2).
Example
use id3::{Frame, Tag}; use id3::frame::Content; let mut tag = Tag::new(); let mut frame = Frame::new("TPE2"); frame.content = Content::Text("artist".to_owned()); tag.push(frame); assert_eq!(tag.album_artist().unwrap(), "artist");Run
fn set_album_artist<T: Into<String>>(&mut self, album_artist: T)
Sets the album artist (TPE2).
Example
use id3::Tag; let mut tag = Tag::new(); tag.set_album_artist("artist"); assert_eq!(tag.album_artist().unwrap(), "artist");Run
fn set_album_artist_enc<T: Into<String>>(&mut self, album_artist: T, encoding: Encoding)
Sets the album artist (TPE2) using the specified text encoding.
Example
use id3::Tag; use id3::frame::Encoding::UTF16; let mut tag = Tag::new(); tag.set_album_artist_enc("album artist", UTF16); assert_eq!(tag.album_artist().unwrap(), "album artist");Run
fn remove_album_artist(&mut self)
Removes the album artist (TPE2).
Example
use id3::Tag; let mut tag = Tag::new(); tag.set_album_artist("artist"); assert!(tag.album_artist().is_some()); tag.remove_album_artist(); assert!(tag.album_artist().is_none());Run
fn album(&self) -> Option<&str>
Returns the album (TALB).
Example
use id3::{Frame, Tag}; use id3::frame::Content; let mut tag = Tag::new(); let mut frame = Frame::new("TALB"); frame.content = Content::Text("album".to_owned()); tag.push(frame); assert_eq!(tag.album().unwrap(), "album");Run
fn set_album<T: Into<String>>(&mut self, album: T)
Sets the album (TALB).
Example
use id3::Tag; let mut tag = Tag::new(); tag.set_album("album"); assert_eq!(tag.album().unwrap(), "album");Run
fn set_album_enc<T: Into<String>>(&mut self, album: T, encoding: Encoding)
Sets the album (TALB) using the specified text encoding.
Example
use id3::Tag; use id3::frame::Encoding::UTF16; let mut tag = Tag::new(); tag.set_album_enc("album", UTF16); assert_eq!(tag.album().unwrap(), "album");Run
fn remove_album(&mut self)
Removes the album (TALB).
Example
use id3::Tag; let mut tag = Tag::new(); tag.set_album("album"); assert!(tag.album().is_some()); tag.remove_album(); assert!(tag.album().is_none());Run
fn title(&self) -> Option<&str>
Returns the title (TIT2).
Example
use id3::{Frame, Tag}; use id3::frame::Content; let mut tag = Tag::new(); let mut frame = Frame::new("TIT2"); frame.content = Content::Text("title".to_owned()); tag.push(frame); assert_eq!(tag.title().unwrap(), "title");Run
fn set_title<T: Into<String>>(&mut self, title: T)
Sets the title (TIT2).
Example
use id3::Tag; let mut tag = Tag::new(); tag.set_title("title"); assert_eq!(tag.title().unwrap(), "title");Run
fn set_title_enc<T: Into<String>>(&mut self, title: T, encoding: Encoding)
Sets the song title (TIT2) using the specified text encoding.
Example
use id3::Tag; use id3::frame::Encoding::UTF16; let mut tag = Tag::new(); tag.set_title_enc("title", UTF16); assert_eq!(tag.title().unwrap(), "title");Run
fn remove_title(&mut self)
Removes the title (TIT2).
Example
use id3::Tag; let mut tag = Tag::new(); tag.set_title("title"); assert!(tag.title().is_some()); tag.remove_title(); assert!(tag.title().is_none());Run
fn duration(&self) -> Option<u32>
Returns the duration (TLEN).
Example
use id3::{Frame, Tag}; use id3::frame::Content; let mut tag = Tag::new(); let mut frame = Frame::new("TLEN"); frame.content = Content::Text("350".to_owned()); tag.push(frame); assert_eq!(tag.duration().unwrap(), 350);Run
fn set_duration(&mut self, duration: u32)
Sets the duration (TLEN).
Example
use id3::Tag; let mut tag = Tag::new(); tag.set_duration(350); assert_eq!(tag.duration().unwrap(), 350);Run
fn remove_duration(&mut self)
Removes the duration (TLEN).
Example
use id3::Tag; let mut tag = Tag::new(); tag.set_duration(350); assert!(tag.duration().is_some()); tag.remove_duration(); assert!(tag.duration().is_none());Run
fn genre(&self) -> Option<&str>
Returns the genre (TCON).
Example
use id3::{Frame, Tag}; use id3::frame::Content; let mut tag = Tag::new(); let mut frame = Frame::new("TCON"); frame.content = Content::Text("genre".to_owned()); tag.push(frame); assert_eq!(tag.genre().unwrap(), "genre");Run
fn set_genre<T: Into<String>>(&mut self, genre: T)
Sets the genre (TCON).
Example
use id3::Tag; let mut tag = Tag::new(); tag.set_genre("genre"); assert_eq!(tag.genre().unwrap(), "genre");Run
fn set_genre_enc<T: Into<String>>(&mut self, genre: T, encoding: Encoding)
Sets the genre (TCON) using the specified text encoding.
Example
use id3::Tag; use id3::frame::Encoding::UTF16; let mut tag = Tag::new(); tag.set_genre_enc("genre", UTF16); assert_eq!(tag.genre().unwrap(), "genre");Run
fn remove_genre(&mut self)
Removes the genre (TCON).
Example
use id3::Tag; let mut tag = Tag::new(); tag.set_genre("genre"); assert!(tag.genre().is_some()); tag.remove_genre(); assert!(tag.genre().is_none());Run
fn disc(&self) -> Option<u32>
Returns the disc number (TPOS).
Example
use id3::{Tag, Frame}; use id3::frame::Content; let mut tag = Tag::new(); assert!(tag.disc().is_none()); let mut frame_valid = Frame::new("TPOS"); frame_valid.content = Content::Text("4".to_owned()); tag.push(frame_valid); assert_eq!(tag.disc().unwrap(), 4); tag.remove("TPOS"); let mut frame_invalid = Frame::new("TPOS"); frame_invalid.content = Content::Text("nope".to_owned()); tag.push(frame_invalid); assert!(tag.disc().is_none());Run
fn set_disc(&mut self, disc: u32)
Sets the disc (TPOS).
Example
use id3::Tag; let mut tag = Tag::new(); tag.set_disc(2); assert_eq!(tag.disc().unwrap(), 2);Run
fn set_disc_enc(&mut self, disc: u32, encoding: Encoding)
Sets the disc number (TPOS) using the specified text encoding.
Example
use id3::Tag; use id3::frame::Encoding::UTF16; let mut tag = Tag::new(); tag.set_disc_enc(2, UTF16); assert_eq!(tag.disc().unwrap(), 2);Run
fn remove_disc(&mut self)
Removes the disc number (TPOS).
Example
use id3::Tag; let mut tag = Tag::new(); tag.set_disc(3); assert!(tag.disc().is_some()); tag.remove_disc(); assert!(tag.disc().is_none());Run
fn total_discs(&self) -> Option<u32>
Returns the total number of discs (TPOS).
Example
use id3::{Tag, Frame}; use id3::frame::Content; let mut tag = Tag::new(); assert!(tag.disc().is_none()); let mut frame_valid = Frame::new("TPOS"); frame_valid.content = Content::Text("4/10".to_owned()); tag.push(frame_valid); assert_eq!(tag.total_discs().unwrap(), 10); tag.remove("TPOS"); let mut frame_invalid = Frame::new("TPOS"); frame_invalid.content = Content::Text("4/nope".to_owned()); tag.push(frame_invalid); assert!(tag.total_discs().is_none());Run
fn set_total_discs(&mut self, total_discs: u32)
Sets the total number of discs (TPOS).
Example
use id3::Tag; let mut tag = Tag::new(); tag.set_total_discs(10); assert_eq!(tag.total_discs().unwrap(), 10);Run
fn set_total_discs_enc(&mut self, total_discs: u32, encoding: Encoding)
Sets the total number of discs (TPOS) using the specified text encoding.
Example
use id3::Tag; use id3::frame::Encoding::UTF16; let mut tag = Tag::new(); tag.set_total_discs_enc(12, UTF16); assert_eq!(tag.total_discs().unwrap(), 12);Run
fn remove_total_discs(&mut self)
Removes the total number of discs (TPOS).
Example
use id3::Tag; let mut tag = Tag::new(); tag.set_total_discs(10); assert!(tag.total_discs().is_some()); tag.remove_total_discs(); assert!(tag.total_discs().is_none());Run
fn track(&self) -> Option<u32>
Returns the track number (TRCK).
Example
use id3::{Tag, Frame}; use id3::frame::Content; let mut tag = Tag::new(); assert!(tag.track().is_none()); let mut frame_valid = Frame::new("TRCK"); frame_valid.content = Content::Text("4".to_owned()); tag.push(frame_valid); assert_eq!(tag.track().unwrap(), 4); tag.remove("TRCK"); let mut frame_invalid = Frame::new("TRCK"); frame_invalid.content = Content::Text("nope".to_owned()); tag.push(frame_invalid); assert!(tag.track().is_none());Run
fn set_track(&mut self, track: u32)
Sets the track (TRCK).
Example
use id3::Tag; let mut tag = Tag::new(); tag.set_track(10); assert_eq!(tag.track().unwrap(), 10);Run
fn set_track_enc(&mut self, track: u32, encoding: Encoding)
Sets the track number (TRCK) using the specified text encoding.
Example
use id3::Tag; use id3::frame::Encoding::UTF16; let mut tag = Tag::new(); tag.set_track_enc(5, UTF16); assert_eq!(tag.track().unwrap(), 5);Run
fn remove_track(&mut self)
Removes the track number (TRCK).
Example
use id3::Tag; let mut tag = Tag::new(); tag.set_track(10); assert!(tag.track().is_some()); tag.remove_track(); assert!(tag.track().is_none());Run
fn total_tracks(&self) -> Option<u32>
Returns the total number of tracks (TRCK).
Example
use id3::{Tag, Frame}; use id3::frame::Content; let mut tag = Tag::new(); assert!(tag.total_tracks().is_none()); let mut frame_valid = Frame::new("TRCK"); frame_valid.content = Content::Text("4/10".to_owned()); tag.push(frame_valid); assert_eq!(tag.total_tracks().unwrap(), 10); tag.remove("TRCK"); let mut frame_invalid = Frame::new("TRCK"); frame_invalid.content = Content::Text("4/nope".to_owned()); tag.push(frame_invalid); assert!(tag.total_tracks().is_none());Run
fn set_total_tracks(&mut self, total_tracks: u32)
Sets the total number of tracks (TRCK).
Example
use id3::Tag; let mut tag = Tag::new(); tag.set_total_tracks(10); assert_eq!(tag.total_tracks().unwrap(), 10);Run
fn set_total_tracks_enc(&mut self, total_tracks: u32, encoding: Encoding)
Sets the total number of tracks (TRCK) using the specified text encoding.
Example
use id3::Tag; use id3::frame::Encoding::UTF16; let mut tag = Tag::new(); tag.set_total_tracks_enc(12, UTF16); assert_eq!(tag.total_tracks().unwrap(), 12);Run
fn remove_total_tracks(&mut self)
Removes the total number of tracks (TCON).
Example
use id3::Tag; let mut tag = Tag::new(); tag.set_total_tracks(10); assert!(tag.total_tracks().is_some()); tag.remove_total_tracks(); assert!(tag.total_tracks().is_none());Run
fn lyrics(&self) -> Option<&str>
Returns the lyrics (USLT).
Example
use id3::{Frame, Tag}; use id3::frame::Content; use id3::frame::Lyrics; let mut tag = Tag::new(); let mut frame = Frame::new("USLT"); frame.content = Content::Lyrics(Lyrics { lang: "eng".to_owned(), description: "description".to_owned(), text: "lyrics".to_owned() }); tag.push(frame); assert_eq!(tag.lyrics().unwrap(), "lyrics");Run
fn set_lyrics<T: Into<String>>(&mut self, text: T)
Sets the lyrics (USLT).
Example
use id3::Tag; let mut tag = Tag::new(); tag.set_lyrics("lyrics"); assert_eq!(tag.lyrics().unwrap(), "lyrics");Run
fn set_lyrics_enc<L: Into<String>, K: Into<String>, V: Into<String>>(&mut self, lang: L, description: K, text: V, encoding: Encoding)
Sets the lyrics text (USLT) using the specified text encoding.
Example
use id3::Tag; use id3::frame::Encoding::UTF16; let mut tag = Tag::new(); tag.set_lyrics_enc("eng", "description", "lyrics", UTF16); assert_eq!(tag.lyrics().unwrap(), "lyrics");Run
fn remove_lyrics(&mut self)
Removes the lyrics text (USLT) from the tag.
Exmaple
use id3::Tag; let mut tag = Tag::new(); tag.set_lyrics("lyrics"); assert!(tag.lyrics().is_some()); tag.remove_lyrics(); assert!(tag.lyrics().is_none());Run
fn skip_metadata<R: Read + Seek>(reader: &mut R) -> Vec<u8>
Returns the contents of the reader without any ID3 metadata.
fn is_candidate<R: Read + Seek>(reader: &mut R) -> bool
Will return true if the reader is a candidate for an ID3 tag. The reader position will be reset back to the previous position before returning.
fn read_from(reader: &mut Read) -> Result<Tag>
Attempts to read an ID3 tag from the reader.
fn write_to(&mut self, writer: &mut Write) -> Result<()>
Attempts to write the ID3 tag to the writer.
fn read_from_path<P: AsRef<Path>>(path: P) -> Result<Tag>
Attempts to read an ID3 tag from the file at the indicated path.
fn write_to_path<P: AsRef<Path>>(&mut self, path: P) -> Result<()>
Attempts to write the ID3 tag from the file at the indicated path. If the specified path is the same path which the tag was read from, then the tag will be written to the padding if possible.
fn save(&mut self) -> Result<()>
Attempts to save the tag back to the file which it was read from. An error with kind
InvalidInput
will be returned if this is called on a tag which was not read from a file.