From 2c03760157d3e2f3a61fd78921065113aef7f08e Mon Sep 17 00:00:00 2001 From: Daniel Erat Date: Sun, 19 Jan 2014 18:53:44 -0800 Subject: [PATCH] third_party/taglib: Update to ef5ded85df. Change-Id: I536e08d2c0184b1d2abe52f3f139be35e9f331dd --- third_party/taglib/id3/id3v23.go | 45 ++++++++++++++++++++++++-- third_party/taglib/id3/id3v23frames.go | 14 ++++++++ third_party/taglib/id3/id3v24.go | 40 +++++++++++++++++++++++ third_party/taglib/id3/id3v24_test.go | 14 ++++++++ third_party/taglib/id3/id3v24frames.go | 14 ++++++++ third_party/taglib/id3/util.go | 14 ++++++++ third_party/taglib/taglib.go | 24 ++++++++++++++ third_party/taglib/taglib_test.go | 25 ++++++++++++-- 8 files changed, 185 insertions(+), 5 deletions(-) diff --git a/third_party/taglib/id3/id3v23.go b/third_party/taglib/id3/id3v23.go index 5a3697b49..39cbf7a5f 100644 --- a/third_party/taglib/id3/id3v23.go +++ b/third_party/taglib/id3/id3v23.go @@ -1,3 +1,17 @@ +// Copyright 2013 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package id3 import ( @@ -55,12 +69,12 @@ func (t *Id3v23Tag) Genre() string { } func (t *Id3v23Tag) Year() time.Time { - yearStr := getSimpleId3v23TextFrame(t.Frames["TDRC"]) - if len(yearStr) < 4 { + yearStr := getSimpleId3v23TextFrame(t.Frames["TYER"]) + if len(yearStr) != 4 { return time.Time{} } - yearInt, err := strconv.Atoi(yearStr[0:4]) + yearInt, err := strconv.Atoi(yearStr) if err != nil { return time.Time{} } @@ -76,6 +90,31 @@ func (t *Id3v23Tag) Track() uint32 { return uint32(track) } +func (t *Id3v23Tag) Disc() uint32 { + disc, err := parseLeadingInt(getSimpleId3v23TextFrame(t.Frames["TPOS"])) + if err != nil { + return 0 + } + return uint32(disc) +} + +func (t *Id3v23Tag) CustomFrames() map[string]string { + info := make(map[string]string) + for _, frame := range t.Frames["TXXX"] { + // See http://id3.org/id3v2.3.0#User_defined_text_information_frame. + // TXXX frames contain NUL-separated descriptions and values. + parts, err := GetId3v23TextIdentificationFrame(frame) + if err == nil && len(parts) == 2 { + info[parts[0]] = parts[1] + } + } + return info +} + +func (t *Id3v23Tag) TagSize() uint32 { + return 10 + t.Header.Size +} + type Id3v23Header struct { MinorVersion byte Flags Id3v23HeaderFlags diff --git a/third_party/taglib/id3/id3v23frames.go b/third_party/taglib/id3/id3v23frames.go index 2dcc89fbe..5e6f8b1e5 100644 --- a/third_party/taglib/id3/id3v23frames.go +++ b/third_party/taglib/id3/id3v23frames.go @@ -1,3 +1,17 @@ +// Copyright 2013 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package id3 func GetId3v23TextIdentificationFrame(frame *Id3v23Frame) ([]string, error) { diff --git a/third_party/taglib/id3/id3v24.go b/third_party/taglib/id3/id3v24.go index b8cd2b4db..2bd0334d5 100644 --- a/third_party/taglib/id3/id3v24.go +++ b/third_party/taglib/id3/id3v24.go @@ -1,3 +1,17 @@ +// Copyright 2013 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package id3 import ( @@ -76,6 +90,32 @@ func (t *Id3v24Tag) Track() uint32 { return uint32(track) } +func (t *Id3v24Tag) Disc() uint32 { + disc, err := parseLeadingInt(getSimpleId3v24TextFrame(t.Frames["TPOS"])) + if err != nil { + return 0 + } + return uint32(disc) +} + +func (t *Id3v24Tag) CustomFrames() map[string]string { + info := make(map[string]string) + for _, frame := range t.Frames["TXXX"] { + // See "4.2.6. User defined text information frame" at + // http://id3.org/id3v2.4.0-frames. TXXX frames contain + // NUL-separated descriptions and values. + parts, err := GetId3v24TextIdentificationFrame(frame) + if err == nil && len(parts) == 2 { + info[parts[0]] = parts[1] + } + } + return info +} + +func (t *Id3v24Tag) TagSize() uint32 { + return 10 + t.Header.Size +} + type Id3v24Header struct { MinorVersion byte Flags Id3v24HeaderFlags diff --git a/third_party/taglib/id3/id3v24_test.go b/third_party/taglib/id3/id3v24_test.go index 236a2e53b..432d26a0b 100644 --- a/third_party/taglib/id3/id3v24_test.go +++ b/third_party/taglib/id3/id3v24_test.go @@ -1,3 +1,17 @@ +// Copyright 2013 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package id3 // import ( diff --git a/third_party/taglib/id3/id3v24frames.go b/third_party/taglib/id3/id3v24frames.go index 75c6cfc6d..1bb20e82d 100644 --- a/third_party/taglib/id3/id3v24frames.go +++ b/third_party/taglib/id3/id3v24frames.go @@ -1,3 +1,17 @@ +// Copyright 2013 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package id3 func GetId3v24TextIdentificationFrame(frame *Id3v24Frame) ([]string, error) { diff --git a/third_party/taglib/id3/util.go b/third_party/taglib/id3/util.go index a46cff767..a8a6a6480 100644 --- a/third_party/taglib/id3/util.go +++ b/third_party/taglib/id3/util.go @@ -1,3 +1,17 @@ +// Copyright 2013 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package id3 import ( diff --git a/third_party/taglib/taglib.go b/third_party/taglib/taglib.go index c3d68ca29..d0d61cfcb 100644 --- a/third_party/taglib/taglib.go +++ b/third_party/taglib/taglib.go @@ -1,3 +1,17 @@ +// Copyright 2013 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + // Package taglib provides utilities for parsing audio tags in // various formats. package taglib @@ -26,6 +40,16 @@ type GenericTag interface { Genre() string Year() time.Time Track() uint32 + Disc() uint32 + + // CustomFrames returns non-standard, user-defined frames as a map from + // descriptions (e.g. "PERFORMER", "MusicBrainz Album Id", etc.) to + // values. + CustomFrames() map[string]string + + // TagSize returns the total size of the tag's header and frames, + // i.e. the position at which audio data starts. + TagSize() uint32 } // Decode reads r and determines which tag format the data is in, if diff --git a/third_party/taglib/taglib_test.go b/third_party/taglib/taglib_test.go index 5e4749c9b..4bd4fb79b 100644 --- a/third_party/taglib/taglib_test.go +++ b/third_party/taglib/taglib_test.go @@ -1,3 +1,17 @@ +// Copyright 2013 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package taglib import ( @@ -11,8 +25,11 @@ func ExampleDecode() { if err != nil { panic(err) } - - tag, err := Decode(f) + fi, err := f.Stat() + if err != nil { + panic(err) + } + tag, err := Decode(f, fi.Size()) if err != nil { panic(err) } @@ -22,7 +39,9 @@ func ExampleDecode() { fmt.Println("Album:", tag.Album()) fmt.Println("Genre:", tag.Genre()) fmt.Println("Year:", tag.Year()) + fmt.Println("Disc:", tag.Disc()) fmt.Println("Track:", tag.Track()) + fmt.Println("Performer:", tag.CustomFrames()["PERFORMER"]) // Output: // Title: Test Name @@ -30,5 +49,7 @@ func ExampleDecode() { // Album: Test Album // Genre: Classical // Year: 2008-01-01 00:00:00 +0000 UTC + // Disc: 3 // Track: 7 + // Performer: Somebody }