From 8e724312fc9831f74f021e57cfc0fb6b72e54408 Mon Sep 17 00:00:00 2001 From: Giovanni Fulco Date: Sat, 16 Sep 2023 17:07:34 +0200 Subject: [PATCH] 269 maintenance support for upcoming new tidal plugin (#270) * Support for new tidal plugin * [Maintenance] Support for upcoming new Tidal Plugin #269 --- Dockerfile | 12 ++++ README.md | 55 ++++++++++++++-- app/bin/get-tidal-credentials.py | 42 +++++++++++++ app/bin/run-upmpdcli.sh | 53 ++++++++++++++++ app/conf/upmpdcli.conf | 7 +++ app/install/setup.sh | 2 +- doc/example-configurations.md | 104 ++++++++++++++++++++----------- 7 files changed, 231 insertions(+), 44 deletions(-) create mode 100755 app/bin/get-tidal-credentials.py diff --git a/Dockerfile b/Dockerfile index d1936f3..4b167d1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -151,6 +151,15 @@ ENV SUBSONIC_WHITELIST_CODECS "" ENV SUBSONIC_DOWNLOAD_PLUGIN "" ENV SUBSONIC_PLUGIN_BRANCH "" +ENV TIDAL_ENABLE "" +ENV TIDAL_TOKEN_TYPE "" +ENV TIDAL_ACCESS_TOKEN "" +ENV TIDAL_REFRESH_TOKEN "" +ENV TIDAL_EXPIRY_TIME "" +ENV TIDAL_AUDIO_QUALITY "" +ENV TIDAL_DOWNLOAD_PLUGIN "" +ENV TIDAL_PLUGIN_BRANCH "" + ENV PUID "" ENV PGID "" @@ -182,6 +191,9 @@ COPY app/bin/get-value.sh /app/bin/ COPY app/bin/config-builder.sh /app/bin/ RUN chmod u+x /app/bin/*.sh +COPY app/bin/get-tidal-credentials.py /app/bin/ +RUN chmod u+x /app/bin/get-tidal-credentials.py + COPY README.md /app/doc WORKDIR /app/bin diff --git a/README.md b/README.md index ddc0b65..a9708dc 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # upmpdcli-docker A Docker image for upmpdcli. -Now with support for custom radios, [radio-browser.info](https://www.radio-browser.info/), and [subsonic servers](https://github.com/navidrome/navidrome/discussions/2324). +There is built-in support for custom radios, [radio-browser.info](https://www.radio-browser.info/), Tidal, Qobuz, and [subsonic servers](https://github.com/navidrome/navidrome/discussions/2324). A few screenshots for the subsonic plugin on [Kazoo](https://github.com/GioF71/upmpdcli-docker/tree/main/doc/screenshots/kazoo) and [Upplay](https://github.com/GioF71/upmpdcli-docker/tree/main/doc/screenshots/upplay) are now available. ## Latest Build @@ -17,12 +17,21 @@ Current version is `1.8.1`. ## News -### Native Tidal support dropped +### Tidal support is back -Upmpdcli does not support Tidal natively anymore. +We have a new, updated Tidal plugin for upmpdcli. I have contributed it to upmpdcli. See the git repository forks [here](https://framagit.org/medoc92/upmpdcli) and [here](https://codeberg.org/GioF71/upmpdcli). +The plugin is built around [python-tidal](https://github.com/tamland/python-tidal). +Building this plugin would not have been possible without this library, so a big thank you goes to [its author](https://github.com/tamland). +Remember, this is not, in any way, supported by Tidal. It might stop working at any moment. Consider alternatives as BubbleUpnp, mConnect or similar software which are, to my knowledge, officially supported by Tidal. +About the configuration, this time there is no need to go hunting for a valid access token: again, thanks to the advancements in the underlying library, you will be able to generate your own set of credentials from a valid username/password combination. +Of course, a premium account of Tidal is strictly required. + +~~### Native Tidal support dropped~~ + +~~Upmpdcli does not support Tidal natively anymore. I have therefore removed the relevant environment variables and portions of the scripts which build the configuration file based on the mentioned environment variables. Of course, you can still stream Tidal to a upnp player created using upmpdcli using an application like BubbleUpnp, mConnect/mConnect Lite, etc. -On a ARM-based single board computer like the Raspberry Pi and many others (example: an Asus Tinkerboard), you can still run (until Tidal does not stop this somehow) Tidal Connect, see [this](https://github.com/GioF71/tidal-connect) and [this other](https://github.com/TonyTromp/tidal-connect-docker) repository, and then stream direcly from the Tidal official applications. +On a ARM-based single board computer like the Raspberry Pi and many others (example: an Asus Tinkerboard), you can still run (until Tidal does not stop this somehow) Tidal Connect, see [this](https://github.com/GioF71/tidal-connect) and [this other](https://github.com/TonyTromp/tidal-connect-docker) repository, and then stream direcly from the Tidal official applications.~~ ### BBC @@ -35,7 +44,7 @@ Since release 2023-07-05, support the upmpdcli [`Upradios radio list`](https://w ### Subsonic Since release 2023-04-19, support for the [`Subsonic plugin`](https://www.lesbonscomptes.com/upmpdcli/pages/upmpdcli-manual.html#UPMPDCLI-MS-SUBSONIC) has been introduced. -I am now a contributor to upmpdcli for this plugin. See the git repository [here](https://framagit.org/medoc92/upmpdcli). +I am now a contributor to upmpdcli for this plugin. See the git repository forks [here](https://framagit.org/medoc92/upmpdcli) and [here](https://codeberg.org/GioF71/upmpdcli). The plugin uses my [subsonic-connector](https://github.com/GioF71/subsonic-connector) library which in turn is built around [py-sonic](https://github.com/crustymonkey/py-sonic). Everything has been developed and tested against [Navidrome](https://www.navidrome.org/) but should work with other servers hopefully. See [this](https://github.com/navidrome/navidrome/discussions/2324) discussion on the Navidrome repo for updates and further information. @@ -209,6 +218,14 @@ SUBSONIC_PLUGIN_BRANCH|If `SUBSONIC_DOWNLOAD_PLUGIN`, the branch indicated by th PLG_MICRO_HTTP_HOST|IP for the qobuz local HTTP service. PLG_MICRO_HTTP_PORT|Port for the qobuz local HTTP service. MEDIA_SERVER_FRIENDLY_NAME|Friendly name for the Media Server +TIDAL_ENABLE|Set to `yes` to enable Tidal support, defaults to `no` +TIDAL_TOKEN_TYPE|Tidal token type +TIDAL_ACCESS_TOKEN|Tidal access token +TIDAL_REFRESH_TOKEN|Tidal refresh token +TIDAL_EXPIRY_TIME|Tidal expiry time +TIDAL_QUALITY|Possible values are `LOW` (mp3@96k), `HIGH` (mp3@320k), `LOSSLESS` (flac@44.1kHz), `HI_RES` (I believe it's MQA), `HI_RES_LOSSLESS` (flac@hires), defaults to `LOSSLESS` +TIDAL_DOWNLOAD_PLUGIN|If set to `YES`, the updated plugin is downloaded from the upstream repo +TIDAL_PLUGIN_BRANCH|If `TIDAL_DOWNLOAD_PLUGIN`, the branch indicated by this variable will be used. Must be specified if enabling `TIDAL_DOWNLOAD_PLUGIN`. Suggested branch name is `latest-tidal` QOBUZ_ENABLE|Set to `yes` to enable Qobuz support, defaults to `no` QOBUZ_USERNAME|Your Qobuz account username QOBUZ_PASSWORD|Your Qobuz account password @@ -253,6 +270,33 @@ preferScript = 1 Only the `url` line is mandatory. Refer to the file [radiolist.conf](https://github.com/GioF71/upmpdcli-docker/blob/main/app/reference/radiolist.conf) from the git repository for further details. +### Obtain Tidal credentials + +In order to obtain your set of tidal credentials, execute the following command: + +```text +docker run --rm -it --entrypoint /app/bin/get-tidal-credentials.py giof71/upmpdcli +``` + +You will be presented with an output similar to the following: + +```text +Visit https://link.tidal.com/XXXXX to log in, the code will expire in 300 seconds +``` + +Open the link in the browser, login to Tidal and authorize the application. Once that is done, you will be greeted with an output like the following: + +```text +Environment variables: +TIDAL_TOKEN_TYPE=Bearer +TIDAL_ACCESS_TOKEN=your-tidal-token +TIDAL_REFRESH_TOKEN=your-refresh-token +TIDAL_EXPIRY_TIME=1694616998.732007 +``` + +The tokens will be very long strings. Those values must be used in your docker-compose file, or, even better, through the separate `.env` file. +Never share the tokens on the internet (and also on public git repositories). + ## Usage examples A few usage examples are available [here](https://github.com/GioF71/upmpdcli-docker/blob/main/doc/example-configurations.md). @@ -270,6 +314,7 @@ Just be careful to use the tag you have built. Change Date|Major Changes ---|--- +2023-09-16|Support for upcoming new Tidal Plugin (see issue [#269](https://github.com/GioF71/upmpdcli-docker/issues/269)) 2023-09-13|Add example subsonic configuration (see issue [#266](https://github.com/GioF71/upmpdcli-docker/issues/266)) 2023-08-20|Add `renderer` tag image (see issue [#252](https://github.com/GioF71/upmpdcli-docker/issues/252)) 2023-08-20|Add support for `ENABLE_AUTO_UPNPIFACE` (see issue [#248](https://github.com/GioF71/upmpdcli-docker/issues/248)) diff --git a/app/bin/get-tidal-credentials.py b/app/bin/get-tidal-credentials.py new file mode 100755 index 0000000..cc56939 --- /dev/null +++ b/app/bin/get-tidal-credentials.py @@ -0,0 +1,42 @@ +#!/usr/bin/python3 + +# Copyright (C) 2023 Giovanni Fulco +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +import tidalapi +from datetime import datetime + +tidal_plugin_name : str = "tidal" + +def print_setting(name : str, value : str): + print(f"{name}={value}") + +session = tidalapi.Session() +# Will run until you visit the printed url and link your account +session.login_oauth_simple() + +token_type = session.token_type +access_token = session.access_token +refresh_token = session.refresh_token # Not needed if you don't care about refreshing +expiry_time = session.expiry_time + +storable_expiry_time = datetime.timestamp(expiry_time) + +print("Environment variables:") +print_setting("TIDAL_TOKEN_TYPE", token_type) +print_setting("TIDAL_ACCESS_TOKEN", access_token) +print_setting("TIDAL_REFRESH_TOKEN", refresh_token) +print_setting("TIDAL_EXPIRY_TIME", storable_expiry_time) + diff --git a/app/bin/run-upmpdcli.sh b/app/bin/run-upmpdcli.sh index b0c8f9c..44994bf 100644 --- a/app/bin/run-upmpdcli.sh +++ b/app/bin/run-upmpdcli.sh @@ -25,6 +25,27 @@ if [[ "${SUBSONIC_DOWNLOAD_PLUGIN^^}" == "YES" ]]; then cd /app/bin fi +if [[ "${TIDAL_DOWNLOAD_PLUGIN^^}" == "YES" ]]; then + echo "Downloading updated tidal plugin" + if [[ -n "${TIDAL_PLUGIN_BRANCH}" ]]; then + echo " using branch [$TIDAL_PLUGIN_BRANCH]" + cd /app + mkdir -p src + cd /app/src + git clone https://framagit.org/GioF71/upmpdcli.git --branch ${TIDAL_PLUGIN_BRANCH} + echo " copying updated files ..." + cp upmpdcli/src/mediaserver/cdplugins/tidal/* /usr/share/upmpdcli/cdplugins/tidal/ + echo " copied, removing repo ..." + rm -Rf upmpdcli + echo " repo removed." + cd .. + rm -Rf src + echo " src directory removed." + fi + # return to the path + cd /app/bin +fi + DEFAULT_UID=1000 DEFAULT_GID=1000 @@ -229,6 +250,7 @@ if [[ "${UPRCL_ENABLE^^}" == "YES" || "${RADIOS_ENABLE^^}" == "YES" || "${BBC_ENABLE^^}" == "YES" || "${SUBSONIC_ENABLE^^}" == "YES" || + "${TIDAL_ENABLE^^}" == "YES" || "${HRA_ENABLE^^}" == "YES" || "${DEEZER_ENABLE^^}" == "YES" || "${HRA_ENABLE^^}" == "YES" || @@ -329,6 +351,37 @@ if [ "${SUBSONIC_ENABLE^^}" == "YES" ]; then fi fi +echo "TIDAL_ENABLE=[$TIDAL_ENABLE]" +if [ "${TIDAL_ENABLE^^}" == "YES" ]; then + echo "Enabling new Tidal, processing settings"; + TIDAL_ENABLE=YES + sed -i 's/\#tidaluser/tidaluser/g' $CONFIG_FILE + echo "TIDAL_AUTOSTART=[$TIDAL_AUTOSTART]" + if [[ -z "${TIDAL_AUTOSTART^^}" || "${TIDAL_AUTOSTART}" == "1" || "${SUBSONIC_AUTOSTART^^}" == "YES" ]]; then + TIDAL_AUTOSTART=1 + sed -i 's/\#tidalautostart/tidalautostart/g' $CONFIG_FILE; + set_parameter $CONFIG_FILE TIDAL_AUTOSTART "$TIDAL_AUTOSTART" tidalautostart + fi + echo "Setting Token Type [$TIDAL_TOKEN_TYPE]" + sed -i 's/\#tidaltokentype/tidaltokentype/g' $CONFIG_FILE + sed -i 's,TIDAL_TOKEN_TYPE,'"$TIDAL_TOKEN_TYPE"',g' $CONFIG_FILE + echo "Setting Access Token [$TIDAL_ACCESS_TOKEN]" + sed -i 's/\#tidalaccesstoken/tidalaccesstoken/g' $CONFIG_FILE + sed -i 's,TIDAL_ACCESS_TOKEN,'"$TIDAL_ACCESS_TOKEN"',g' $CONFIG_FILE + echo "Setting Access Token [$TIDAL_REFRESH_TOKEN]" + sed -i 's/\#tidalrefreshtoken/tidalrefreshtoken/g' $CONFIG_FILE + sed -i 's,TIDAL_REFRESH_TOKEN,'"$TIDAL_REFRESH_TOKEN"',g' $CONFIG_FILE + echo "Setting Token Expiry Time [$TIDAL_EXPIRY_TIME]" + sed -i 's/\#tidalexpirytime/tidalexpirytime/g' $CONFIG_FILE + sed -i 's,TIDAL_EXPIRY_TIME,'"$TIDAL_EXPIRY_TIME"',g' $CONFIG_FILE + if [[ -z "$TIDAL_AUDIO_QUALITY" ]]; then + TIDAL_AUDIO_QUALITY="LOSSLESS" + fi + echo "Setting Audio Quality [$TIDAL_AUDIO_QUALITY]" + sed -i 's/\#tidalaudioquality/tidalaudioquality/g' $CONFIG_FILE + sed -i 's,TIDAL_AUDIO_QUALITY,'"$TIDAL_AUDIO_QUALITY"',g' $CONFIG_FILE +fi + echo "Qobuz Enable [$QOBUZ_ENABLE]" if [ "${QOBUZ_ENABLE^^}" == "YES" ]; then echo "Processing Qobuz settings"; diff --git a/app/conf/upmpdcli.conf b/app/conf/upmpdcli.conf index 08b4507..e0b3365 100644 --- a/app/conf/upmpdcli.conf +++ b/app/conf/upmpdcli.conf @@ -104,3 +104,10 @@ upradiostitle = Upmpdcli Radio List #subsonicappendyeartoalbum = SUBSONIC_APPEND_YEAR_TO_ALBUM #subsonicappendcodecstoalbum = SUBSONIC_APPEND_CODECS_TO_ALBUM #subsonicwhitelistcodecs = SUBSONIC_WHITELIST_CODECS +#tidaluser = tidal +#tidalautostart = TIDAL_AUTOSTART +#tidaltokentype = TIDAL_TOKEN_TYPE +#tidalaccesstoken = TIDAL_ACCESS_TOKEN +#tidalrefreshtoken = TIDAL_REFRESH_TOKEN +#tidalexpirytime = TIDAL_EXPIRY_TIME +#tidalaudioquality = TIDAL_AUDIO_QUALITY diff --git a/app/install/setup.sh b/app/install/setup.sh index 0c01140..b8f98b6 100644 --- a/app/install/setup.sh +++ b/app/install/setup.sh @@ -19,7 +19,7 @@ if [ "$BUILD_MODE" = "full" ]; then if [ $add_switch -eq 1 ]; then pip_upgrade="$pip_upgrade --break-system-packages" fi - python_packages=(pyradios py-sonic subsonic-connector==0.1.17 mutagen) + python_packages=(pyradios py-sonic subsonic-connector==0.1.17 mutagen tidalapi==0.7.3) for pkg in "${python_packages[@]}" do echo "Installing ${pkg} with add_switch [$add_switch]..." diff --git a/doc/example-configurations.md b/doc/example-configurations.md index 1115d47..3dc824c 100644 --- a/doc/example-configurations.md +++ b/doc/example-configurations.md @@ -40,13 +40,13 @@ version: "3" services: upmpdcli: - image: giof71/upmpdcli + image: giof71/upmpdcli:renderer container_name: upmpdcli network_mode: host environment: - PUID=1000 - PGID=1000 - - FRIENDLY_NAME=upmpd #optional + - FRIENDLY_NAME=upmpd volumes: - ./cache:/cache - ./log:/log @@ -85,7 +85,6 @@ services: - FRIENDLY_NAME=upmpd-library - UPRCL_ENABLE=yes - UPRCL_USER=upmpdcli-library - - UPRCL_HOSTPORT=192.168.1.101:9090 - UPRCL_AUTOSTART=1 volumes: - ./cache:/cache @@ -115,14 +114,10 @@ services: container_name: upmpdcli-radio network_mode: host environment: - - PUID=1000 - - PGID=1000 - - PORT_OFFSET=0 - RENDERER_MODE=NONE - FRIENDLY_NAME=upmpd-radio - UPRCL_ENABLE=yes - UPRCL_USER=upmpdcli-library - - UPRCL_HOSTPORT=192.168.1.105:9090 - UPRCL_AUTOSTART=1 - LOG_ENABLE=yes - LOG_LEVEL=2 @@ -137,69 +132,102 @@ services: This configuration disables the renderers (`RENDERER_MODE=NONE`), but this is not mandatory. When you disable renderers, you are essentially creating a pure upnp/dlna server. -### Streaming Services +### Subsonic Server -A simple upmpdcli instance for streaming Qobuz: +A simple upmpdcli instance for a Subsonic server: ```text --- version: "3" services: - upmpdcli-streaming-services: + upmpdcli: image: giof71/upmpdcli - container_name: upmpdcli-streaming-services + container_name: upmpdcli-subsonic network_mode: host environment: - - PUID=1000 - - PGID=1000 - RENDERER_MODE=NONE - - FRIENDLY_NAME=upmpd-streaming-services - - QOBUZ_ENABLE=yes + - FRIENDLY_NAME=upmpdcli-subsonic + - SUBSONIC_ENABLE=yes + - SUBSONIC_BASE_URL=${SUBSONIC_BASE_URL} + - SUBSONIC_PORT=${SUBSONIC_PORT} + - SUBSONIC_USER=${SUBSONIC_USER} + - SUBSONIC_PASSWORD=${SUBSONIC_PASSWORD} + - SUBSONIC_DOWNLOAD_PLUGIN=yes + - SUBSONIC_PLUGIN_BRANCH=subsonic-latest volumes: - - ./config/uprclconfdir:/uprcl/confdir - - ./config/credentials/qobuz.txt:/user/config/qobuz.txt:ro - labels: - - com.centurylinklabs.watchtower.enable=false + - ./cache:/cache restart: unless-stopped ``` -The `qobuz.txt` file should resemble the following: +The configuration assumes the credentials to be stored in the `.env` file. + +### Streaming Services + +#### Tidal + +A simple upmpdcli instance for streaming Tidal: ```text -QOBUZ_USERNAME=qobuz-username -QOBUZ_PASSWORD=qobuz-password -QOBUZ_FORMAT_ID=27 +--- +version: "3" + +services: + upmpdcli: + image: giof71/upmpdcli:latest + container_name: upmpdcli-tidal + network_mode: host + environment: + - RENDERER_MODE=NONE + - FRIENDLY_NAME=Tidal (upmpdcli) + - TIDAL_ENABLE=yes + - TIDAL_TOKEN_TYPE=${TIDAL_TOKEN_TYPE} + - TIDAL_ACCESS_TOKEN=${TIDAL_ACCESS_TOKEN} + - TIDAL_REFRESH_TOKEN=${TIDAL_REFRESH_TOKEN} + - TIDAL_EXPIRY_TIME=${TIDAL_EXPIRY_TIME} + - TIDAL_AUDIO_QUALITY=${TIDAL_AUDIO_QUALITY} + - TIDAL_DOWNLOAD_PLUGIN=yes + - TIDAL_PLUGIN_BRANCH=latest-tidal + volumes: + - ./cache:/cache + restart: unless-stopped ``` -Alternatively, those values can be passed as individual environment variables. +Remember to use a volume for the `/cache` volume, so that the collected playback statistics will be preserved even when the container is recreated. +Refer to the section "Obtain Tidal credentials" in the [README.md](https://github.com/GioF71/upmpdcli-docker/blob/main/README.md) for more information on how to retrieve your set of Tidal credentials. -### Subsonic +#### Qobuz -A simple upmpdcli instance for a Subsonic server: +A simple upmpdcli instance for streaming Qobuz: ```text --- version: "3" services: - upmpdcli: + upmpdcli-streaming-services: image: giof71/upmpdcli - container_name: upmpdcli-subsonic + container_name: upmpdcli-streaming-services network_mode: host environment: - RENDERER_MODE=NONE - - FRIENDLY_NAME=upmpdcli-subsonic - - SUBSONIC_ENABLE=yes - - SUBSONIC_BASE_URL=${SUBSONIC_BASE_URL} - - SUBSONIC_PORT=${SUBSONIC_PORT} - - SUBSONIC_USER=${SUBSONIC_USER} - - SUBSONIC_PASSWORD=${SUBSONIC_PASSWORD} - - SUBSONIC_DOWNLOAD_PLUGIN=yes - - SUBSONIC_PLUGIN_BRANCH=latest-subsonic + - FRIENDLY_NAME=upmpd-streaming-services + - QOBUZ_ENABLE=yes volumes: - - ./cache:/cache + - ./config/uprclconfdir:/uprcl/confdir + - ./config/credentials/qobuz.txt:/user/config/qobuz.txt:ro + labels: + - com.centurylinklabs.watchtower.enable=false restart: unless-stopped ``` -The configuration assumes the credentials to be stored in the `.env` file. +The `qobuz.txt` file should resemble the following: + +```text +QOBUZ_USERNAME=qobuz-username +QOBUZ_PASSWORD=qobuz-password +QOBUZ_FORMAT_ID=27 +``` + +Alternatively, those values can be passed as individual environment variables. +