Add id3 tags to mp3 files #1

Open
opened 2023-07-25 07:59:00 +01:00 by kemitix · 0 comments
Owner

Use the metadata from the YouTube page to populate the tags.

In Rust, you can use the id3 crate to update an MP3 file with ID3 metadata. The id3 crate provides methods to read, write, and manipulate ID3 metadata in MP3 files.

If you want to modify an existing tag, you can use the Tag::read_from_path method to read the existing tag from the file. If there is no existing tag, you can create a new one using the Tag::new method. To update the metadata, you can use the set_album method and then write the updated tag back to the file using the write_to_path method. Here is an example:

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(())
}

docs.rs/id3

Use the metadata from the YouTube page to populate the tags. In Rust, you can use the `id3` crate to update an MP3 file with ID3 metadata. The `id3` crate provides methods to read, write, and manipulate ID3 metadata in MP3 files. If you want to modify an existing tag, you can use the `Tag::read_from_path` method to read the existing tag from the file. If there is no existing tag, you can create a new one using the `Tag::new` method. To update the metadata, you can use the `set_album` method and then write the updated tag back to the file using the `write_to_path` method. Here is an example: ```rust 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(()) } ``` [docs.rs/id3](https://docs.rs/id3/latest/id3/)
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: kemitix/podal#1
No description provided.