Commits

Robert Lowry committed 59a4af1

split IDv2.x functions back into seperate files

Comments (0)

Files changed (5)

 // Parse stream for ID3 information. Returns nil if parsing failed or the
 // input didn't contain ID3 information.
 // NOTE: ID3v1 and appended ID3v2.x are not supported without the ability
-// to seek in the input.
+// to seek in the input. Use ReadFile instead.
 func Read(reader io.Reader) (*File, error) {
 	buf := bufio.NewReader(reader)
 	if !hasID3v2Tag(buf) {
 	return tags, nil
 }
 
+// Parse seekable stream for ID3 information. Returns nil if ID3 tag is
+// not found or parsing fails.
 func ReadFile(reader io.ReadSeeker) (*File, error) {
 	buf := bufio.NewReader(reader)
 	if hasID3v1Tag(reader) {
 
 import (
 	"bufio"
-	"encoding/binary"
 	"fmt"
 	"io"
 )
 	Size              int32
 }
 
-var ID3v22Tags = map[string]string{
-	"TAL": "album",
-	"TRK": "track",
-	"TP1": "artist",
-	"TT2": "name",
-	"TYE": "year",
-	"TPA": "disc",
-	"TCO": "genre",
-}
-
-var ID3v23Tags = map[string]string{
-	"TALB": "album",
-	"TRCK": "track",
-	"TPE1": "artist",
-	"TIT2": "name",
-	"TYER": "year",
-	"TPOS": "disc",
-	"TCON": "genre",
-	"TLEN": "length",
-}
-
-var ID3v24Tags = map[string]string{
-	"TALB": "album",
-	"TRCK": "track",
-	"TPE1": "artist",
-	"TIT2": "name",
-	"TDRC": "year",
-	"TPOS": "disc",
-	"TCON": "genre",
-	"TLEN": "length",
-}
-
 func hasID3v2Tag(reader *bufio.Reader) bool {
 	data, err := reader.Peek(3)
 	if err != nil || len(data) < 3 {
 	return h, nil
 }
 
-// ID3 v2.2 uses 24-bit big endian frame sizes.
-func parseID3v22FrameSize(reader *bufio.Reader) (int, error) {
-	size, err := readBytes(reader, 3)
-	if err != nil {
-		return -1, err
-	}
-	return int(size[0])<<16 | int(size[1])<<8 | int(size[2]), nil
-}
-
-// ID3 v2.3 doesn't use sync-safe frame sizes: read in as a regular big endian number.
-func parseID3v23FrameSize(reader *bufio.Reader) (int, error) {
-	var size int32
-	binary.Read(reader, binary.BigEndian, &size)
-	return int(size), nil
-}
-
-// ID3 v2.4 uses sync-safe frame sizes similar to those found in the header.
-func parseID3v24FrameSize(reader *bufio.Reader) (int, error) {
-	size, err := readBytes(reader, 4)
-	if err != nil {
-		return -1, err
-	}
-	return int(parseSize(size)), nil
-}
-
 func parseID3v2File(reader *bufio.Reader) (*File, error) {
 	var parseSize func(*bufio.Reader) (int, error)
 	var tagMap map[string]string
+// Copyright 2011 Andrew Scherkus
+//
+// 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 (
+	"bufio"
+)
+
+var ID3v22Tags = map[string]string{
+	"TAL": "album",
+	"TRK": "track",
+	"TP1": "artist",
+	"TT2": "name",
+	"TYE": "year",
+	"TPA": "disc",
+	"TCO": "genre",
+}
+
+// ID3 v2.2 uses 24-bit big endian frame sizes.
+func parseID3v22FrameSize(reader *bufio.Reader) (int, error) {
+	size, err := readBytes(reader, 3)
+	if err != nil {
+		return -1, err
+	}
+	return int(size[0])<<16 | int(size[1])<<8 | int(size[2]), nil
+}
+
+// Copyright 2011 Andrew Scherkus
+//
+// 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 (
+	"bufio"
+	"encoding/binary"
+)
+
+var ID3v23Tags = map[string]string{
+	"TALB": "album",
+	"TRCK": "track",
+	"TPE1": "artist",
+	"TIT2": "name",
+	"TYER": "year",
+	"TPOS": "disc",
+	"TCON": "genre",
+	"TLEN": "length",
+}
+
+// ID3 v2.3 doesn't use sync-safe frame sizes: read in as a regular big endian number.
+func parseID3v23FrameSize(reader *bufio.Reader) (int, error) {
+	var size int32
+	binary.Read(reader, binary.BigEndian, &size)
+	return int(size), nil
+}
+
+// Copyright 2011 Andrew Scherkus
+//
+// 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 (
+	"bufio"
+)
+
+var ID3v24Tags = map[string]string{
+	"TALB": "album",
+	"TRCK": "track",
+	"TPE1": "artist",
+	"TIT2": "name",
+	"TDRC": "year",
+	"TPOS": "disc",
+	"TCON": "genre",
+	"TLEN": "length",
+}
+
+// ID3 v2.4 uses sync-safe frame sizes similar to those found in the header.
+func parseID3v24FrameSize(reader *bufio.Reader) (int, error) {
+	size, err := readBytes(reader, 4)
+	if err != nil {
+		return -1, err
+	}
+	return int(parseSize(size)), nil
+}