Latest 2.1.0
Homepage https://github.com/chicio/ID3TagEditor
License MIT
Platforms ios 11.0, osx 10.13, tvos 11.0, watchos 4.0
Authors

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](https://raw.githubusercontent.com/chicio/ID3TagEditor/master/Assets/icon-logo-background.png
"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', '~> 2.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

To read the ID3 tag of an mp3 file you can choose between two api contained in the ID3TagEditor class:

  • public func read(from path: String) throws -> ID3Tag?
  • public func read(mp3: Data) throws -> ID3Tag?

Below you can find a sample code of the api usage.

do {
    let id3TagEditor = ID3TagEditor()

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

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

To write a new ID3 tag into an mp3 file you can choose between two api contained in the ID3TagEditor class:

  • public func write(tag: ID3Tag, to path: String, andSaveTo newPath: String? = nil) throws
  • public func write(tag: ID3Tag, mp3: Data) throws -> Data

Below you can find a sample code of the api usage.

do {
    let id3Tag = ID3Tag(
        version: .version3,
        artist: "an example artist",
        albumArtist: "an example album artist",
        album: "an example album",
        title: "an example title",
        recordingDateTime: RecordingDateTime(date: RecordingDate(day: 1, month: 10, year: 2019), 
                                             time: RecordingTime(hour: 14, minute: 30)),
        genre: Genre(genre: .ClassicRock, description: "Rock & Roll"),
        attachedPictures: AttachedPicture(picture: <NSData/Data of the image>, type: .FrontCover, format: .Jpeg),
        trackPosition: TrackPositionInSet(position: 2, totalTracks: 9)
    )

    try id3TagEditor.write(tag: id3Tag, to: "<valid path to the mp3 file that will be overwritten>"))
    try id3TagEditor.write(tag: id3Tag, 
                           to: "<valid path to the mp3 file>",
                           andSaveTo: "<new path where you want to save the mp3>"))
    let newMp3: Data = try id3TagEditor.write(tag: id3Tag, mp3: <valid mp3 file passed as Data>)                          
} catch {
    print(error)
}    

The above methods use the ID3Tag class to describe a valid ID3 tag. This class contains various properties that could be
used to read/write a tag to the mp3 file.
Three 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
  • version 2.4, described by the enum value .version4

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
  • album, as a string containing the album title
  • title, as a string containing the title of the song
  • recordingDateTime, as an object composed by two other properties:
    • date as a RecordingDate object with three fields:
      • day, as a number that represents the recording day
      • month, as a number that represents the recording month
      • year, as a number that represents the recording year
    • time as a RecordingTime object with two fields:
      • hour, as a number that represents the recording hour
      • minute, as a number that represents the recording minute
  • trackPosition, as a TrackPositionInSet object containing the position of the track in the recording and the total number of track in the recordings
  • 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 recordingDateTime must always be a ISO88591 string).


Documentation

You can find the complete api documentation on fabrizioduroni.it.


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.

ID3TagEditorID3TagEditorID3TagEditorID3TagEditor

Latest podspec

{
    "name": "ID3TagEditor",
    "version": "2.1.0",
    "summary": "A swift library to read and modify ID3 Tag of any mp3 file",
    "description": "A swift library to read and modify ID3 Tag of any mp3 file.",
    "homepage": "https://github.com/chicio/ID3TagEditor",
    "screenshots": "https://raw.githubusercontent.com/chicio/ID3TagEditor/master/Screenshots/01-example.png",
    "license": {
        "type": "MIT",
        "file": "LICENSE.md"
    },
    "authors": {
        "chicio": "[email protected]"
    },
    "social_media_url": "https://github.com/chicio",
    "source": {
        "git": "https://github.com/chicio/ID3TagEditor.git",
        "tag": "2.1.0"
    },
    "platforms": {
        "ios": "11.0",
        "osx": "10.13",
        "tvos": "11.0",
        "watchos": "4.0"
    },
    "source_files": [
        "Source",
        "Source/**/*.{h,m}",
        "Source/**/*.swift"
    ]
}

Pin It on Pinterest

Share This