pub struct Tag { /* private fields */ }
Expand description
An ID3 tag containing zero or more Frame
s.
Implementations§
Source§impl<'a> Tag
impl<'a> Tag
Sourcepub fn with_version(version: Version) -> Tag
pub fn with_version(version: Version) -> Tag
Used for creating new tag with a specific version.
Sourcepub fn is_candidate(reader: impl Read + Seek) -> Result<bool>
pub fn is_candidate(reader: impl Read + Seek) -> Result<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.
Sourcepub fn skip(reader: impl Read + Seek) -> Result<bool>
pub fn skip(reader: impl Read + Seek) -> Result<bool>
Detects the presence of an ID3v2 tag at the current position of the reader and skips it if is found. Returns true if a tag was found.
Sourcepub fn remove_from_path(path: impl AsRef<Path>) -> Result<bool>
pub fn remove_from_path(path: impl AsRef<Path>) -> Result<bool>
Removes an ID3v2 tag from the file at the specified path.
Returns true if the file initially contained a tag.
Sourcepub fn remove_from_file(file: impl StorageFile) -> Result<bool>
pub fn remove_from_file(file: impl StorageFile) -> Result<bool>
Removes an ID3v2 tag from the specified file.
Returns true if the file initially contained a tag.
Sourcepub fn read_from(reader: impl Read) -> Result<Tag>
👎Deprecated: use read_from2
pub fn read_from(reader: impl Read) -> Result<Tag>
Attempts to read an ID3 tag from the reader.
Sourcepub fn read_from2(reader: impl Read + Seek) -> Result<Tag>
pub fn read_from2(reader: impl Read + Seek) -> Result<Tag>
Attempts to read an ID3 tag from the reader.
The file format is detected using header magic.
In the case of both Aiff/Wav tags and a ID3 header being present, the header takes precense.
Sourcepub fn read_from_path(path: impl AsRef<Path>) -> Result<Tag>
pub fn read_from_path(path: impl AsRef<Path>) -> Result<Tag>
Attempts to read an ID3 tag from the file at the indicated path.
Sourcepub fn read_from_aiff(reader: impl Read + Seek) -> Result<Tag>
👎Deprecated: use read_from
pub fn read_from_aiff(reader: impl Read + Seek) -> Result<Tag>
Reads an AIFF stream and returns any present ID3 tag.
Sourcepub fn read_from_aiff_path(path: impl AsRef<Path>) -> Result<Tag>
👎Deprecated: use read_from_path
pub fn read_from_aiff_path(path: impl AsRef<Path>) -> Result<Tag>
Reads an AIFF file at the specified path and returns any present ID3 tag.
Sourcepub fn read_from_aiff_file(file: impl StorageFile) -> Result<Tag>
👎Deprecated: use read_from_file
pub fn read_from_aiff_file(file: impl StorageFile) -> Result<Tag>
Reads an AIFF file and returns any present ID3 tag.
Sourcepub fn read_from_wav(reader: impl Read + Seek) -> Result<Tag>
👎Deprecated: use read_from
pub fn read_from_wav(reader: impl Read + Seek) -> Result<Tag>
Reads an WAV stream and returns any present ID3 tag.
Sourcepub fn read_from_wav_path(path: impl AsRef<Path>) -> Result<Tag>
👎Deprecated: use read_from_path
pub fn read_from_wav_path(path: impl AsRef<Path>) -> Result<Tag>
Reads an WAV file at the specified path and returns any present ID3 tag.
Sourcepub fn read_from_wav_file(file: impl StorageFile) -> Result<Tag>
👎Deprecated: use read_from_file
pub fn read_from_wav_file(file: impl StorageFile) -> Result<Tag>
Reads an WAV file and returns any present ID3 tag.
Sourcepub fn write_to(&self, writer: impl Write, version: Version) -> Result<()>
pub fn write_to(&self, writer: impl Write, version: Version) -> Result<()>
Attempts to write the ID3 tag to the writer using the specified version.
Note that the plain tag is written, regardless of the original contents. To safely encode a
tag to an MP3 file, use Tag::write_to_file
.
Sourcepub fn write_to_file(
&self,
file: impl StorageFile,
version: Version,
) -> Result<()>
pub fn write_to_file( &self, file: impl StorageFile, version: Version, ) -> 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.
Sourcepub fn write_to_path(
&self,
path: impl AsRef<Path>,
version: Version,
) -> Result<()>
pub fn write_to_path( &self, path: impl AsRef<Path>, version: Version, ) -> Result<()>
Conventience function for [write_to_file
].
Sourcepub fn write_to_aiff_path(
&self,
path: impl AsRef<Path>,
version: Version,
) -> Result<()>
👎Deprecated: use write_to_path
pub fn write_to_aiff_path( &self, path: impl AsRef<Path>, version: Version, ) -> Result<()>
Overwrite WAV file ID3 chunk in a file
Sourcepub fn write_to_aiff_file(
&self,
file: impl StorageFile,
version: Version,
) -> Result<()>
👎Deprecated: use write_to_file
pub fn write_to_aiff_file( &self, file: impl StorageFile, version: Version, ) -> Result<()>
Overwrite AIFF file ID3 chunk in a file. The file must be opened read/write.
Sourcepub fn write_to_wav_path(
&self,
path: impl AsRef<Path>,
version: Version,
) -> Result<()>
👎Deprecated: use write_to_path
pub fn write_to_wav_path( &self, path: impl AsRef<Path>, version: Version, ) -> Result<()>
Overwrite WAV file ID3 chunk
Sourcepub fn write_to_wav_file(
&self,
file: impl StorageFile,
version: Version,
) -> Result<()>
👎Deprecated: use write_to_file
pub fn write_to_wav_file( &self, file: impl StorageFile, version: Version, ) -> Result<()>
Overwrite AIFF file ID3 chunk in a file. The file must be opened read/write.
Sourcepub fn frames(&'a self) -> impl Iterator<Item = &'a Frame> + 'a
pub fn frames(&'a self) -> impl Iterator<Item = &'a Frame> + 'a
Returns an iterator over the all frames in the tag.
§Example
use id3::{Content, Frame, Tag, TagLike};
let mut tag = Tag::new();
tag.add_frame(Frame::with_content("TPE1", Content::Text("".to_string())));
tag.add_frame(Frame::with_content("APIC", Content::Text("".to_string())));
assert_eq!(tag.frames().count(), 2);
Sourcepub fn extended_texts(&'a self) -> impl Iterator<Item = &'a ExtendedText> + 'a
pub fn extended_texts(&'a self) -> impl Iterator<Item = &'a ExtendedText> + 'a
Returns an iterator over the extended texts in the tag.
Sourcepub fn extended_links(&'a self) -> impl Iterator<Item = &'a ExtendedLink> + 'a
pub fn extended_links(&'a self) -> impl Iterator<Item = &'a ExtendedLink> + 'a
Returns an iterator over the extended links in the tag.
Sourcepub fn encapsulated_objects(
&'a self,
) -> impl Iterator<Item = &'a EncapsulatedObject> + 'a
pub fn encapsulated_objects( &'a self, ) -> impl Iterator<Item = &'a EncapsulatedObject> + 'a
Returns an iterator over the General Encapsulated Object (GEOB) frames in the tag.
Sourcepub fn comments(&'a self) -> impl Iterator<Item = &'a Comment> + 'a
pub fn comments(&'a self) -> impl Iterator<Item = &'a Comment> + 'a
Returns an iterator over the comments in the tag.
§Example
use id3::{Frame, Tag, TagLike};
use id3::frame::{Content, Comment};
let mut tag = Tag::new();
let frame = Frame::with_content("COMM", Content::Comment(Comment {
lang: "eng".to_owned(),
description: "key1".to_owned(),
text: "value1".to_owned()
}));
tag.add_frame(frame);
let frame = Frame::with_content("COMM", Content::Comment(Comment {
lang: "eng".to_owned(),
description: "key2".to_owned(),
text: "value2".to_owned()
}));
tag.add_frame(frame);
assert_eq!(tag.comments().count(), 2);
Sourcepub fn lyrics(&'a self) -> impl Iterator<Item = &'a Lyrics> + 'a
pub fn lyrics(&'a self) -> impl Iterator<Item = &'a Lyrics> + 'a
Returns an iterator over the lyrics frames in the tag.
Sourcepub fn synchronised_lyrics(
&'a self,
) -> impl Iterator<Item = &'a SynchronisedLyrics> + 'a
pub fn synchronised_lyrics( &'a self, ) -> impl Iterator<Item = &'a SynchronisedLyrics> + 'a
Returns an iterator over the synchronised lyrics frames in the tag.
Sourcepub fn pictures(&'a self) -> impl Iterator<Item = &'a Picture> + 'a
pub fn pictures(&'a self) -> impl Iterator<Item = &'a Picture> + 'a
Returns an iterator over the pictures in the tag.
§Example
use id3::{Frame, Tag, TagLike};
use id3::frame::{Content, Picture, PictureType};
let mut tag = Tag::new();
let picture = Picture {
mime_type: String::new(),
picture_type: PictureType::Other,
description: String::new(),
data: Vec::new(),
};
tag.add_frame(Frame::with_content("APIC", Content::Picture(picture.clone())));
tag.add_frame(Frame::with_content("APIC", Content::Picture(picture.clone())));
assert_eq!(tag.pictures().count(), 1);
Sourcepub fn unique_file_identifiers(
&'a self,
) -> impl Iterator<Item = &'a UniqueFileIdentifier> + 'a
pub fn unique_file_identifiers( &'a self, ) -> impl Iterator<Item = &'a UniqueFileIdentifier> + 'a
Returns an iterator over the Unique File Identifiers (ufid) in the tag.
§Example
use id3::{Frame, Tag, TagLike};
use id3::frame::{Content, UniqueFileIdentifier};
let mut tag = Tag::new();
let unique_file_identifier = UniqueFileIdentifier {
owner_identifier: String::from("http://www.id3.org/dummy/ufid.html"),
identifier: "7FZo5fMqyG5Ys1dm8F1FHa".into(),
};
tag.add_frame(Frame::with_content("UFID", Content::UniqueFileIdentifier(unique_file_identifier.clone())));
tag.add_frame(Frame::with_content("UFID", Content::UniqueFileIdentifier(unique_file_identifier.clone())));
assert_eq!(tag.unique_file_identifiers().count(), 1);
Sourcepub fn chapters(&self) -> impl Iterator<Item = &Chapter>
pub fn chapters(&self) -> impl Iterator<Item = &Chapter>
Returns an iterator over all chapters (CHAP) in the tag.
§Example
use id3::{Tag, TagLike};
use id3::frame::{Chapter, Content, Frame};
let mut tag = Tag::new();
tag.add_frame(Chapter{
element_id: "01".to_string(),
start_time: 1000,
end_time: 2000,
start_offset: 0xff,
end_offset: 0xff,
frames: Vec::new(),
});
tag.add_frame(Chapter{
element_id: "02".to_string(),
start_time: 2000,
end_time: 3000,
start_offset: 0xff,
end_offset: 0xff,
frames: Vec::new(),
});
assert_eq!(2, tag.chapters().count());
Sourcepub fn tables_of_contents(&self) -> impl Iterator<Item = &TableOfContents>
pub fn tables_of_contents(&self) -> impl Iterator<Item = &TableOfContents>
Returns an iterator over all tables of contents (CTOC) in the tag.
§Example
use id3::{Tag, TagLike};
use id3::frame::{Chapter, TableOfContents, Content, Frame};
let mut tag = Tag::new();
tag.add_frame(Chapter{
element_id: "chap01".to_string(),
start_time: 1000,
end_time: 2000,
start_offset: 0xff,
end_offset: 0xff,
frames: Vec::new(),
});
tag.add_frame(TableOfContents{
element_id: "internalTable01".to_string(),
top_level: false,
ordered: false,
elements: Vec::new(),
frames: Vec::new(),
});
tag.add_frame(TableOfContents{
element_id: "01".to_string(),
top_level: true,
ordered: true,
elements: vec!["internalTable01".to_string(),"chap01".to_string()],
frames: Vec::new(),
});
assert_eq!(2, tag.tables_of_contents().count());
Sourcepub fn involved_people_lists(&self) -> impl Iterator<Item = &InvolvedPeopleList>
pub fn involved_people_lists(&self) -> impl Iterator<Item = &InvolvedPeopleList>
Returns an iterator over all involved people lists (IPLS
in ID3v2.3, TIPL
and TMCL
in
ID3v2.4) in the tag.
§Examples
§IPLS
frame (ID3v2.3)
use id3::{Frame, Tag, TagLike, Version};
use id3::frame::{Content, InvolvedPeopleList, InvolvedPeopleListItem};
let mut tag = Tag::with_version(Version::Id3v23);
let frame = Frame::with_content("IPLS", Content::InvolvedPeopleList(InvolvedPeopleList {
items: vec![
InvolvedPeopleListItem {
involvement: "drums (drum set)".to_string(),
involvee: "Gene Krupa".to_string(),
},
InvolvedPeopleListItem {
involvement: "piano".to_string(),
involvee: "Hank Jones".to_string(),
},
InvolvedPeopleListItem {
involvement: "tenor saxophone".to_string(),
involvee: "Frank Socolow".to_string(),
},
InvolvedPeopleListItem {
involvement: "tenor saxophone".to_string(),
involvee: "Eddie Wasserman".to_string(),
},
],
}));
tag.add_frame(frame);
assert_eq!(1, tag.involved_people_lists().count());
assert_eq!(4, tag.involved_people_lists().flat_map(|list| list.items.iter()).count());
§TIPL
/TMCL
frames (ID3v2.4)
use id3::{Frame, Tag, TagLike, Version};
use id3::frame::{Content, InvolvedPeopleList, InvolvedPeopleListItem};
let mut tag = Tag::with_version(Version::Id3v24);
let frame = Frame::with_content("TMCL", Content::InvolvedPeopleList(InvolvedPeopleList {
items: vec![
InvolvedPeopleListItem {
involvement: "drums (drum set)".to_string(),
involvee: "Gene Krupa".to_string(),
},
InvolvedPeopleListItem {
involvement: "piano".to_string(),
involvee: "Hank Jones".to_string(),
},
InvolvedPeopleListItem {
involvement: "tenor saxophone".to_string(),
involvee: "Frank Socolow".to_string(),
},
InvolvedPeopleListItem {
involvement: "tenor saxophone".to_string(),
involvee: "Eddie Wasserman".to_string(),
},
],
}));
tag.add_frame(frame);
let frame = Frame::with_content("TIPL", Content::InvolvedPeopleList(InvolvedPeopleList {
items: vec![
InvolvedPeopleListItem {
involvement: "executive producer".to_string(),
involvee: "Ken Druker".to_string(),
},
InvolvedPeopleListItem {
involvement: "arranger".to_string(),
involvee: "Gerry Mulligan".to_string(),
},
],
}));
tag.add_frame(frame);
assert_eq!(2, tag.involved_people_lists().count());
assert_eq!(6, tag.involved_people_lists().flat_map(|list| list.items.iter()).count());
Trait Implementations§
Source§impl Extend<Frame> for Tag
impl Extend<Frame> for Tag
Source§fn extend<I: IntoIterator<Item = Frame>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = Frame>>(&mut self, iter: I)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Source§impl FromIterator<Frame> for Tag
impl FromIterator<Frame> for Tag
Source§impl TagLike for Tag
impl TagLike for Tag
Source§fn get(&self, id: impl AsRef<str>) -> Option<&Frame>
fn get(&self, id: impl AsRef<str>) -> Option<&Frame>
Source§fn add_frame(&mut self, new_frame: impl Into<Frame>) -> Option<Frame>
fn add_frame(&mut self, new_frame: impl Into<Frame>) -> Option<Frame>
Source§fn set_text(&mut self, id: impl AsRef<str>, text: impl Into<String>)
fn set_text(&mut self, id: impl AsRef<str>, text: impl Into<String>)
Source§fn set_text_values(
&mut self,
id: impl AsRef<str>,
texts: impl IntoIterator<Item = impl Into<String>>,
)
fn set_text_values( &mut self, id: impl AsRef<str>, texts: impl IntoIterator<Item = impl Into<String>>, )
Source§fn remove(&mut self, id: impl AsRef<str>) -> Vec<Frame>
fn remove(&mut self, id: impl AsRef<str>) -> Vec<Frame>
Source§fn year(&self) -> Option<i32>
fn year(&self) -> Option<i32>
None
if the year frame could not be found or if it could not be parsed. Read more