Struct id3::Tag

source ·
pub struct Tag { /* private fields */ }
Expand description

An ID3 tag containing zero or more Frames.

Implementations§

source§

impl<'a> Tag

source

pub fn new() -> Tag

Creates a new ID3v2.4 tag with no frames.

source

pub fn with_version(version: Version) -> Tag

Used for creating new tag with a specific version.

source

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.

source

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.

source

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.

source

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.

source

pub fn read_from(reader: impl Read) -> Result<Tag>

👎Deprecated: use read_from2

Attempts to read an ID3 tag from the reader.

source

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.

source

pub fn read_from_path(path: impl AsRef<Path>) -> Result<Tag>

Attempts to read an ID3 tag from the file at the indicated path.

source

pub fn read_from_aiff(reader: impl Read + Seek) -> Result<Tag>

👎Deprecated: use read_from

Reads an AIFF stream and returns any present ID3 tag.

source

pub fn read_from_aiff_path(path: impl AsRef<Path>) -> Result<Tag>

👎Deprecated: use read_from_path

Reads an AIFF file at the specified path and returns any present ID3 tag.

source

pub fn read_from_aiff_file(file: impl StorageFile) -> Result<Tag>

👎Deprecated: use read_from_file

Reads an AIFF file and returns any present ID3 tag.

source

pub fn read_from_wav(reader: impl Read + Seek) -> Result<Tag>

👎Deprecated: use read_from

Reads an WAV stream and returns any present ID3 tag.

source

pub fn read_from_wav_path(path: impl AsRef<Path>) -> Result<Tag>

👎Deprecated: use read_from_path

Reads an WAV file at the specified path and returns any present ID3 tag.

source

pub fn read_from_wav_file(file: impl StorageFile) -> Result<Tag>

👎Deprecated: use read_from_file

Reads an WAV file and returns any present ID3 tag.

source

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.

source

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.

source

pub fn write_to_path( &self, path: impl AsRef<Path>, version: Version ) -> Result<()>

Conventience function for [write_to_file].

source

pub fn write_to_aiff_path( &self, path: impl AsRef<Path>, version: Version ) -> Result<()>

👎Deprecated: use write_to_path

Overwrite WAV file ID3 chunk in a file

source

pub fn write_to_aiff_file( &self, file: impl StorageFile, version: Version ) -> Result<()>

👎Deprecated: use write_to_file

Overwrite AIFF file ID3 chunk in a file. The file must be opened read/write.

source

pub fn write_to_wav_path( &self, path: impl AsRef<Path>, version: Version ) -> Result<()>

👎Deprecated: use write_to_path

Overwrite WAV file ID3 chunk

source

pub fn write_to_wav_file( &self, file: impl StorageFile, version: Version ) -> Result<()>

👎Deprecated: use write_to_file

Overwrite AIFF file ID3 chunk in a file. The file must be opened read/write.

source

pub fn version(&self) -> Version

Returns version of the read tag.

source

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);
source

pub fn extended_texts(&'a self) -> impl Iterator<Item = &'a ExtendedText> + 'a

Returns an iterator over the extended texts in the tag.

Returns an iterator over the extended links in the tag.

source

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.

source

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);
source

pub fn lyrics(&'a self) -> impl Iterator<Item = &'a Lyrics> + 'a

Returns an iterator over the lyrics frames in the tag.

source

pub fn synchronised_lyrics( &'a self ) -> impl Iterator<Item = &'a SynchronisedLyrics> + 'a

Returns an iterator over the synchronised lyrics frames in the tag.

source

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);
source

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());
source

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());

Trait Implementations§

source§

impl Clone for Tag

source§

fn clone(&self) -> Tag

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Tag

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Tag

source§

fn default() -> Tag

Returns the “default value” for a type. Read more
source§

impl Extend<Frame> for Tag

source§

fn extend<I: IntoIterator<Item = Frame>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl From<Tag> for Tag

source§

fn from(tag_v1: Tag) -> Tag

Converts to this type from the input type.
source§

impl FromIterator<Frame> for Tag

source§

fn from_iter<I: IntoIterator<Item = Frame>>(iter: I) -> Self

Creates a value from an iterator. Read more
source§

impl PartialEq for Tag

source§

fn eq(&self, other: &Tag) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl TagLike for Tag

source§

fn get(&self, id: impl AsRef<str>) -> Option<&Frame>

Returns a reference to the first frame with the specified identifier. Read more
source§

fn add_frame(&mut self, new_frame: impl Into<Frame>) -> Option<Frame>

Adds the frame to the tag, replacing and returning any conflicting frame. Read more
source§

fn set_text(&mut self, id: impl AsRef<str>, text: impl Into<String>)

Adds a text frame. Read more
source§

fn set_text_values( &mut self, id: impl AsRef<str>, texts: impl IntoIterator<Item = impl Into<String>> )

Panics Read more
source§

fn remove(&mut self, id: impl AsRef<str>) -> Vec<Frame>

Remove all frames with the specified identifier and return them. Read more
source§

fn year(&self) -> Option<i32>

Returns the year (TYER). Returns None if the year frame could not be found or if it could not be parsed. Read more
source§

fn set_year(&mut self, year: i32)

Sets the year (TYER). Read more
source§

fn remove_year(&mut self)

Removes the year (TYER). Read more
source§

fn date_recorded(&self) -> Option<Timestamp>

Return the content of the TRDC frame, if any Read more
source§

fn set_date_recorded(&mut self, timestamp: Timestamp)

Sets the content of the TDRC frame Read more
source§

fn remove_date_recorded(&mut self)

Remove the content of the TDRC frame Read more
source§

fn date_released(&self) -> Option<Timestamp>

Return the content of the TDRL frame, if any Read more
source§

fn set_date_released(&mut self, timestamp: Timestamp)

Sets the content of the TDRL frame Read more
source§

fn remove_date_released(&mut self)

Remove the content of the TDRL frame Read more
source§

fn original_date_released(&self) -> Option<Timestamp>

Return the content of the TDOR frame, if any Read more
source§

fn set_original_date_released(&mut self, timestamp: Timestamp)

Sets the content of the TDOR frame Read more
source§

fn remove_original_date_released(&mut self)

Remove the content of the TDOR frame Read more
source§

fn artist(&self) -> Option<&str>

Returns the artist (TPE1). Read more
source§

fn artists(&self) -> Option<Vec<&str>>

Returns the (potential) multiple artists (TPE1).
source§

fn set_artist(&mut self, artist: impl Into<String>)

Sets the artist (TPE1). Read more
source§

fn remove_artist(&mut self)

Removes the artist (TPE1). Read more
source§

fn album_artist(&self) -> Option<&str>

Sets the album artist (TPE2). Read more
source§

fn set_album_artist(&mut self, album_artist: impl Into<String>)

Sets the album artist (TPE2). Read more
source§

fn remove_album_artist(&mut self)

Removes the album artist (TPE2). Read more
source§

fn album(&self) -> Option<&str>

Returns the album (TALB). Read more
source§

fn set_album(&mut self, album: impl Into<String>)

Sets the album (TALB). Read more
source§

fn remove_album(&mut self)

Removes the album (TALB). Read more
source§

fn title(&self) -> Option<&str>

Returns the title (TIT2). Read more
source§

fn set_title(&mut self, title: impl Into<String>)

Sets the title (TIT2). Read more
source§

fn remove_title(&mut self)

Removes the title (TIT2). Read more
source§

fn duration(&self) -> Option<u32>

Returns the duration (TLEN). Read more
source§

fn set_duration(&mut self, duration: u32)

Sets the duration (TLEN). Read more
source§

fn remove_duration(&mut self)

Removes the duration (TLEN). Read more
source§

fn genre(&self) -> Option<&str>

Returns the plain genre (TCON) text. Read more
source§

fn genre_parsed(&self) -> Option<Cow<'_, str>>

Returns the genre (TCON) with ID3v1 genre indices resolved. Read more
source§

fn genres(&self) -> Option<Vec<&str>>

Returns the (potential) multiple plain genres (TCON).
source§

fn set_genre(&mut self, genre: impl Into<String>)

Sets the plain genre (TCON). Read more
source§

fn remove_genre(&mut self)

Removes the genre (TCON). Read more
source§

fn disc(&self) -> Option<u32>

Returns the disc number (TPOS). Read more
source§

fn set_disc(&mut self, disc: u32)

Sets the disc (TPOS). Read more
source§

fn remove_disc(&mut self)

Removes the disc number (TPOS). Read more
source§

fn total_discs(&self) -> Option<u32>

Returns the total number of discs (TPOS). Read more
source§

fn set_total_discs(&mut self, total_discs: u32)

Sets the total number of discs (TPOS). Read more
source§

fn remove_total_discs(&mut self)

Removes the total number of discs (TPOS). Read more
source§

fn track(&self) -> Option<u32>

Returns the track number (TRCK). Read more
source§

fn set_track(&mut self, track: u32)

Sets the track (TRCK). Read more
source§

fn remove_track(&mut self)

Removes the track number (TRCK). Read more
source§

fn total_tracks(&self) -> Option<u32>

Returns the total number of tracks (TRCK). Read more
source§

fn set_total_tracks(&mut self, total_tracks: u32)

Sets the total number of tracks (TRCK). Read more
source§

fn remove_total_tracks(&mut self)

Removes the total number of tracks (TCON). Read more
source§

fn add_extended_text( &mut self, description: impl Into<String>, value: impl Into<String> )

👎Deprecated: Use add_frame(frame::ExtendedText{ .. })
Adds a user defined text frame (TXXX). Read more
source§

fn remove_extended_text( &mut self, description: Option<&str>, value: Option<&str> )

Removes the user defined text frame (TXXX) with the specified key and value. Read more
source§

fn add_picture(&mut self, picture: Picture)

👎Deprecated: Use add_frame(frame::Picture{ .. })
Adds a picture frame (APIC). Any other pictures with the same type will be removed from the tag. Read more
source§

fn remove_picture_by_type(&mut self, picture_type: PictureType)

Removes all pictures of the specified type. Read more
source§

fn remove_all_pictures(&mut self)

Removes all pictures. Read more
source§

fn add_comment(&mut self, comment: Comment)

👎Deprecated: Use add_frame(frame::Comment{ .. })
Adds a comment (COMM). Read more
source§

fn remove_comment(&mut self, description: Option<&str>, text: Option<&str>)

Removes the comment (COMM) with the specified key and value. Read more
source§

fn add_encapsulated_object( &mut self, description: impl Into<String>, mime_type: impl Into<String>, filename: impl Into<String>, data: impl Into<Vec<u8>> )

👎Deprecated: Use add_frame(frame::EncapsulatedObject{ .. })
Adds an encapsulated object frame (GEOB). Read more
source§

fn remove_encapsulated_object( &mut self, description: Option<&str>, mime_type: Option<&str>, filename: Option<&str>, data: Option<&[u8]> )

Removes the encapsulated object frame (GEOB) with the specified key, MIME type, filename and data. Read more
source§

fn add_lyrics(&mut self, lyrics: Lyrics)

👎Deprecated: Use add_frame(frame::Lyrics{ .. })
Sets the lyrics (USLT). Read more
source§

fn remove_all_lyrics(&mut self)

Removes the lyrics text (USLT) from the tag. Read more
source§

fn add_synchronised_lyrics(&mut self, lyrics: SynchronisedLyrics)

👎Deprecated: Use add_frame(frame::SynchronisedLyrics{ .. })
Adds a synchronised lyrics frame (SYLT). Read more
source§

fn remove_all_synchronised_lyrics(&mut self)

Removes all synchronised lyrics (SYLT) frames from the tag. Read more
source§

fn remove_all_chapters(&mut self)

/// Removes all chapters (CHAP) frames from the tag. Read more
source§

fn remove_all_tables_of_contents(&mut self)

/// Removes all tables of contents (CTOC) frames from the tag. Read more
source§

impl Eq for Tag

Auto Trait Implementations§

§

impl RefUnwindSafe for Tag

§

impl Send for Tag

§

impl Sync for Tag

§

impl Unpin for Tag

§

impl UnwindSafe for Tag

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.