Crate lofty

source · []
Expand description

GitHub Workflow Status Downloads Version

Parse, convert, and write metadata to audio formats.

Supported Formats

File FormatMetadata Format(s)
ApeAPEv2, APEv1, ID3v2*, ID3v1
AIFFID3v2, Text Chunks
FLACVorbis Comments, ID3v2*
MP3ID3v2, ID3v1, APEv2, APEv1
MP4iTunes-style ilst
OpusVorbis Comments
Ogg VorbisVorbis Comments
SpeexVorbis Comments
WAVID3v2, RIFF INFO

* The tag will be read only, due to lack of official support

Examples

Reading a generic file

It isn’t always convenient to use concrete file types, which is where TaggedFile comes in.

Using a path

use lofty::{read_from_path, Probe};

// This will guess the format from the extension
// ("mp3" in this case), but we can guess from the content if we want to.
let path = "test.mp3";
let tagged_file = read_from_path(path, false)?;

// Let's guess the format from the content just in case.
// This is not necessary in this case!
let tagged_file2 = Probe::open(path)?.guess_file_type()?.read(false)?;

Using an existing reader

use lofty::read_from;
use std::fs::File;

// Let's read from an open file
let mut file = File::open(path)?;

// Here, we have to guess the file type prior to reading
let tagged_file = read_from(&mut file, false)?;

Accessing tags

use lofty::read_from_path;

let tagged_file = read_from_path(path, false)?;

// Get the primary tag (ID3v2 in this case)
let id3v2 = tagged_file.primary_tag();

// If the primary tag doesn't exist, or the tag types
// don't matter, the first tag can be retrieved
let unknown_first_tag = tagged_file.first_tag();

Using concrete file types

use lofty::mp3::Mp3File;
use lofty::{AudioFile, TagType};
use std::fs::File;

let mut file_content = File::open(path)?;

// We are expecting an MP3 file
let mp3_file = Mp3File::read_from(&mut file_content, true)?;

assert_eq!(mp3_file.properties().channels(), 2);

// Here we have a file with multiple tags
assert!(mp3_file.contains_tag_type(TagType::Id3v2));
assert!(mp3_file.contains_tag_type(TagType::Ape));

Features

Individual metadata formats

These features are available if you have a specific use case, or just don’t want certain formats.

  • aiff_text_chunks
  • ape
  • id3v1
  • id3v2
  • mp4_ilst
  • riff_info_list
  • vorbis_comments

Utilities

  • id3v2_restrictions - Parses ID3v2 extended headers and exposes flags for fine grained control

Important format-specific notes

All formats have their own quirks that may produce unexpected results between conversions. Be sure to read the module documentation of each format to see important notes and warnings.

Re-exports

pub use crate::error::LoftyError;
pub use crate::error::Result;

Modules

APE specific items

Contains the errors that can arise within Lofty

Items for FLAC

ID3 specific items

WAV/AIFF specific items

MP3 specific items

MP4 specific items

Items for OGG container formats

Structs

Various immutable audio properties

Represents a picture.

PictureInformationvorbis_comments

Information about a Picture

A format agnostic reader

Represents a parsed tag

Represents a tag item (key/value)

A generic representation of a file

Enums

The type of file read

A generic representation of a tag’s key

Represents a tag item’s value

Mime types for pictures.

The picture type, according to ID3v2 APIC

The tag’s format

Traits

Provides accessors for common items

Provides various methods for interaction with a file

A set of common methods between tags

Functions

Read a TaggedFile from a File

Read a TaggedFile from a path