Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add chapter picture frame #83

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions v2/chapter_frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ type ChapterFrame struct {
EndOffset uint32
Title *TextFrame
Description *TextFrame
Link *LinkFrame
Artwork *PictureFrame
}

func (cf ChapterFrame) Size() int {
Expand Down Expand Up @@ -91,6 +93,8 @@ func parseChapterFrame(br *bufReader, version byte) (Framer, error) {

var title TextFrame
var description TextFrame
var link LinkFrame
var artwork PictureFrame

// borrowed from parse.go
buf := getByteSlice(32 * 1024)
Expand Down Expand Up @@ -121,6 +125,29 @@ func parseChapterFrame(br *bufReader, version byte) (Framer, error) {

putLimitedReader(bodyRd)
}
if id == "WXXX" {
bodyRd := getLimitedReader(br, bodySize)
br := newBufReader(bodyRd)
frame, err := parseLinkFrame(br)
if err != nil {
putLimitedReader(bodyRd)
return nil, err
}
link = frame.(LinkFrame)

putLimitedReader(bodyRd)
}
if id == "APIC" {
bodyRd := getLimitedReader(br, bodySize)
br := newBufReader(bodyRd)
frame, err := parsePictureFrame(br, version)
if err != nil {
putLimitedReader(bodyRd)
return nil, err
}
artwork = frame.(PictureFrame)
putLimitedReader(bodyRd)
}
}

cf := ChapterFrame{
Expand All @@ -133,6 +160,8 @@ func parseChapterFrame(br *bufReader, version byte) (Framer, error) {
EndOffset: endOffset,
Title: &title,
Description: &description,
Link: &link,
Artwork: &artwork,
}
return cf, nil
}
52 changes: 52 additions & 0 deletions v2/link_frame.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright 2016 Albert Nigmatzianov. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

package id3v2

import "io"

type LinkFrame struct {
Encoding Encoding
Url string
}

func (lf LinkFrame) Size() int {
return 1 + encodedSize(lf.Url, lf.Encoding) + len(lf.Encoding.TerminationBytes)
}

func (lf LinkFrame) UniqueIdentifier() string {
return "ID"
}

func (lf LinkFrame) WriteTo(w io.Writer) (int64, error) {
return useBufWriter(w, func(bw *bufWriter) {
bw.WriteByte(lf.Encoding.Key)
bw.EncodeAndWriteText(lf.Url, lf.Encoding)

// https://github.com/bogem/id3v2/pull/52
// https://github.com/bogem/id3v2/pull/33
bw.Write(lf.Encoding.TerminationBytes)
})
}

func parseLinkFrame(br *bufReader) (Framer, error) {
encoding := getEncoding(br.ReadByte())

if br.Err() != nil {
return nil, br.Err()
}

buf := getBytesBuffer()
defer putBytesBuffer(buf)
if _, err := buf.ReadFrom(br); err != nil {
return nil, err
}

lf := LinkFrame{
Encoding: encoding,
Url: decodeText(buf.Bytes(), encoding),
}

return lf, nil
}