Crate lofty[][src]

Expand description

GitHub Workflow Status Downloads Version

Parse, convert, and write metadata to audio formats.

Supported Formats

File FormatExtensionsReadWriteMetadata Format(s)
APEapeXXAPEv2, APEv1, ID3v2 (Read only), ID3v1
AIFFaiff, aifXXID3v2, Text Chunks
FLACflacXXVorbis Comments
MP3mp3XXID3v2, ID3v1, APEv2, APEv1
MP4mp4, m4a, m4b, m4p, m4r, m4v, 3gpXXiTunes-style ilst
OpusopusXXVorbis Comments
Ogg VorbisoggXXVorbis Comments
WAVwav, waveXXID3v2, RIFF INFO

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};

// First, create a 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 tagged_file = read_from_path("tests/files/assets/a.mp3", false)?;

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

Using an existing reader

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

// Let's read from an open file
let mut file = File::open("tests/files/assets/a.mp3")?;

// 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("tests/files/assets/a.mp3", false)?;

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

// 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().unwrap();

Using concrete file types

use lofty::mp3::Mp3File;
use lofty::AudioFile;
use lofty::TagType;
use std::fs::File;

let mut file_content = File::open("tests/files/assets/a.mp3")?;

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

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

// Here we have a file with multiple tags
assert!(mpeg_file.contains_tag_type(&TagType::Id3v2));
assert!(mpeg_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.

Modules

APE specific items

ID3 specific items

WAV/AIFF specific items

MP3 specific items

MP4 specific items

OPUS/FLAC/Vorbis specific items

Structs

Various immutable audio properties

Represents a picture.

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

Errors that could occur within Lofty

Mime types for pictures.

The picture type

The tag’s format

Traits

Provides accessors for common items

Provides various methods for interaction with a file

Functions

Read a TaggedFile from a File

Read a TaggedFile from a path

Type Definitions

Alias for Result<T, LoftyError>