diff --git a/README.md b/README.md index 36ef5ea..400a6e7 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,40 @@ # ID3ED (ID3 - Encoder - Decoder) ## Library for encoding/decoding ID3 tags +# Installation +`go get https://github.com/Unbewohnte/id3ed` + +# Usage + +``` +package main + +import( + "fmt" + "github.com/Unbewohnte/id3ed" +) + +func main() { + mp3file, err := os.Open("/path/to/mp3/myMP3.mp3") + if err != nil { + panic(err) + } + + mp3tags, err := GetID3v11Tags(mp3file) + if err != nil { + panic(err) + } + + // printing all tags + fmt.Printf("%+v",mp3tags) + + // getting certain tag + songname := mp3tags.GetSongName() + + // etc. +} + +``` + # Under construction ! ## Bugs are a possibility rn in this state \ No newline at end of file diff --git a/id3v10.go b/id3v10.go index 65fa0bc..83998af 100644 --- a/id3v10.go +++ b/id3v10.go @@ -38,17 +38,17 @@ func GetID3v1Tags(rs io.ReadSeeker) (*ID3v1Tags, error) { return nil, fmt.Errorf("does not use ID3v1") } - songname, err := read(rs, 30) + songname, err := readToString(rs, 30) if err != nil { return nil, err } - artist, err := read(rs, 30) + artist, err := readToString(rs, 30) if err != nil { return nil, err } - album, err := read(rs, 30) + album, err := readToString(rs, 30) if err != nil { return nil, err } @@ -62,7 +62,7 @@ func GetID3v1Tags(rs io.ReadSeeker) (*ID3v1Tags, error) { return nil, fmt.Errorf("could not convert yearbytes into int: %s", err) } - comment, err := read(rs, 30) + comment, err := readToString(rs, 30) if err != nil { return nil, err } @@ -78,11 +78,11 @@ func GetID3v1Tags(rs io.ReadSeeker) (*ID3v1Tags, error) { } return &ID3v1Tags{ - SongName: string(songname), - Artist: string(artist), - Album: string(album), + SongName: songname, + Artist: artist, + Album: album, Year: year, - Comment: string(comment), + Comment: comment, Genre: genre, }, nil } diff --git a/id3v11.go b/id3v11.go index 26875b3..3da3e98 100644 --- a/id3v11.go +++ b/id3v11.go @@ -35,17 +35,17 @@ func GetID3v11Tags(rs io.ReadSeeker) (*ID3v11Tags, error) { return nil, fmt.Errorf("does not use ID3v1") } - songname, err := read(rs, 30) + songname, err := readToString(rs, 30) if err != nil { return nil, err } - artist, err := read(rs, 30) + artist, err := readToString(rs, 30) if err != nil { return nil, err } - album, err := read(rs, 30) + album, err := readToString(rs, 30) if err != nil { return nil, err } @@ -59,7 +59,7 @@ func GetID3v11Tags(rs io.ReadSeeker) (*ID3v11Tags, error) { return nil, fmt.Errorf("could not convert yearbytes into int: %s", err) } - comment, err := read(rs, 28) + comment, err := readToString(rs, 28) if err != nil { return nil, err } @@ -89,11 +89,11 @@ func GetID3v11Tags(rs io.ReadSeeker) (*ID3v11Tags, error) { } return &ID3v11Tags{ - SongName: string(songname), - Artist: string(artist), - Album: string(album), + SongName: songname, + Artist: artist, + Album: album, Year: year, - Comment: string(comment), + Comment: comment, Track: track, Genre: genre, }, nil diff --git a/util.go b/util.go index 691838c..21cd30e 100644 --- a/util.go +++ b/util.go @@ -15,3 +15,13 @@ func read(rs io.Reader, n int) ([]byte, error) { return read, nil } + +// Shortcut function to read n bytes and convert them into string +func readToString(rs io.Reader, n int) (string, error) { + read := make([]byte, n) + _, err := rs.Read(read) + if err != nil { + return "", fmt.Errorf("could not read from reader: %s", err) + } + return string(read), nil +}