#id3 #mp3 #wav #aiff #metadata

id3

A library for reading and writing ID3 metadata

45 releases (14 stable)

1.6.0 Jan 1, 2023
1.5.1 Dec 8, 2022
1.5.0 Nov 16, 2022
1.2.1 Jun 28, 2022
0.1.6 Jun 6, 2015

#14 in Audio

Download history 388/week @ 2022-10-18 897/week @ 2022-10-25 870/week @ 2022-11-01 1144/week @ 2022-11-08 983/week @ 2022-11-15 720/week @ 2022-11-22 468/week @ 2022-11-29 1147/week @ 2022-12-06 748/week @ 2022-12-13 983/week @ 2022-12-20 670/week @ 2022-12-27 551/week @ 2023-01-03 789/week @ 2023-01-10 507/week @ 2023-01-17 935/week @ 2023-01-24 1148/week @ 2023-01-31

3,445 downloads per month
Used in 39 crates (30 directly)

MIT license

305KB
7K 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(())
}

Contributing

Do you think you have found a bug? Then please report it via the Github issue tracker. Make sure to attach any problematic files that can be used to reproduce the issue. Such files are also used to create regression tests that ensure that your bug will never return.

When submitting pull requests, please prefix your commit messages with fix: or feat: for bug fixes and new features respectively. This is the Conventional Commits scheme that is used to automate some maintenance chores such as generating the changelog and inferring the next version number.

Dependencies

~0.4–5MB
~77K SLoC