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

Skip ID3v2 data prepended to flac files on parsing #21

Merged
merged 12 commits into from
May 25, 2018

Conversation

karlek
Copy link
Contributor

@karlek karlek commented May 24, 2018

This shoud close #20.

Note: A new import was introduced. [0]

[0]: https://github.com/mikkyang/id3-go/encodedbytes

karlek added 4 commits May 24, 2018 21:01
In order to disambiguate the introduction of the ID3v2 signature.
Note: a new import for decoding synchronized integers from ID3v2 headers
was introduced.
@karlek karlek requested a review from mewmew May 24, 2018 12:09
@karlek
Copy link
Contributor Author

karlek commented May 24, 2018

Should we add a new test case?

Edit: Looks like the travis conf is broken. I'll leave that one to you :)

Copy link
Member

@mewmew mewmew left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with some minor suggestions.

Edit:

Should we add a new test case?

I think it would be good to add a test case.

flac.go Outdated
@@ -80,7 +82,10 @@ func New(r io.Reader) (stream *Stream, err error) {
}

// signature marks the beginning of a FLAC stream.
var signature = []byte("fLaC")
var flacSignature = []byte("fLaC")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-// signature marks the beginning of a FLAC stream.
+// flacSignature marks the beginning of a FLAC stream.

flac.go Outdated
var flacSignature = []byte("fLaC")

// signature marks the beginning of a FLAC stream.
var id3Signature = []byte("ID3")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-// signature marks the beginning of a FLAC stream. 
+// id3Signature marks the beginning of a FLAC stream.

@@ -30,6 +30,8 @@ import (

"github.com/mewkiz/flac/frame"
"github.com/mewkiz/flac/meta"

"github.com/mikkyang/id3-go/encodedbytes"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we start using vgo to track versions of external dependencies? We can do this in a follow-up PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, I'll create the issue.

flac.go Outdated
@@ -111,6 +130,33 @@ func (stream *Stream) parseStreamInfo() (isLast bool, err error) {
return block.IsLast, nil
}

// skipId3v2 skips ID3v2 data prepended to flac files.
func (stream *Stream) skipId3v2() (err error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capitalize ID, I think golint may be upset otherwise: https://github.com/golang/lint/blob/a5f4a247366d8fc436941822e14fc3eac7727015/lint_test.go#L224

Mostly nit picks, but use named return values only when they add to documentation: https://github.com/golang/go/wiki/CodeReviewComments#named-result-parameters

flac.go Outdated

// Discard unnecessary data from the ID3v2 header.
_, err = r.Discard(2)
if err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personal preference, keep scope of variable to a minimum if possible. This makes it clear we don't use the value later.

if _, err := r.Discard(2) {
	return err
}

flac.go Outdated

// Read the size from the ID3v2 header.
var sizeBuf [4]byte
_, err = r.Read(sizeBuf[:])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, limit scope of err.

@@ -24,7 +24,7 @@ func Encode(w io.Writer, stream *Stream) error {
enc := &encoder{bw: bitio.NewWriter(buf)}

// Store FLAC signature.
if _, err := enc.bw.Write(signature); err != nil {
if _, err := enc.bw.Write(flacSignature); err != nil {
Copy link
Member

@mewmew mewmew May 24, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was reading enc and thought, hmm. Shouldn't it be dec? Haha, I forgot for a moment we have FLAC encoding.

Well, we don't re-encode the samples yes, that is perhaps part of project metalstorm :)

Copy link
Contributor Author

@karlek karlek May 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha, yeah I got the same reaction when I got the error. Like, "Wuah..? Ah yeah, now I remember."

However, the code we've written is very nice. I don't have that embarrased feeling I usually have when reading old code! 🐫

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However, the code we've written is very nice. I don't have that embarrased feeling I usually have when reading old code! 🐫

That's great to hear! I feel the same. Small things we can clean up here and there, e.g. #22, but mostly it is straightforward and consistent code.

flac.go Outdated
}

// Second attempt at verifying signature.
_, err = io.ReadFull(r, buf[:])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Limit scope of err, see comment below for similar example.

@mewmew mewmew mentioned this pull request May 24, 2018
@mewmew mewmew merged commit 36cc17e into mewkiz:master May 25, 2018
@mewmew
Copy link
Member

mewmew commented May 25, 2018

hallon bror!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request] Add the ability to skip ID3 tags/ID3 data
3 participants