Skip to content

Commit

Permalink
269 maintenance support for upcoming new tidal plugin (#270)
Browse files Browse the repository at this point in the history
* Support for new tidal plugin

* [Maintenance] Support for upcoming new Tidal Plugin #269
  • Loading branch information
GioF71 authored Sep 16, 2023
1 parent c7f62b2 commit 8e72431
Show file tree
Hide file tree
Showing 7 changed files with 231 additions and 44 deletions.
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""

Expand Down Expand Up @@ -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
Expand Down
55 changes: 50 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand All @@ -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.
Expand Down Expand Up @@ -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` ([email protected]), `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
Expand Down Expand Up @@ -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).
Expand All @@ -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))
Expand Down
42 changes: 42 additions & 0 deletions app/bin/get-tidal-credentials.py
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.

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)

53 changes: 53 additions & 0 deletions app/bin/run-upmpdcli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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" ||
Expand Down Expand Up @@ -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";
Expand Down
7 changes: 7 additions & 0 deletions app/conf/upmpdcli.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion app/install/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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]..."
Expand Down
Loading

0 comments on commit 8e72431

Please sign in to comment.