pub struct TaggedFile { /* private fields */ }
Expand description

A generic representation of a file

This is used when the FileType has to be guessed

Implementations

Returns the file’s FileType

Examples
use lofty::FileType;

let mut tagged_file = lofty::read_from_path(path_to_mp3)?;

assert_eq!(tagged_file.file_type(), FileType::MPEG);

Returns all tags

Examples
use lofty::FileType;

// An MP3 file with 3 tags
let mut tagged_file = lofty::read_from_path(path_to_mp3)?;

let tags = tagged_file.tags();

assert_eq!(tags.len(), 3);

Returns the file type’s primary TagType

See FileType::primary_tag_type

Examples
use lofty::TagType;

let mut tagged_file = lofty::read_from_path(path_to_mp3)?;

assert_eq!(tagged_file.primary_tag_type(), TagType::ID3v2);

Determines whether the file supports the given TagType

Examples
use lofty::TagType;

let mut tagged_file = lofty::read_from_path(path_to_mp3)?;

assert!(tagged_file.supports_tag_type(TagType::ID3v2));

Get a reference to a specific TagType

Examples
use lofty::TagType;

// Read an MP3 file with an ID3v2 tag
let mut tagged_file = lofty::read_from_path(path_to_mp3)?;

// An ID3v2 tag
let tag = tagged_file.tag(TagType::ID3v2);

assert!(tag.is_some());
assert_eq!(tag.unwrap().tag_type(), TagType::ID3v2);

Get a mutable reference to a specific TagType

Examples
use lofty::TagType;

// Read an MP3 file with an ID3v2 tag
let mut tagged_file = lofty::read_from_path(path_to_mp3)?;

// An ID3v2 tag
let tag = tagged_file.tag(TagType::ID3v2);

assert!(tag.is_some());
assert_eq!(tag.unwrap().tag_type(), TagType::ID3v2);

// Alter the tag...

Returns the primary tag

See FileType::primary_tag_type

Examples
use lofty::TagType;

// Read an MP3 file with an ID3v2 tag
let mut tagged_file = lofty::read_from_path(path_to_mp3)?;

// An ID3v2 tag
let tag = tagged_file.primary_tag();

assert!(tag.is_some());
assert_eq!(tag.unwrap().tag_type(), TagType::ID3v2);

Gets a mutable reference to the file’s “Primary tag”

See FileType::primary_tag_type

Examples
use lofty::TagType;

// Read an MP3 file with an ID3v2 tag
let mut tagged_file = lofty::read_from_path(path_to_mp3)?;

// An ID3v2 tag
let tag = tagged_file.primary_tag_mut();

assert!(tag.is_some());
assert_eq!(tag.unwrap().tag_type(), TagType::ID3v2);

// Alter the tag...

Gets the first tag, if there are any

NOTE: This will grab the first available tag, you cannot rely on the result being a specific type

Examples
// A file we know has tags
let mut tagged_file = lofty::read_from_path(path)?;

// A tag of a (currently) unknown type
let tag = tagged_file.first_tag();
assert!(tag.is_some());

Gets a mutable reference to the first tag, if there are any

NOTE: This will grab the first available tag, you cannot rely on the result being a specific type

Examples
// A file we know has tags
let mut tagged_file = lofty::read_from_path(path)?;

// A tag of a (currently) unknown type
let tag = tagged_file.first_tag_mut();
assert!(tag.is_some());

// Alter the tag...

Inserts a Tag

NOTE: This will do nothing if the FileType does not support the TagType. See FileType::supports_tag_type

If a tag is replaced, it will be returned

Examples
use lofty::{AudioFile, Tag, TagType};

// Read an MP3 file without an ID3v2 tag
let mut tagged_file = lofty::read_from_path(path_to_mp3)?;

assert!(!tagged_file.contains_tag_type(TagType::ID3v2));

// Insert the ID3v2 tag
let new_id3v2_tag = Tag::new(TagType::ID3v2);
tagged_file.insert_tag(new_id3v2_tag);

assert!(tagged_file.contains_tag_type(TagType::ID3v2));

Removes a specific TagType and returns it

Examples
use lofty::{AudioFile, TagType};

// Read an MP3 file containing an ID3v2 tag
let mut tagged_file = lofty::read_from_path(path_to_mp3)?;

assert!(tagged_file.contains_tag_type(TagType::ID3v2));

// Take the ID3v2 tag
let id3v2 = tagged_file.take(TagType::ID3v2);

assert!(!tagged_file.contains_tag_type(TagType::ID3v2));

Changes the FileType

NOTES:

Examples
use lofty::{AudioFile, FileType, TagType};

// Read an MP3 file containing an ID3v2 tag
let mut tagged_file = lofty::read_from_path(path_to_mp3)?;

assert!(tagged_file.contains_tag_type(TagType::ID3v2));

// Remap our MP3 file to WavPack, which doesn't support ID3v2
tagged_file.change_file_type(FileType::WavPack);

assert!(!tagged_file.contains_tag_type(TagType::ID3v2));

Removes all tags from the file

Examples
let mut tagged_file = lofty::read_from_path(path)?;

tagged_file.clear();

assert!(tagged_file.tags().is_empty());

Attempts to write all tags to a path

Errors

See TaggedFile::save_to

Examples
let mut tagged_file = lofty::read_from_path(path)?;

// Edit the tags

tagged_file.save_to_path(path)?;

Attempts to write all tags to a file

Errors

See Tag::save_to, however this is applicable to every tag in the TaggedFile.

Examples
use std::fs::OpenOptions;

let mut tagged_file = lofty::read_from_path(path)?;

// Edit the tags

let mut file = OpenOptions::new().read(true).write(true).open(path)?;
tagged_file.save_to(&mut file)?;

Trait Implementations

The struct the file uses for audio properties Read more
Read a file from a reader Read more
Returns a reference to the file’s properties
Checks if the file contains any tags
Checks if the file contains the given TagType
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.