aboutsummaryrefslogtreecommitdiff
path: root/cmd/mpd-scrobbler/main.go
diff options
context:
space:
mode:
authorFranck Cuny <franck@fcuny.net>2025-08-29 09:23:18 -0700
committerFranck Cuny <franck@fcuny.net>2025-08-29 09:23:18 -0700
commit91ead5e4493bb459ea537ad204e7e6b3d15a220b (patch)
treef712f9d75a969479bda177bc439918ed2a1008f0 /cmd/mpd-scrobbler/main.go
parentfix readme for x509-info project (diff)
parentprepare the migration (diff)
downloadx-91ead5e4493bb459ea537ad204e7e6b3d15a220b.tar.gz
Merge remote-tracking branch 'import/main'
Diffstat (limited to '')
-rw-r--r--cmd/mpd-scrobbler/main.go57
1 files changed, 57 insertions, 0 deletions
diff --git a/cmd/mpd-scrobbler/main.go b/cmd/mpd-scrobbler/main.go
new file mode 100644
index 0000000..c2693a4
--- /dev/null
+++ b/cmd/mpd-scrobbler/main.go
@@ -0,0 +1,57 @@
+package main
+
+import (
+ "flag"
+ "fmt"
+ "log"
+ "os"
+ "path/filepath"
+
+ "golang.fcuny.net/mpd-stats/internal/scrobbler"
+)
+
+func main() {
+ var (
+ mpdHost = flag.String("host", "localhost", "The MPD server to connect to (default: localhost)")
+ mpdPort = flag.Int("port", 6600, "The TCP port of the MPD server to connect to (default: 6600)")
+ )
+ flag.Parse()
+
+ net := "tcp"
+ addr := fmt.Sprintf("%s:%d", *mpdHost, *mpdPort)
+
+ dbpath, err := getDbPath()
+ if err != nil {
+ log.Fatalf("failed to get the path to the database: %v", err)
+ }
+
+ s, err := scrobbler.NewScrobbler(net, addr, dbpath)
+ if err != nil {
+ log.Fatalf("failed to create a client: %v", err)
+ }
+
+ defer func() {
+ if err := s.Close(); err != nil {
+ log.Fatalf("failed to close the scrobbler: %v", err)
+ }
+ }()
+
+ s.Run()
+}
+
+func getDbPath() (string, error) {
+ xch := os.Getenv("XDG_CONFIG_HOME")
+ if xch == "" {
+ home := os.Getenv("HOME")
+ xch = filepath.Join(home, ".config")
+ }
+
+ scrobblerHome := filepath.Join(xch, "mpd-scrobbler")
+ if _, err := os.Stat(scrobblerHome); os.IsNotExist(err) {
+ if err := os.Mkdir(scrobblerHome, 0755); err != nil {
+ return "", err
+ }
+ }
+
+ return filepath.Join(scrobblerHome, "scrobbler.sql"), nil
+}