diff --git a/cmus2obs b/cmus2obs index f18c77f..09a5b82 100755 Binary files a/cmus2obs and b/cmus2obs differ diff --git a/go.mod b/go.mod index d8d0930..0f015a6 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,8 @@ module cmus2obs -go 1.22.1 \ No newline at end of file +go 1.22.1 + +require ( + github.com/go-flac/flacpicture v0.3.0 // indirect + github.com/go-flac/go-flac v1.0.0 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..c9e2442 --- /dev/null +++ b/go.sum @@ -0,0 +1,4 @@ +github.com/go-flac/flacpicture v0.3.0 h1:LkmTxzFLIynwfhHiZsX0s8xcr3/u33MzvV89u+zOT8I= +github.com/go-flac/flacpicture v0.3.0/go.mod h1:DPbrzVYQ3fJcvSgLFp9HXIrEQEdfdk/+m0nQCzwodZI= +github.com/go-flac/go-flac v1.0.0 h1:6qI9XOVLcO50xpzm3nXvO31BgDgHhnr/p/rER/K/doY= +github.com/go-flac/go-flac v1.0.0/go.mod h1:WnZhcpmq4u1UdZMNn9LYSoASpWOCMOoxXxcWEHSzkW8= diff --git a/main.go b/main.go index 7a8505d..d066b6c 100644 --- a/main.go +++ b/main.go @@ -1,12 +1,16 @@ package main import ( + "errors" "fmt" "log" "os" "strings" "os/exec" + + "github.com/go-flac/flacpicture" + "github.com/go-flac/go-flac" ) const TIMER = 2 @@ -31,9 +35,58 @@ func main() { title = "Unknown" } + filepath, err := getAttribute(remoteResp, "file ") + if err != nil { + log.Fatal(err.Error()) + } + img := make([]byte, 0) + if strings.HasSuffix(filepath, ".flac") { + img, err = getFlacArt(filepath) + if err != nil { + img = defaultArt() + } + } else if strings.HasSuffix(filepath, ".mp3") { + getMP3Art() + } else { + defaultArt() + } + writeTxt("SongAlbum", album) writeTxt("SongArtist", artist) writeTxt("SongTitle", title) + writeJpg("AlbumArt", img) +} + +func getFlacArt(s string) ([]byte, error) { + f, err := flac.ParseFile(s) + if err != nil { + return nil, errors.New("can't open file") + } + for _, metadata := range f.Meta { + if metadata.Type == flac.Picture { + pic, err := flacpicture.ParseFromMetaDataBlock(*metadata) + return pic.ImageData, err + } + } + return nil, errors.New("no image found") +} + +func getMP3Art() { + +} + +func defaultArt() []byte { + return nil +} + +func writeJpg(filename string, input []byte) { + f, err := os.Create("./output/" + filename + ".jpg") + if err != nil { + log.Fatal(err.Error()) + } + defer f.Close() + + f.Write(input) } func writeTxt(filename, input string) { diff --git a/output/AlbumArt.jpg b/output/AlbumArt.jpg index 2265011..b854919 100644 Binary files a/output/AlbumArt.jpg and b/output/AlbumArt.jpg differ diff --git a/output/SongAlbum.txt b/output/SongAlbum.txt index 736950d..7828974 100644 --- a/output/SongAlbum.txt +++ b/output/SongAlbum.txt @@ -1 +1 @@ -LOVE /// DISCONNECT \ No newline at end of file +Beyond Canon \ No newline at end of file diff --git a/output/SongArtist.txt b/output/SongArtist.txt index 63427ca..95c146d 100644 --- a/output/SongArtist.txt +++ b/output/SongArtist.txt @@ -1 +1 @@ -♥ GOJII ♥ \ No newline at end of file +Homestuck \ No newline at end of file diff --git a/output/SongTitle.txt b/output/SongTitle.txt index c97e1ac..5922f5c 100644 --- a/output/SongTitle.txt +++ b/output/SongTitle.txt @@ -1 +1 @@ -TOOTHPASTE FOREST ( SHADY ☆ MONK RMX ) \ No newline at end of file +Make a Pretty Picture \ No newline at end of file