first commit. lay groundworks for reading.

This commit is contained in:
Octopus Octopus 2024-03-13 11:35:20 -05:00
commit 21733c11e4
8 changed files with 68 additions and 0 deletions

BIN
cmus2obs Executable file

Binary file not shown.

3
go.mod Normal file
View File

@ -0,0 +1,3 @@
module cmus2obs
go 1.22.1

62
main.go Normal file
View File

@ -0,0 +1,62 @@
package main
import (
"fmt"
"log"
"os"
"strings"
"os/exec"
)
const TIMER = 2
func main() {
c := exec.Command("cmus-remote", "-Q")
o, _ := c.Output()
remoteResp := strings.Split(string(o), "\n")
//Album
album, err := getAttribute(remoteResp, "tag album ")
if err != nil {
album = "Unknown"
}
//artist
artist, err := getAttribute(remoteResp, "tag artist ")
if err != nil {
artist = "Unknown"
}
// Title
title, err := getAttribute(remoteResp, "tag title ")
if err != nil {
title = "Unknown"
}
writeTxt("SongAlbum", album)
writeTxt("SongArtist", artist)
writeTxt("SongTitle", title)
}
func writeTxt(filename, input string) {
f, err := os.Create("./output/" + filename + ".txt")
if err != nil {
log.Fatal(err.Error())
}
defer f.Close()
f.Write([]byte(input))
}
func getAttribute(input []string, prefix string) (string, error) {
var attr string
for i := range input {
has := strings.HasPrefix(input[i], prefix)
if has {
attr = input[i]
}
}
attr, b := strings.CutPrefix(attr, prefix)
if !b {
return "", fmt.Errorf("did not find prefix \"%v\"", prefix)
}
return attr, nil
}

BIN
output/AlbumArt.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 96 KiB

1
output/SongAlbum.txt Normal file
View File

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

1
output/SongArtist.txt Normal file
View File

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

0
output/SongInfo.txt Normal file
View File

1
output/SongTitle.txt Normal file
View File

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