Compare commits

...

2 Commits

Author SHA1 Message Date
Octopus Octopus 9842fbc069 remove output files from git tree 2024-03-13 12:14:10 -05:00
Octopus Octopus 9d58b083af add .flac reading 2024-03-13 12:13:19 -05:00
9 changed files with 63 additions and 4 deletions

BIN
cmus2obs

Binary file not shown.

5
go.mod
View File

@ -1,3 +1,8 @@
module cmus2obs
go 1.22.1
require (
github.com/go-flac/flacpicture v0.3.0 // indirect
github.com/go-flac/go-flac v1.0.0 // indirect
)

4
go.sum Normal file
View File

@ -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
View File

@ -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

View File

@ -1 +0,0 @@
LOVE /// DISCONNECT

View File

@ -1 +0,0 @@
♥ GOJII ♥

View File

View File

@ -1 +0,0 @@
TOOTHPASTE FOREST ( SHADY ☆ MONK RMX )