Giter Club home page Giter Club logo

outcastid3's Introduction

OutcastID3

A lightweight Swift library for reading and writing ID3 tags, including chapters.

Swift Package Manager

To install via SPM, add the URL https://github.com/CrunchyBagel/OutcastID3 to your project.

CocoaPods

https://cocoapods.org/pods/OutcastID3

Version License Platform

To install via CocoaPods, add the following line to your Podfile:

pod 'OutcastID3'

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Read an ID3 tag:

let url = Bundle.main.url(forResource: "MyFile", withExtension: "mp3")!

let mp3 = try MP3File(localUrl: url)
let tag = try x.readID3Tag()

let version = tag.tag.version

for frame in tag.tag.frames {
    switch frame {
    case let s as OutcastID3.Frame.StringFrame:
        print("\(s.type.description): \(s.str)")
        
    case let u as OutcastID3.Frame.UrlFrame:
        print("\(u.type.description): \(u.urlString)")

    case let comment as OutcastID3.Frame.CommentFrame:
        print("COMMENT: \(comment)")
        
    case let transcription as OutcastID3.Frame.TranscriptionFrame:
        print("TRANSCRIPTION: \(transcription)")
        
    case let picture as OutcastID3.Frame.PictureFrame:
        print("PICTURE: \(picture)")

    case let f as OutcastID3.Frame.ChapterFrame:
        print("CHAPTER: \(f)")
        
    case let toc as OutcastID3.Frame.TableOfContentsFrame:
        print("TOC: \(toc)")
        
    case let rawFrame as OutcastID3.Frame.RawFrame:
        print("Unrecognised frame: \(String(describing: rawFrame.frameIdentifier))")

    default:
        break
    }
}

Write an ID3 tag:

let frames: [OutcastID3TagFrame] = [
    OutcastID3.Frame.StringFrame(type: .title, encoding: .utf8, str: "Tag Writer Test")
]

let tag = OutcastID3.ID3Tag(
    version: .v2_4,
    frames: frames
)

let inputUrl = Bundle.main.url(forResource: "input", withExtension: "mp3")!

let outputUrl = Bundle.main.url(forResource: "output", withExtension: "mp3")!

let mp3File = try OutcastID3.MP3File(localUrl: inputUrl)

try mp3File.writeID3Tag(tag: tag, outputUrl: outputUrl)

Author

Crunchy Bagel, [email protected]

License

OutcastID3 is available under the MIT license. See the LICENSE file for more info.

outcastid3's People

Contributors

hendx avatar marcelmendesfilho avatar michaeljberk avatar ncrusher74 avatar normand1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

outcastid3's Issues

Transcription and Comment frame encoding

I'm having an interesting issue with the Transcription and Comment frames. When I write them using this code:

            OutcastID3.Frame.CommentFrame(
                encoding: .utf8, language: "eng",
                commentDescription: "description",
                comment: "Comment Test"),
            OutcastID3.Frame.TranscriptionFrame(
                encoding: .utf8, language: "eng",
                lyricsDescription: "description",
                lyrics: "Lyrics Test")

And run this test:

            // ... test on StringFrame types
            } else if let isolatedFrame = frame as? OutcastID3.Frame.CommentFrame {
                XCTAssertEqual(isolatedFrame.language, "eng")
                XCTAssertEqual(isolatedFrame.commentDescription, "description")
                XCTAssertEqual(isolatedFrame.comment, "Comment Test")
            } else if let isolatedFrame = frame as? OutcastID3.Frame.TranscriptionFrame {
                XCTAssertEqual(isolatedFrame.language, "eng")
                XCTAssertEqual(isolatedFrame.lyricsDescription, "description")
                XCTAssertEqual(isolatedFrame.lyrics, "Lyrics Test")
            }

This is the result I see:

Screen Shot 2020-03-08 at 3 36 22 PM

And the reason I'm including that as a screenshot is because when I try to cut/paste the test of the error, my posts on GitHub get cut off, because this is the actual text:

Screen Shot 2020-03-08 at 3 44 13 PM

and GitHub apparently doesn't like that extra character at the beginning.

I've tried every kind of encoding I can think of and none of them improve the result. And that doesn't explain why the content of the TranscriptionFrame is being written to the CommentFrame.

It also looks like OutcastID3 may be having an issue with adding characters to tags written by other writers. This is what happens when I try to read a file written using ID3TagEditor with OutcastID3:

        for frame in outcastFrames {
            if let isolatedFrame = frame as? OutcastID3.Frame.StringFrame {
                if isolatedFrame.type == AudiobookTag.authors.outcastType {
                    XCTAssertEqual(isolatedFrame.str, "Artist")
                    print((isolatedFrame.str).unicodeScalars.map({ $0.value }))
                    print("Artist".unicodeScalars.map({ $0.value }))
                    }
                }
            }
        let id3TagEditor = ID3TagEditor()
        if let id3Tag = try id3TagEditor.read(from: Bundle.testMp3FullMeta.path) {
            print((id3Tag.frames[.Artist] as? ID3FrameWithStringContent)?.content.unicodeScalars.map({ $0.value }))

        }

^^^ this test gets me this result:

/OutcastID3Tests.swift:26: error: -[AudiobookTaggerTests.OutcastID3Tests testMP3AudiobookTag] : 
XCTAssertEqual failed: ("Artist[X*]") is not equal to ("Artist")
[65, 114, 116, 105, 115, 116, 0]
[65, 114, 116, 105, 115, 116]
Optional([65, 114, 116, 105, 115, 116])

note*: X marks the extra character I removed so that the post wouldn't get cut off.

Wrong length zero bytes for UTF-8 encoding strings

Data+String.swift
in case when comment have encoding .utf8 and we looking for zero bytes end of string we must wait ONE zero byte not two

two zero bytes only for UTF16

// unicode strings are terminated by \0\0, while latin terminated by \0
your comment is wrong only utf16 strinds are termonated by \0\0

http://id3.org/id3v2.4.0-structure
Frames that allow different types of text encoding contains a text
encoding description byte. Possible encodings:

 $00   ISO-8859-1 [ISO-8859-1]. Terminated with $00.
 $01   UTF-16 [UTF-16] encoded Unicode [UNICODE] with BOM. All
       strings in the same frame SHALL have the same byteorder.
       Terminated with $00 00.
 $02   UTF-16BE [UTF-16] encoded Unicode [UNICODE] without BOM.
       Terminated with $00 00.
 $03   UTF-8 [UTF-8] encoded Unicode [UNICODE]. Terminated with $00.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.