Skip to content

Commit

Permalink
Add script for generating tidal oauth2 credentials #425 (#426)
Browse files Browse the repository at this point in the history
  • Loading branch information
GioF71 authored Jul 12, 2024
1 parent 40023b6 commit 1fe001e
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,9 @@ RUN chmod +x /app/bin/*.sh
COPY app/bin/get-tidal-credentials.py /app/bin/
RUN chmod +x /app/bin/get-tidal-credentials.py

COPY app/bin/get-tidal-credentials-oauth2.py /app/bin/
COPY app/bin/get-tidal-credentials-pkce.py /app/bin/
RUN chmod u+x /app/bin/get-tidal-credentials-oauth2.py
RUN chmod u+x /app/bin/get-tidal-credentials-pkce.py

COPY README.md /app/doc
Expand Down
61 changes: 61 additions & 0 deletions app/bin/get-tidal-credentials-oauth2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/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
import json
import os
from pathlib import Path
from datetime import datetime

tidal_plugin_name : str = "tidal"


def print_setting(name : str, value : str):
print(f"{name}={value}")


tmp_directory : str = "generated"
file_path : str = os.path.join("/tmp", tmp_directory)
if not os.path.exists(file_path):
os.makedirs(file_path)

file_name = f"{file_path}/credentials.json"

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
expiry_time = session.expiry_time

storable_expiry_time = datetime.timestamp(expiry_time)

cred_dict: dict = dict()
cred_dict["authentication_type"] = "oauth2"
cred_dict["tokentype"] = "Bearer"
cred_dict["accesstoken"] = access_token
cred_dict["refreshtoken"] = refresh_token
cred_dict["expirytimetimestampstr"] = storable_expiry_time

print(json.dumps(cred_dict, indent=4, sort_keys=True))

print(f"Writing credentials to file [{file_name}] ...")
with open(file_name, 'w') as wcf:
json.dump(cred_dict, wcf, indent = 4)
print(f"Credentials written to file [{file_name}].")
1 change: 1 addition & 0 deletions doc/change-history.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

Change Date|Major Changes
---|---
2024-07-12|Add script for generating tidal oauth2 credentials (see issue [#425](https://github.com/GioF71/upmpdcli-docker/issues/425))
2024-06-13|Automatically set ohproductroom to friendlyname if not explicitly set
2024-06-13|Add support for MPD password and timeout
2024-05-17|Support title for Qobuz (see issue [#412](https://github.com/GioF71/upmpdcli-docker/issues/412))
Expand Down

0 comments on commit 1fe001e

Please sign in to comment.