Compare commits
2 Commits
89cc368f7c
...
9842fbc069
Author | SHA1 | Date |
---|---|---|
|
9842fbc069 | |
|
9d58b083af |
7
go.mod
7
go.mod
|
@ -1,3 +1,8 @@
|
|||
module cmus2obs
|
||||
|
||||
go 1.22.1
|
||||
go 1.22.1
|
||||
|
||||
require (
|
||||
github.com/go-flac/flacpicture v0.3.0 // indirect
|
||||
github.com/go-flac/go-flac v1.0.0 // indirect
|
||||
)
|
||||
|
|
|
@ -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=
|
53
main.go
53
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) {
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 96 KiB |
|
@ -1 +0,0 @@
|
|||
LOVE /// DISCONNECT
|
|
@ -1 +0,0 @@
|
|||
♥ GOJII ♥
|
|
@ -1 +0,0 @@
|
|||
TOOTHPASTE FOREST ( SHADY ☆ MONK RMX )
|
Loading…
Reference in New Issue