#id3 #mp3 #wav #aiff #metadata

id3

A library for reading and writing ID3 metadata

34 releases (3 stable)

Uses new Rust 2021

1.0.3 May 10, 2022
1.0.2 Jan 29, 2022
0.6.6 Nov 10, 2021
0.6.4 Apr 24, 2021
0.1.6 Jun 6, 2015

#3 in Audio

Download history 722/week @ 2022-01-28 575/week @ 2022-02-04 506/week @ 2022-02-11 723/week @ 2022-02-18 677/week @ 2022-02-25 473/week @ 2022-03-04 572/week @ 2022-03-11 625/week @ 2022-03-18 437/week @ 2022-03-25 577/week @ 2022-04-01 610/week @ 2022-04-08 550/week @ 2022-04-15 454/week @ 2022-04-22 544/week @ 2022-04-29 865/week @ 2022-05-06 1034/week @ 2022-05-13

2,975 downloads per month
Used in 32 crates (25 directly)

MIT license

275KB
6K SLoC

rust-id3

Build Status Crate Documentation

A library for reading and writing ID3 metadata.

Implemented Features

  • ID3v1 reading
  • ID3v2.2, ID3v2.3, ID3v2.4 reading/writing
  • MP3, WAV and AIFF files
  • Latin1, UTF16 and UTF8 encodings
  • Text frames
  • Extended Text frames
  • Link frames
  • Extended Link frames
  • Comment frames
  • Lyrics frames
  • Synchronised Lyrics frames
  • Picture frames
  • Encapsulated Object frames
  • Chapter frames
  • Unsynchronisation
  • Compression
  • MPEG Location Lookup Table frames
  • Tag and File Alter Preservation bits

Examples

Reading tag frames

use id3::{Tag, TagLike};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let tag = Tag::read_from_path("testdata/id3v24.id3")?;

    // Get a bunch of frames...
    if let Some(artist) = tag.artist() {
        println!("artist: {}", artist);
    }
    if let Some(title) = tag.title() {
        println!("title: {}", title);
    }
    if let Some(album) = tag.album() {
        println!("album: {}", album);
    }

    // Get frames before getting their content for more complex tags.
    if let Some(artist) = tag.get("TPE1").and_then(|frame| frame.content().text()) {
        println!("artist: {}", artist);
    }
    Ok(())
}

Modifying any existing tag.

use id3::{Error, ErrorKind, Tag, TagLike, Version};
use std::fs::copy;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    copy("testdata/quiet.mp3", "/tmp/music.mp3")?;

    let mut tag = match Tag::read_from_path("/tmp/music.mp3") {
        Ok(tag) => tag,
        Err(Error{kind: ErrorKind::NoTag, ..}) => Tag::new(),
        Err(err) => return Err(Box::new(err)),
    };

    tag.set_album("Fancy Album Title");

    tag.write_to_path("/tmp/music.mp3", Version::Id3v24)?;
    Ok(())
}

Creating a new tag, overwriting any old tag.

use id3::{Tag, TagLike, Frame, Version};
use id3::frame::Content;
use std::fs::copy;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    copy("testdata/quiet.mp3", "/tmp/music.mp3")?;

    let mut tag = Tag::new();
    tag.set_album("Fancy Album Title");

    // Set the album the hard way.
    tag.add_frame(Frame::text("TALB", "album"));

    tag.write_to_path("/tmp/music.mp3", Version::Id3v24)?;
    Ok(())
}

Dependencies

~350–480KB