/ID3TagEditor

:musical_note::guitar:A swift library to read and modify ID3 Tag of any mp3 file. Supported ID3 tag version: 2.2. and 2.3. Supported platform: iOS, macOS, tvOS, watchOS. :musical_note::guitar:

Primary LanguageSwiftMIT LicenseMIT

ID3TagEditor

Build Status codebeat badge codecov GitHub license Supported platform CocoaPods Version

ID3TagEditor: A swift library to read and modify ID3 Tag of any mp3 file

A swift library to read and modify ID3 Tag of any mp3 file.


Installation

There are three ways to install ID3TagEditor in your project: manual installation, as a stand-alone framework or using cocoapods.

Manual installation

To manually install ID3TagEditor simply drag and drop all the file contained in the Source folder inside your project (except for the info.plist file).

Framework

ID3TagEditor is also available as a framework. You can follow the standard procedure to install a custom cocoa touch framework (simply drag the ID3TagEditor.xcodeproj inside your project and add it to the Embedded Binaries/Linked Frameworks and Libraries section of your project. See the demo project for a complete example of the setup of the framework.

CocoaPods

ID3TagEditor is also available as a pod on CocoaPods. Add the dependency to your Podfile (choose the release version you prefer):

target 'MyApp' do
    pod 'ID3TagEditor', '~> 1.0'
end

and then run pod install (or pod update).


Usage

ID3Tag editor is compatible with the following platforms:

  • iOS
  • MacOS
  • Apple Watch
  • Apple TV

ID3TagEditor is really easy to use. To read the ID3 tag of an mp3 file use the read method of an instance of the ID3TagEditor class.

do {
    let id3TagEditor = ID3TagEditor()

    if let id3Tag = try id3TagEditor.read(from: "<valid path to the mp3 file>") {
        ...use the tag...
    }
} catch {
    print(error)
}  

To write a new ID3 tag into an mp3 file use the write method of an instance of the ID3TagEditor class.

do {
    let id3Tag = ID3Tag(
        version: .version3,
        artist: "an example artist",
        albumArtist: "an example album artist",
        album: "an example album",
        title: "an example title",
        year: "2019",
        genre: Genre(genre: .ClassicRock, description: "Rock & Roll"),
        attachedPictures: AttachedPicture(art: <NSData/Data of the image>, type: .FrontCover, format: .Jpeg),
        trackPosition: TrackPositionInSet(position: 2, totalTracks: 9)
    )
    try id3TagEditor.write(tag: id3Tag, to: PathLoader().pathFor(name: "example", fileType: "mp3"))
} catch {
    print(error)
}    

The above methods use the ID3Tag class to describe a valid ID3 tag. The class contains various properties that could be used to read/write a tag to the mp3 file. Two versions of the tag are supported. They are described in the ID3Version enum:

  • version 2.2, described by the enum value .version2
  • version 2.3, described by the enum value .version3

The ID3 supported properties are:

  • version, as previously described
  • artist, as a string containing the name of the song's artists
  • albumArtist, as a string containing additional info about the artists
  • title, as a string containing the title of the song
  • trackPosition, as a TrackPositionInSet object containing the position of the track in the recording and the total number of track in the recordings
  • album, as a string containing the album title
  • year, as a string containing the year of the recording
  • genre, as a Genre object containing the ID3Genre identifier and/or a description of the song's genre
  • attachedPictures, as an array of AttachedPicture objects containing the Data of an image, the ID3PictureType and the ID3PictureFormat

Only the version field is mandatory. The other fields are optional. The field artist, albumArtist, title and album are encoded/saved using Unicode 16 bit string (as requested by specification). The library is also able to read text frame wrongly encoded with Unicode (for example year must always be a ISO88591 string).


Examples

In the following screenshots you can find examples of the data extracted/updated. In the demo project you will find an example for each supported target.