From 53cc05214fbaa1ea30b170c0dac2e264bc1a0a59 Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Wed, 19 Jun 2024 23:02:35 -0700 Subject: [PATCH] Add mpdscrobble service --- oni/home/config/rincewind.scm | 4 ++- oni/home/services/mpd.scm | 49 +++++++++++++++++++++++++++++++++-- oni/packages/mpd.scm | 30 ++++++++++++++++++++- 3 files changed, 79 insertions(+), 4 deletions(-) diff --git a/oni/home/config/rincewind.scm b/oni/home/config/rincewind.scm index fe607e2..83c1883 100644 --- a/oni/home/config/rincewind.scm +++ b/oni/home/config/rincewind.scm @@ -109,7 +109,8 @@ home-mpd-configuration home-mpc-update-service-type - home-mpd-notify-service-type)) + home-mpd-notify-service-type + home-mpdscrobble-service-type)) #:use-module ((oni home services mpv) #:select (home-mpv-service-type home-mpv-mpris-service-type)) @@ -466,6 +467,7 @@ #:format "44100:16:2"))))) (service home-mpc-update-service-type) (service home-mpd-notify-service-type) + (service home-mpdscrobble-service-type) (service home-mpv-service-type) ;; [2024-01-05 Fri] mpv-mpris fails to compile: diff --git a/oni/home/services/mpd.scm b/oni/home/services/mpd.scm index c3c272c..0fcd411 100644 --- a/oni/home/services/mpd.scm +++ b/oni/home/services/mpd.scm @@ -10,7 +10,8 @@ #:use-module (oop goops) #:use-module (ice-9 string-fun) #:use-module ((oni packages mpd) - #:select (mpd-notify)) + #:select (mpd-notify + mpdscrobble)) #:export (home-mpd-service-type home-mpd-configuration @@ -20,7 +21,10 @@ home-mpc-update-configuration home-mpd-notify-service-type - home-mpd-notify-configuration)) + home-mpd-notify-configuration + + home-mpdscrobble-service-type + home-mpdscrobble-configuration)) (define (serialize-boolean field value) "") @@ -204,3 +208,44 @@ (compose identity) (default-value (home-mpd-notify-configuration)) (description "Install and configure mpd notifications."))) + +(define-configuration home-mpdscrobble-configuration + (package + (package mpdscrobble) + "Pakcage to use for setting mpdscrobble") + (auto-start? + (boolean #t) + "Should mpdscrobble be started automatically?")) + +(define (add-mpdscrobble-packages config) + (list (home-mpdscrobble-configuration-package config))) + +(define (home-mpdscrobble-shepherd-service config) + (list + (shepherd-service + (documentation "Scrobble songs to last.fm and/or maloja") + (provision '(mpdscrobble)) + (requirement '(mpd)) + (auto-start? (home-mpdscrobble-configuration-auto-start? config)) + (start + #~(make-forkexec-constructor + (list #$(file-append (home-mpdscrobble-configuration-package config) "/bin/mpdscrobble")) + #:log-file (format #f "~a/.local/var/log/mpdscrobble.log" (getenv "HOME")))) + (stop #~(make-kill-destructor)) + (respawn? #t) + (respawn-delay 1) + (respawn-limit 60)))) + +(define home-mpdscrobble-service-type + (service-type + (name 'home-mpdscrobble) + (extensions + (list (service-extension + home-profile-service-type + add-mpdscrobble-packages) + (service-extension + home-shepherd-service-type + home-mpdscrobble-shepherd-service))) + (compose identity) + (default-value (home-mpdscrobble-configuration)) + (description "Install and configure mpdscrobble."))) diff --git a/oni/packages/mpd.scm b/oni/packages/mpd.scm index cb1cac1..a2c1e49 100644 --- a/oni/packages/mpd.scm +++ b/oni/packages/mpd.scm @@ -6,8 +6,14 @@ #:use-module (gnu packages mpd) #:use-module (gnu packages gnome) #:use-module (guix build-system gnu) + #:use-module (guix build-system python) + #:use-module (guix build-system pyproject) + #:use-module (guix download) #:use-module (guix git-download) - #:use-module (guix packages)) + #:use-module (guix packages) + #:use-module (gnu packages python-web) + #:use-module (gnu packages music) + #:use-module (gnu packages check)) (define-public mpd-notify (let ((commit "1bf3786878eb499b6a0c56e47ba3f3e07cd81182") @@ -76,3 +82,25 @@ (synopsis "A simple script that populates the MPD playlist with all of my albums in random order.") (description "Creates a new playlist in MPD with all of the albums in my database and shuffles them by album.") (license license:gpl3+)))) + +(define-public mpdscrobble + (let ((commit "c4314b026183a2b38673db898deb98f24dfb3901") + (revision "0")) + (package + (name "python-mpdscrobble") + (version (git-version "0.3.3" revision commit)) + (source + (origin + (method git-fetch) + (uri (git-reference + (url "https://github.com/dbeley/mpdscrobble") + (commit commit))) + (sha256 + (base32 "1kixss0s182hhl52qrr646zswx0c81si6jxz08jc8sal8y1rm4ql")))) + (build-system pyproject-build-system) + (native-inputs (list python-pytest)) + (propagated-inputs (list python-httpx python-pylast python-mpd2)) + (home-page "https://github.com/dbeley/mpdscrobble") + (synopsis "A simple Last.fm scrobbler for MPD.") + (description "This package provides a simple Last.fm scrobbler for MPD.") + (license license:expat))))