Browse Source

⬥ Function names renaming ⬥

main
Unbewohnte 3 years ago
parent
commit
4207d8f1aa
  1. 5
      README.md
  2. 8
      id3ed.go
  3. 30
      v1/id3v10_test.go
  4. 26
      v1/id3v11_test.go
  5. 12
      v1/v11read.go
  6. 4
      v1/v11tag.go
  7. 34
      v1/v11write.go
  8. 4
      v1/v1read.go
  9. 4
      v1/v1tag.go
  10. 34
      v1/v1write.go
  11. 0
      v2/v2tag.go

5
README.md

@ -9,7 +9,7 @@
Right now it`s capable of reading and writing ID3v1 and ID3v1.1 tags.
ID3v2.x support is still in making.
ID3v2.x support is still in making, but it can read header and v.3~v.4 frames
---
@ -19,8 +19,9 @@ To download package source:
```
go get github.com/Unbewohnte/id3ed/...
```
will be deprecated in 1.17 as far as I know
To compile package:
To donwload and compile package:
```
go install github.com/Unbewohnte/id3ed/...
```

8
id3ed.go

@ -1,17 +1,11 @@
package id3ed
// type File struct {
// Filename string
// ContainsV1 bool
// ContainsV2 bool
// }
// type Metadata interface {
// Write() error
// ?
// }
// func Open(path string) (*File, error) {
// return &File{}, nil
// }
// func (f *File) GetMetadata() (*Metadata, error)

30
v1/id3v10_test.go

@ -8,7 +8,7 @@ import (
var TESTDATAPATH string = filepath.Join("..", "testData")
var TESTv1TAGS = &ID3v1Tags{
var TESTv1TAG = &ID3v1Tag{
SongName: "testsong",
Artist: "testartist",
Album: "testalbum",
@ -22,13 +22,13 @@ func TestGetv1Tags(t *testing.T) {
if err != nil {
t.Errorf("could not open file for testing: %s", err)
}
tags, err := Getv1Tags(testfile)
tag, err := Getv1Tag(testfile)
if err != nil {
t.Errorf("GetID3v1Tags failed: %s", err)
t.Errorf("GetID3v1Tag failed: %s", err)
}
if tags.Comment != "Comment here " {
t.Errorf("GetID3v1Tags failed: expected %s; got %s", "Comment here ", tags.Comment)
if tag.Comment != "Comment here " {
t.Errorf("GetID3v1Tag failed: expected %s; got %s", "Comment here ", tag.Comment)
}
}
@ -39,26 +39,26 @@ func TestWritev1Tags(t *testing.T) {
}
defer f.Close()
tags := TESTv1TAGS
tag := TESTv1TAG
// writing tags
err = tags.Write(f)
// writing a tag
err = tag.Write(f)
if err != nil {
t.Errorf("WriteID3v1Tags failed: %s", err)
t.Errorf("WriteID3v1Tag failed: %s", err)
}
// reading tags
readTags, err := Getv1Tags(f)
// reading a tag
readTags, err := Getv1Tag(f)
if err != nil {
t.Errorf("%s", err)
}
if readTags.Album != "testalbum" {
t.Errorf("WriteID3v1Tags failed: expected %s; got %s", "testalbum", readTags.Album)
t.Errorf("WriteID3v1Tag failed: expected %s; got %s", "testalbum", readTags.Album)
}
if readTags.Year != 727 {
t.Errorf("WriteID3v1Tags failed: expected %d; got %d", 727, readTags.Year)
t.Errorf("WriteID3v1Tag failed: expected %d; got %d", 727, readTags.Year)
}
}
@ -68,9 +68,9 @@ func TestWriteID3v1ToFile(t *testing.T) {
t.Errorf("%s", err)
}
tags := TESTv1TAGS
tag := TESTv1TAG
err = tags.WriteToFile(f)
err = tag.WriteToFile(f)
if err != nil {
t.Errorf("WriteID3v1ToFile failed: %s", err)
}

26
v1/id3v11_test.go

@ -7,7 +7,7 @@ import (
"testing"
)
var TESTV11TAGS = &ID3v11Tags{
var TESTV11TAG = &ID3v11Tag{
SongName: "testsong",
Artist: "testartist",
Album: "testalbum",
@ -22,18 +22,18 @@ func TestGetID3v11Tags(t *testing.T) {
if err != nil {
t.Errorf("could not open file for testing: %s", err)
}
mp3tags, err := Getv11Tags(testfile)
mp3tags, err := Getv11Tag(testfile)
if err != nil {
t.Errorf("GetID3v11Tags failed: %s", err)
t.Errorf("GetID3v11Tag failed: %s", err)
}
if mp3tags.Artist != "Artist" {
fmt.Printf("%v", mp3tags.Artist)
t.Errorf("GetID3v11Tags failed: expected artist %s; got %s", "Artist", mp3tags.Artist)
t.Errorf("GetID3v11Tag failed: expected artist %s; got %s", "Artist", mp3tags.Artist)
}
if mp3tags.Track != 8 {
t.Errorf("GetID3v11Tags failed: expected track %d; got %d", 8, mp3tags.Track)
t.Errorf("GetID3v11Tag failed: expected track %d; got %d", 8, mp3tags.Track)
}
}
@ -45,28 +45,28 @@ func TestWriteID3v11Tags(t *testing.T) {
}
defer f.Close()
tags := TESTV11TAGS
tag := TESTV11TAG
err = tags.Write(f)
err = tag.Write(f)
if err != nil {
t.Errorf("WriteID3v1Tags failed: %s", err)
}
readTags, err := Getv11Tags(f)
readTags, err := Getv11Tag(f)
if err != nil {
t.Errorf("%s", err)
}
if readTags.Album != "testalbum" {
t.Errorf("WriteID3v11Tags failed: expected album %s; got %s", "testalbum", readTags.Album)
t.Errorf("WriteID3v11Tag failed: expected album %s; got %s", "testalbum", readTags.Album)
}
if readTags.Year != 727 {
t.Errorf("WriteID3v11Tags failed: expected year %d; got %d", 727, readTags.Year)
t.Errorf("WriteID3v11Tag failed: expected year %d; got %d", 727, readTags.Year)
}
if readTags.Track != 10 {
t.Errorf("WriteID3v11Tags failed: expected track %d; got %d", 10, readTags.Track)
t.Errorf("WriteID3v11Tag failed: expected track %d; got %d", 10, readTags.Track)
}
}
@ -76,9 +76,9 @@ func TestWriteID3v11ToFile(t *testing.T) {
t.Errorf("%s", err)
}
tags := TESTV11TAGS
tag := TESTV11TAG
err = tags.WriteToFile(f)
err = tag.WriteToFile(f)
if err != nil {
t.Errorf("WriteID3v1ToFile failed: %s", err)
}

12
v1/v11read.go

@ -10,21 +10,21 @@ import (
)
// Retrieves ID3v1.1 field values of provided io.ReadSeeker
func Getv11Tags(rs io.ReadSeeker) (*ID3v11Tags, error) {
func Getv11Tag(rs io.ReadSeeker) (*ID3v11Tag, error) {
// set reader to the last 128 bytes
_, err := rs.Seek(-int64(ID3v1SIZE), io.SeekEnd)
if err != nil {
return nil, fmt.Errorf("could not seek: %s", err)
}
tag, err := util.Read(rs, 3)
identifier, err := util.Read(rs, 3)
if err != nil {
return nil, err
}
if !bytes.Equal(tag, []byte(ID3v1IDENTIFIER)) {
// no TAG, given file does not use ID3v1
return nil, fmt.Errorf("does not use ID3v1: expected %s; got %s", ID3v1IDENTIFIER, tag)
if !bytes.Equal(identifier, []byte(ID3v1IDENTIFIER)) {
// no identifier, given file does not use ID3v1
return nil, fmt.Errorf("does not use ID3v1: expected %s; got %s", ID3v1IDENTIFIER, identifier)
}
songname, err := util.ReadToString(rs, 30)
@ -85,7 +85,7 @@ func Getv11Tags(rs io.ReadSeeker) (*ID3v11Tags, error) {
genre = ""
}
return &ID3v11Tags{
return &ID3v11Tag{
SongName: songname,
Artist: artist,
Album: album,

4
v1/v11tags.go → v1/v11tag.go

@ -1,6 +1,6 @@
package v1
type ID3v11Tags struct {
type ID3v11Tag struct {
SongName string
Artist string
Album string
@ -10,6 +10,6 @@ type ID3v11Tags struct {
Genre string
}
func (tags *ID3v11Tags) Version() int {
func (*ID3v11Tag) Version() int {
return 11
}

34
v1/v11write.go

@ -10,10 +10,10 @@ import (
"github.com/Unbewohnte/id3ed/util"
)
// Writes given ID3v1.1 tags to dst
// Writes given ID3v1.1 tag to dst
// NOTE: will not remove already existing ID3v1.1 tag if it`s present,
// use ⁕WriteToFile⁕ method if you`re working with REAL mp3 files !!!
func (tags *ID3v11Tags) Write(dst io.WriteSeeker) error {
func (tag *ID3v11Tag) Write(dst io.WriteSeeker) error {
dst.Seek(0, io.SeekEnd)
// TAG
@ -23,31 +23,31 @@ func (tags *ID3v11Tags) Write(dst io.WriteSeeker) error {
}
// Song name
err = util.WriteToExtent(dst, []byte(tags.SongName), 30)
err = util.WriteToExtent(dst, []byte(tag.SongName), 30)
if err != nil {
return fmt.Errorf("could not write to dst: %s", err)
}
// Artist
err = util.WriteToExtent(dst, []byte(tags.Artist), 30)
err = util.WriteToExtent(dst, []byte(tag.Artist), 30)
if err != nil {
return fmt.Errorf("could not write to dst: %s", err)
}
// Album
err = util.WriteToExtent(dst, []byte(tags.Album), 30)
err = util.WriteToExtent(dst, []byte(tag.Album), 30)
if err != nil {
return fmt.Errorf("could not write to dst: %s", err)
}
// Year
err = util.WriteToExtent(dst, []byte(fmt.Sprint(tags.Year)), 4)
err = util.WriteToExtent(dst, []byte(fmt.Sprint(tag.Year)), 4)
if err != nil {
return fmt.Errorf("could not write to dst: %s", err)
}
// Comment
err = util.WriteToExtent(dst, []byte(tags.Comment), 28)
err = util.WriteToExtent(dst, []byte(tag.Comment), 28)
if err != nil {
return fmt.Errorf("could not write to dst: %s", err)
}
@ -59,14 +59,14 @@ func (tags *ID3v11Tags) Write(dst io.WriteSeeker) error {
// Track
trackBytes := make([]byte, 1)
binary.PutVarint(trackBytes, int64(tags.Track))
binary.PutVarint(trackBytes, int64(tag.Track))
_, err = dst.Write(trackBytes)
if err != nil {
return fmt.Errorf("could not write to dst: %s", err)
}
//Genre
genreCode := util.GetKey(id3v1genres, tags.Genre)
genreCode := util.GetKey(id3v1genres, tag.Genre)
if genreCode == -1 {
// if no genre found - encode genre code as 255
genreCode = ID3v1INVALIDGENRE
@ -82,8 +82,8 @@ func (tags *ID3v11Tags) Write(dst io.WriteSeeker) error {
return nil
}
// Checks for existing ID3v1.1 tag in file, if present - removes it and replaces with provided tags
func (tags *ID3v11Tags) WriteToFile(f *os.File) error {
// Checks for existing ID3v1.1 tag in file, if present - removes it and replaces with provided tag
func (tag *ID3v11Tag) WriteToFile(f *os.File) error {
defer f.Close()
// check for existing ID3v1.1 tag
@ -92,16 +92,16 @@ func (tags *ID3v11Tags) WriteToFile(f *os.File) error {
return fmt.Errorf("could not seek: %s", err)
}
tag, err := util.Read(f, 3)
identifier, err := util.Read(f, 3)
if err != nil {
// return err
return err
}
if !bytes.Equal(tag, []byte(ID3v1IDENTIFIER)) {
// no existing tag, just write given tags
err = tags.Write(f)
if !bytes.Equal(identifier, []byte(ID3v1IDENTIFIER)) {
// no existing identifier, just write given tag
err = tag.Write(f)
if err != nil {
return fmt.Errorf("could not write to writer: %s", err)
}
@ -119,8 +119,8 @@ func (tags *ID3v11Tags) WriteToFile(f *os.File) error {
return fmt.Errorf("could not truncate file %s", err)
}
// writing new tags
err = tags.Write(f)
// writing new tag
err = tag.Write(f)
if err != nil {
return fmt.Errorf("could not write to writer: %s", err)
}

4
v1/v1read.go

@ -10,7 +10,7 @@ import (
)
// Retrieves ID3v1 field values of provided io.ReadSeeker (usually a file)
func Getv1Tags(rs io.ReadSeeker) (*ID3v1Tags, error) {
func Getv1Tag(rs io.ReadSeeker) (*ID3v1Tag, error) {
// set reader to the last 128 bytes
_, err := rs.Seek(-int64(ID3v1SIZE), io.SeekEnd)
if err != nil {
@ -69,7 +69,7 @@ func Getv1Tags(rs io.ReadSeeker) (*ID3v1Tags, error) {
genre = ""
}
return &ID3v1Tags{
return &ID3v1Tag{
SongName: songname,
Artist: artist,
Album: album,

4
v1/v1tags.go → v1/v1tag.go

@ -2,7 +2,7 @@ package v1
// https://id3.org/ID3v1 - documentation
type ID3v1Tags struct {
type ID3v1Tag struct {
SongName string
Artist string
Album string
@ -11,6 +11,6 @@ type ID3v1Tags struct {
Genre string
}
func (tags *ID3v1Tags) Version() int {
func (*ID3v1Tag) Version() int {
return 10
}

34
v1/v1write.go

@ -10,50 +10,50 @@ import (
"github.com/Unbewohnte/id3ed/util"
)
// Writes given ID3v1.0 tags to given io.WriteSeeker.
// Writes given ID3v1.0 tag to given io.WriteSeeker.
// NOTE: will not remove already existing ID3v1 tag if it`s present,
// use ⁕WriteToFile⁕ method if you`re working with REAL mp3 files !!!
func (tags *ID3v1Tags) Write(dst io.WriteSeeker) error {
func (tag *ID3v1Tag) Write(dst io.WriteSeeker) error {
dst.Seek(0, io.SeekEnd)
// TAG
// ID
_, err := dst.Write([]byte(ID3v1IDENTIFIER))
if err != nil {
return fmt.Errorf("could not write to writer: %s", err)
}
// Song name
err = util.WriteToExtent(dst, []byte(tags.SongName), 30)
err = util.WriteToExtent(dst, []byte(tag.SongName), 30)
if err != nil {
return fmt.Errorf("could not write to writer: %s", err)
}
// Artist
err = util.WriteToExtent(dst, []byte(tags.Artist), 30)
err = util.WriteToExtent(dst, []byte(tag.Artist), 30)
if err != nil {
return fmt.Errorf("could not write to writer: %s", err)
}
// Album
err = util.WriteToExtent(dst, []byte(tags.Album), 30)
err = util.WriteToExtent(dst, []byte(tag.Album), 30)
if err != nil {
return fmt.Errorf("could not write to writer: %s", err)
}
// Year
err = util.WriteToExtent(dst, []byte(fmt.Sprint(tags.Year)), 4)
err = util.WriteToExtent(dst, []byte(fmt.Sprint(tag.Year)), 4)
if err != nil {
return fmt.Errorf("could not write to writer: %s", err)
}
// Comment
err = util.WriteToExtent(dst, []byte(tags.Comment), 30)
err = util.WriteToExtent(dst, []byte(tag.Comment), 30)
if err != nil {
return fmt.Errorf("could not write to writer: %s", err)
}
// Genre
genreCode := util.GetKey(id3v1genres, tags.Genre)
genreCode := util.GetKey(id3v1genres, tag.Genre)
if genreCode == -1 {
// if no genre found - encode genre code as 255
genreCode = ID3v1INVALIDGENRE
@ -69,21 +69,21 @@ func (tags *ID3v1Tags) Write(dst io.WriteSeeker) error {
return nil
}
// Checks for existing ID3v1 tag in file, if present - removes it and replaces with provided tags
func (tags *ID3v1Tags) WriteToFile(f *os.File) error {
// Checks for existing ID3v1 tag in file, if present - removes it and replaces with provided tag
func (tag *ID3v1Tag) WriteToFile(f *os.File) error {
defer f.Close()
// check for existing ID3v1 tag
f.Seek(-int64(ID3v1SIZE), io.SeekEnd)
tag, err := util.Read(f, 3)
identifier, err := util.Read(f, 3)
if err != nil {
return err
}
if !bytes.Equal(tag, []byte(ID3v1IDENTIFIER)) {
// no existing tag, just write given tags
err = tags.Write(f)
if !bytes.Equal(identifier, []byte(ID3v1IDENTIFIER)) {
// no existing identifier, just write given tag
err = tag.Write(f)
if err != nil {
return err
}
@ -101,8 +101,8 @@ func (tags *ID3v1Tags) WriteToFile(f *os.File) error {
return fmt.Errorf("could not truncate file %s", err)
}
// writing new tags
err = tags.Write(f)
// writing new tag
err = tag.Write(f)
if err != nil {
return fmt.Errorf("could not write to writer: %s", err)
}

0
v2/v2tags.go → v2/v2tag.go

Loading…
Cancel
Save