Giter VIP home page Giter VIP logo

mpd-subsonic-scrobbler's Introduction

mpd-subsonic-scrobbler

This is a very simple Subsonic scrobbler for MPD.
It is not a LAST.FM or libre.fm scrobbler.
This scrobbler allows mpd to notify a subsonic server when it has played a song which has been server from that subsonic server. The subsonic server might, if configured, scrobble the song to LAST.FM, libre.fm, etc.
It might be useful when using the Subsonic plugin for Upmpdcli. See the discussion here.

Support

ko-fi
Please see the Goal.
Please note that support goal is limited to cover running costs for subscriptions to music services.

Important notice

Initially I used this docker repo. I then noticed that it was named differently from the github repo.
So I created a new docker hub repo here and updated the documentation.
The old docker hub repo will not receive updates of course. Please correct your docker compose/run so that they reference the correct image name.
Sorry for the inconvenience

Links

Related projects

PROJECT Git Repo(s)
Music Player Daemon On GitHub
Upmpdcli Framagit (Mirror). My Fork (Mirror)
mpd-alsa-docker GitHub
upmpdcli-docker GitHub
subsonic-connector GitHub
python-mpd2 GitHub

Among those, mpd-alsa-docker and upmpdcli-docker provide a method for deploying mpd and upmpdcli using docker.

Repositories for this project

Repo URL
Source code GitHub
Docker images Docker Hub

Available Archs on Docker Hub

  • linux/amd64
  • linux/arm/v7
  • linux/arm/v5
  • linux/arm64/v8

Usage

Volumes

VOLUME DESCRIPTION
/config Suggested location for additional configuration files

Enviroment Variables

VARIABLE DESCRIPTION DEFAULT
MPD_FRIENDLY_NAME Friendly name of the mpd instance
MPD_HOST MPD hostname localhost
MPD_PORT MPD port 6600
SUBSONIC_FRIENDLY_NAME Friendly name of the subsonic server
SUBSONIC_PARAMETERS_FILE Separate config file for subsonic parameters
SUBSONIC_BASE_URL Subsonic Server URL, including http or https
SUBSONIC_PORT Subsonic Server Port
SUBSONIC_USER Subsonic Username
SUBSONIC_PASSWORD Subsonic password
SUBSONIC_LEGACYAUTH Legacy authentication, required to true for lms, defaults to false
SUBSONIC_CREDENTIALS Reference to a file with credentials, alternative to specifying SUBSONIC_USER and SUBSONIC_PASSWORD
SUBSONIC_UPMPDCLI_BASE_URL If set, only this upmpdcli server will be allowed (base url)
SUBSONIC_UPMPDCLI_PORT If set, only this upmpdcli server will be allowed (port)
MIN_COVERAGE Percent of the song that needs to be played 50
ENOUGH_PLAYBACK_SEC Minimum playback time needed for a scrobble, regardless of coverage, defaults to 240
SLEEP_TIME Interval between a coverage check and the next, in millisec 1000
REDACT_CREDENTIALS If set to 1, credentials are not displayed on startup
MAX_SUBSONIC_SERVERS Max number of SubSonic servers, defaults to 10
MAX_MPD_INSTANCES Max number of MPD instances, defaults to 10
MPD_CLIENT_TIMEOUT_SEC Mpd client timeout, defaults to 0.05 (one value across all mpd instance)
ITERATION_DURATION_THRESHOLD_PERCENT If total handle_playback elapsed time is greater than this percentage of SLEEP_TIME, a warning is displayed on the standard output. In this case, you should increase SLEEP_TIME, reduce MPD_CLIENT_TIMEOUT_SEC, or increase this threshold
MPD_IMPOSED_SLEEP_ITERATION_COUNT Number of iteration an instance of mpd must sleep when it appears to not be accessible, defaults to 30
VERBOSE Verbose output, valid values are 1 and 0 0

The subsonic configuration parameters are required: either specificy the individual variables, or specify a SUBSONIC_PARAMETERS to indicate the file which will contain the parameters. The file must be accessible to the container. You can use the /config volume and put a file named, e.g. ".subsonic.env" there.
All the MPD_* (unless specified) and SUBSONIC_* variables can be suffixed with _1, _2, _3 etc in order to configure multiple mpd instances and multiple SubSonic servers.
Inside a single config file, even if it refer to an index > 0, the variable names must be specified without the index.

Example configurations

The following compose file creates a subsonic scrobbler for mpd-d10 (as it operates on a Topping D10 DAC) and mpd-d200 (as it operates on a Yulong D200 DAC), which are instances of mpd-alsa-docker running on the same host and specifically on the network mpd.
Subsonic config is read from a separate file.

---
version: "3"

networks:
  mpd:
    external: true

services:
  scrobbler:
    image: giof71/mpd-subsonic-scrobbler:latest
    container_name: subsonic-scrobbler-d10
    networks:
      - mpd
    environment:
      - MPD_HOST=mpd-d10
      - MPD_PORT=6600
      - MPD_HOST_1=mpd-d200
      - MPD_PORT_1=6600
      - SUBSONIC_PARAMETERS_FILE=/config/my-navidrome.env
      - SUBSONIC_PARAMETERS_FILE_1=/config/navidrome-demo.env
      - VERBOSE=0
    volumes:
      - ./my-navidrome.env:/config/my-navidrome.env:ro
      - ./navidrome-demo.env:/config/navidrome-demo.env:ro
    restart: unless-stopped

Same situation, without the separate file:

---
version: "3"

networks:
  mpd:
    external: true

services:
  scrobbler:
    image: giof71/mpd-subsonic-scrobbler:latest
    container_name: subsonic-scrobbler-d10
    networks:
      - mpd
    environment:
      - MPD_HOST=mpd-d10
      - MPD_PORT=6600
      - MPD_HOST_1=mpd-d200
      - MPD_PORT_1=6600
      - SUBSONIC_BASE_URL=${MY_NAVIDROME_BASE_URL}
      - SUBSONIC_PORT=${MY_NAVIDROME_PORT}
      - SUBSONIC_USER=${MY_NAVIDROME_USER}
      - SUBSONIC_PASSWORD=${MY_NAVIDROME_PASSWORD}
      - SUBSONIC_BASE_URL_1=${NAVIDROME_DEMO_BASE_URL}
      - SUBSONIC_PORT_1=${NAVIDROME_DEMO_PORT}
      - SUBSONIC_USER_1=${NAVIDROME_DEMO_USER}
      - SUBSONIC_PASSWORD_1=${NAVIDROME_DEMO_PASSWORD}
      - VERBOSE=0
    restart: unless-stopped

In this case, the configuration parameters are read from the .env file.
In order to avoid issues with password, which might contain special characters, it is better to not place such password on the compose file, and leverage the .env file instead.

Releases

Release 0.5.3

  • Build using setuptools
  • Extracted functions (reduce function length)
  • Misc cleanup

Release 0.5.2

  • Correct version in source code
  • Improved logging

Release 0.5.1

  • Reduce cpu usage (see #53)

Release 0.5.0 (2024-04-19)

  • Bug: fixed repeated scrobbles
  • Code style fixed (flake8)
  • Bump subsonic-connector to 0.3.4
  • Bump py-sonic to 1.0.1

Release 0.4.0 (2023-11-13)

  • Effectively use mpd timeout parameter and handle timeout errors
  • Handle non-accessible mpd instances
  • Slightly improved code readability
  • Dump legacy authentication parameter

Release 0.3.6 (2023-11-11)

  • Handle unavailable servers gracefully (see issue #48)

Release 0.3.5 (2023-11-11)

  • Simplified mpd reconnection code (see issue #46)

Release 0.3.4 (2023-11-11)

  • Compatibility with latest subsonic-connector, for legacy authentication (see issue #44)

Release 0.3.3 (2023-11-11)

  • Recreate mpd connection in case of failure (see issue #39)

Release 0.3.2 (2023-11-06)

  • Check song id belongs to current server (see issue #39)

Release 0.3.1 (2023-11-04)

  • Display upmpdcli configuration parameters (see issue #37)

Release 0.3.0 (2023-11-04)

  • Allow upmpdcli server restrictions (see issue #35)

Release 0.2.2 (2023-10-28)

  • Handle mpd disconnections (see issue #32)

Release 0.2.1 (2023-10-28)

  • Support for upmpdcli intermediate urls

Release 0.2.0 (2023-05-25)

  • Support for multiple mpd instances

Release 0.1.2 (2023-05-18)

  • Support for multiple subsonic servers
  • Code refactor and cleanup
  • Remove need to set PYTHONUNBUFFERED=1 in compose file

Release 0.1.1 (2023-05-13)

  • Mostly documentation changes

Release 0.1.0 (Initial Release, 2023-05-12)

  • First working release

mpd-subsonic-scrobbler's People

Contributors

giof71 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

mpd-subsonic-scrobbler's Issues

[Feature] Allow upmpdcli server restriction

Add new variables

SUBSONIC_UPMPDCLI_BASE_URL
SUBSONIC_UPMPDCLI_PORT

If set, these will determine if a upmpdcli server will be considered as a valid proxy for the subsonic configuration.

Everything seems fine but no scrobble

Hi!

Thank you for you hard work!

I'm pretty sure I have setup everything correctly. I can run the program and see this output:

subsonic-scrobbler  | mpd-subsonic-scrobbler version 0.2.0
subsonic-scrobbler  | SLEEP_TIME: [1000] msec
subsonic-scrobbler  | MIN_COVERAGE: [10%]
subsonic-scrobbler  | ENOUGH_PLAYBACK_SEC: [10 sec]
subsonic-scrobbler  | VERBOSE: [True]
subsonic-scrobbler  | server[0].friendly_name=[navidrome]
subsonic-scrobbler  | server[0].base_url=[http://192.168.191.61]
subsonic-scrobbler  | server[0].port=[4533]
subsonic-scrobbler  | server[0].user=[****]
subsonic-scrobbler  | server[0].password=[****]
subsonic-scrobbler  | mpd[0].friendly_name=[mpd]
subsonic-scrobbler  | mpd[0].host=[localhost]
subsonic-scrobbler  | mpd[0].port=[6600]
subsonic-scrobbler  | Current mpd state for index 0 [mpd] is [stop]
subsonic-scrobbler  | Current mpd state for index 0 [mpd] is [play]

But Navidrome doesn't update the "recently played" page with what I play via MPD, neither does it show mpd-subsonic-scrobbler in the list of players (not sure if it should). I would also imagine that the scrobbling event should show up in the verbose output when it happens. The only events that seem to be registered are play / pause and stop. When I stop it says

subsonic-scrobbler  | Remove some data from context for index 0 ...
subsonic-scrobbler  | Data removal for index 0 complete.

I have tried to change the subsonic base url to http://localhost but to no avail.

Here is my docker-compose:

---
version: "3"

services:
  scrobbler:
    image: giof71/mpd-subsonic-scrobbler:latest
    container_name: subsonic-scrobbler
    network_mode: "host"
    environment:
      - MPD_FRIENDLY_NAME=mpd
      - MPD_HOST=localhost
      - MPD_PORT=6600
      - SUBSONIC_FRIENDLY_NAME=navidrome
      - SUBSONIC_BASE_URL=http://192.168.191.61
      - SUBSONIC_PORT=4533
      - SUBSONIC_USER=****
      - SUBSONIC_PASSWORD=****
      - MIN_COVERAGE=10
      - ENOUGH_PLAYBACK_SEC=10
      - VERBOSE=1
      - REDACT_CREDENTIALS=0
    restart: unless-stopped

Am I missing something?

[Improvement] Reduce cpu usage

CPU usage is not excessively high, but it is not as low as I would like it to be, especially when connecting to many players, as some might (and will be) offline.
Maybe we can put let the algorithm skip a few iterations when a device appears to be offline. That should reduce the cpu load, we'll see by how much.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.