Skip to content

Commit

Permalink
update all comments. update package name. change some exports. this s…
Browse files Browse the repository at this point in the history
…hould clean quite a bit of the code up.
  • Loading branch information
gcottom committed Oct 4, 2023
1 parent 537b32e commit 4be02dd
Show file tree
Hide file tree
Showing 16 changed files with 187 additions and 191 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vendor/
10 changes: 5 additions & 5 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"os"
"strings"

mp3mp4tag "github.com/gcottom/mp3-mp4-tag"
"github.com/gcottom/audiometa"
)

func main() {
Expand All @@ -22,7 +22,7 @@ func main() {
mode = strings.ToLower(args[0])
if len(args)%2 == 0 && len(args) != 1 {
if mode == "p" || mode == "parse" || mode == "r" || mode == "read" || mode == "-p" || mode == "-parse" || mode == "-r" || mode == "-read" {
tag, err := mp3mp4tag.OpenTag(file)
tag, err := audiometa.OpenTag(file)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -108,7 +108,7 @@ func main() {
}
} else if mode == "s" || mode == "w" || mode == "save" || mode == "write" || mode == "-s" || mode == "-w" || mode == "-save" || mode == "-write" {
if len(args) > 2 {
tag, err := mp3mp4tag.OpenTag(file)
tag, err := audiometa.OpenTag(file)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -136,7 +136,7 @@ func main() {
} else if cmdTag == "b" || cmdTag == "-b" || cmdTag == "bpm" || cmdTag == "-bpm" {
tag.SetBPM(writeTag)
} else {
fileType, err := mp3mp4tag.GetFileType(args[1])
fileType, err := audiometa.GetFileType(args[1])
if err != nil {
fmt.Println(err)
}
Expand All @@ -155,7 +155,7 @@ func main() {
}

} else if mode == "c" || mode == "clear" || mode == "e" || mode == "empty" || mode == "-c" || mode == "-clear" || mode == "-e" || mode == "-empty" {
tag, err := mp3mp4tag.OpenTag(file)
tag, err := audiometa.OpenTag(file)
if err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion flac.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package mp3mp4tag
package audiometa

import (
"github.com/go-flac/flacvorbis"
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/gcottom/mp3-mp4-tag
module github.com/gcottom/audiometa

go 1.20

Expand Down
64 changes: 27 additions & 37 deletions mp4.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package mp3mp4tag
package audiometa

import (
"bytes"
Expand Down Expand Up @@ -46,7 +46,7 @@ var pngHeader = []byte{137, 80, 78, 71, 13, 10, 26, 10}

type atomNames map[string]string

func (f atomNames) Name(n string) []string {
func (f atomNames) name(n string) []string {
res := make([]string, 1)
for k, v := range f {
if v == n {
Expand All @@ -61,13 +61,13 @@ type metadataMP4 struct {
data map[string]interface{}
}

func ReadFromMP4(r io.ReadSeeker) (metadataMP4, error) {
return ReadAtoms(r)
func readFromMP4(r io.ReadSeeker) (metadataMP4, error) {
return readAtoms(r)
}

// ReadAtoms reads MP4 metadata atoms from the io.ReadSeeker into a Metadata, returning
// non-nil error if there was a problem.
func ReadAtoms(r io.ReadSeeker) (metadataMP4, error) {
func readAtoms(r io.ReadSeeker) (metadataMP4, error) {
m := metadataMP4{
data: make(map[string]interface{}),
}
Expand Down Expand Up @@ -272,8 +272,6 @@ func readCustomAtom(r io.ReadSeeker, size uint32) (_ string, data []string, _ er
return subNames["name"], data, nil
}

func (m metadataMP4) Raw() map[string]interface{} { return m.data }

func (m metadataMP4) getString(n []string) string {
for _, k := range n {
if x, ok := m.data[k]; ok {
Expand All @@ -292,56 +290,48 @@ func (m metadataMP4) getInt(n []string) int {
return 0
}

func (m metadataMP4) Title() string {
return m.getString(atoms.Name("title"))
func (m metadataMP4) title() string {
return m.getString(atoms.name("title"))
}

func (m metadataMP4) Artist() string {
return m.getString(atoms.Name("artist"))
func (m metadataMP4) artist() string {
return m.getString(atoms.name("artist"))
}

func (m metadataMP4) Album() string {
return m.getString(atoms.Name("album"))
func (m metadataMP4) album() string {
return m.getString(atoms.name("album"))
}

func (m metadataMP4) AlbumArtist() string {
return m.getString(atoms.Name("album_artist"))
func (m metadataMP4) albumArtist() string {
return m.getString(atoms.name("album_artist"))
}

func (m metadataMP4) Composer() string {
return m.getString(atoms.Name("composer"))
func (m metadataMP4) composer() string {
return m.getString(atoms.name("composer"))
}

func (m metadataMP4) Genre() string {
return m.getString(atoms.Name("genre"))
func (m metadataMP4) genre() string {
return m.getString(atoms.name("genre"))
}

func (m metadataMP4) Year() int {
date := m.getString(atoms.Name("year"))
func (m metadataMP4) year() int {
date := m.getString(atoms.name("year"))
if len(date) >= 4 {
year, _ := strconv.Atoi(date[:4])
return year
}
return 0
}

func (m metadataMP4) Lyrics() string {
t, ok := m.data["\xa9lyr"]
if !ok {
return ""
}
return t.(string)
}

func (m metadataMP4) Comment() string {
func (m metadataMP4) comment() string {
t, ok := m.data["\xa9cmt"]
if !ok {
return ""
}
return t.(string)
}

func (m metadataMP4) Picture() []byte {
func (m metadataMP4) picture() []byte {
v, ok := m.data["covr"]
if !ok {
return nil
Expand All @@ -356,13 +346,13 @@ func (m metadataMP4) Picture() []byte {

}

func (m metadataMP4) Tempo() int {
return m.getInt(atoms.Name("tempo"))
func (m metadataMP4) tempo() int {
return m.getInt(atoms.name("tempo"))
}

func (m metadataMP4) Encoder() string {
return m.getString(atoms.Name("encoder"))
func (m metadataMP4) encoder() string {
return m.getString(atoms.name("encoder"))
}
func (m metadataMP4) Copyright() string {
return m.getString(atoms.Name("copyright"))
func (m metadataMP4) copyright() string {
return m.getString(atoms.name("copyright"))
}
Loading

0 comments on commit 4be02dd

Please sign in to comment.