|
|
|
@ -18,7 +18,7 @@
|
|
|
|
|
**ID3v2**. can: |
|
|
|
|
|
|
|
|
|
- read |
|
|
|
|
|
|
|
|
|
- write |
|
|
|
|
|
|
|
|
|
--- |
|
|
|
|
|
|
|
|
@ -37,110 +37,9 @@ go install github.com/Unbewohnte/id3ed/...
|
|
|
|
|
|
|
|
|
|
--- |
|
|
|
|
|
|
|
|
|
# ∙ Examples |
|
|
|
|
|
|
|
|
|
## ⚬ Directly reading ID3v1 |
|
|
|
|
``` |
|
|
|
|
package main |
|
|
|
|
|
|
|
|
|
import( |
|
|
|
|
"fmt" |
|
|
|
|
id3v1 "github.com/Unbewohnte/id3ed/v1" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
func main() { |
|
|
|
|
mp3file, err := os.Open("/path/to/mp3/myMP3.mp3") |
|
|
|
|
if err != nil { |
|
|
|
|
panic(err) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// extract ID3v1.1 tag |
|
|
|
|
mp3tag, err := id3v1.Readv1Tag(mp3file) |
|
|
|
|
if err != nil { |
|
|
|
|
panic(err) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// print the whole tag |
|
|
|
|
fmt.Printf("%+v",mp3tag) |
|
|
|
|
|
|
|
|
|
// get certain fields |
|
|
|
|
songname := mp3tag.SongName |
|
|
|
|
|
|
|
|
|
genre := mp3tag.Genre |
|
|
|
|
|
|
|
|
|
// etc. |
|
|
|
|
} |
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
## ⚬ Directly writing ID3v1 |
|
|
|
|
``` |
|
|
|
|
package main |
|
|
|
|
|
|
|
|
|
import( |
|
|
|
|
"fmt" |
|
|
|
|
id3v1 "github.com/Unbewohnte/id3ed/v1" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
func main() { |
|
|
|
|
f, err := os.OpenFile("/path/to/file/myfile.mp3",os.O_WRONLY, os.ModePerm) |
|
|
|
|
if err != nil { |
|
|
|
|
panic(err) |
|
|
|
|
} |
|
|
|
|
defer f.Close() |
|
|
|
|
|
|
|
|
|
// create your tags struct |
|
|
|
|
tag := &id3v1.ID3v1Tag{ |
|
|
|
|
SongName: "mysong", |
|
|
|
|
Artist: "me", |
|
|
|
|
Album: "my album", |
|
|
|
|
Year: 2021, |
|
|
|
|
Comment: "Cool song", |
|
|
|
|
Track: 1, |
|
|
|
|
Genre: "Christian Gangsta Rap", // for list of genres see: "./v1/genres.go" |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// write tags to file |
|
|
|
|
err = tag.WriteToFile(f) |
|
|
|
|
if err != nil { |
|
|
|
|
panic(err) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
## ⚬ Directly reading ID3v2 |
|
|
|
|
``` |
|
|
|
|
package main |
|
|
|
|
|
|
|
|
|
import( |
|
|
|
|
"fmt" |
|
|
|
|
id3v2 "github.com/Unbewohnte/id3ed/v2" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
func main() { |
|
|
|
|
mp3file, err := os.Open("/path/to/mp3/myMP3.mp3") |
|
|
|
|
if err != nil { |
|
|
|
|
panic(err) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// extract ID3v2 tag |
|
|
|
|
mp3tag, err := id3v2.Readv2Tag(mp3file) |
|
|
|
|
if err != nil { |
|
|
|
|
panic(err) |
|
|
|
|
} |
|
|
|
|
# ∙ Example |
|
|
|
|
|
|
|
|
|
// you can get some essential frames` contents from getters |
|
|
|
|
title := tag.Title() // string |
|
|
|
|
|
|
|
|
|
// or get direct frame by id |
|
|
|
|
commentFrame := tag.GetFrame("COMM") // *Frame |
|
|
|
|
// commentFrame.(Header.(...)|Contents) |
|
|
|
|
|
|
|
|
|
// etc. |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
## ⚬ Easier way to read/write tags |
|
|
|
|
## ⚬ Read/Write v1&&v2 tags |
|
|
|
|
|
|
|
|
|
``` |
|
|
|
|
package main |
|
|
|
@ -149,6 +48,7 @@ import(
|
|
|
|
|
"fmt" |
|
|
|
|
"github.com/Unbewohnte/id3ed" |
|
|
|
|
id3v1 "github.com/Unbewohnte/id3ed/v1" |
|
|
|
|
id3v2 "github.com/Unbewohnte/id3ed/v2" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
func main() { |
|
|
|
@ -158,12 +58,24 @@ func main() {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// reading and writing tags is easy and done by one struct ! |
|
|
|
|
|
|
|
|
|
// print all v2 frames |
|
|
|
|
if f.ContainsID3v2 { |
|
|
|
|
for_, frame := range f.ID3v2Tag.Frames{ |
|
|
|
|
fmt.Printf("%s\n", frame.Header.ID) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// create your own v2 tag from custom frames |
|
|
|
|
myframe, _ := id3v2.NewFrame("TXXX", []byte("Very important data (ᗜˬᗜ)") ,true) |
|
|
|
|
v2tag := id3v2.NewTAG([]id3v2.Frame{*myframe}) |
|
|
|
|
|
|
|
|
|
// replace v2 tag of the file |
|
|
|
|
f.WriteID3v2(v2tag) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// create your own ID3v1 tag |
|
|
|
|
tag := &id3v1.ID3v1Tag{ |
|
|
|
|
SongName: "mysong", |
|
|
|
|
Artist: "me", |
|
|
|
@ -174,6 +86,7 @@ func main() {
|
|
|
|
|
Genre: "Christian Gangsta Rap", // for list of genres see: "./v1/genres.go" |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// write your v1 tag |
|
|
|
|
err = f.WriteID3v1(tag) |
|
|
|
|
if err != nil { |
|
|
|
|
panic(err) |
|
|
|
|