Skip to content

Commit 1fe001e

Browse files
authored
Add script for generating tidal oauth2 credentials #425 (#426)
1 parent 40023b6 commit 1fe001e

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,9 @@ RUN chmod +x /app/bin/*.sh
233233
COPY app/bin/get-tidal-credentials.py /app/bin/
234234
RUN chmod +x /app/bin/get-tidal-credentials.py
235235

236+
COPY app/bin/get-tidal-credentials-oauth2.py /app/bin/
236237
COPY app/bin/get-tidal-credentials-pkce.py /app/bin/
238+
RUN chmod u+x /app/bin/get-tidal-credentials-oauth2.py
237239
RUN chmod u+x /app/bin/get-tidal-credentials-pkce.py
238240

239241
COPY README.md /app/doc
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/python3
2+
3+
# Copyright (C) 2023 Giovanni Fulco
4+
#
5+
# This program is free software: you can redistribute it and/or modify
6+
# it under the terms of the GNU General Public License as published by
7+
# the Free Software Foundation, either version 3 of the License, or
8+
# (at your option) any later version.
9+
#
10+
# This program is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
# GNU General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU General Public License
16+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
18+
import tidalapi
19+
import json
20+
import os
21+
from pathlib import Path
22+
from datetime import datetime
23+
24+
tidal_plugin_name : str = "tidal"
25+
26+
27+
def print_setting(name : str, value : str):
28+
print(f"{name}={value}")
29+
30+
31+
tmp_directory : str = "generated"
32+
file_path : str = os.path.join("/tmp", tmp_directory)
33+
if not os.path.exists(file_path):
34+
os.makedirs(file_path)
35+
36+
file_name = f"{file_path}/credentials.json"
37+
38+
session = tidalapi.Session()
39+
# Will run until you visit the printed url and link your account
40+
session.login_oauth_simple()
41+
42+
token_type = session.token_type
43+
access_token = session.access_token
44+
refresh_token = session.refresh_token
45+
expiry_time = session.expiry_time
46+
47+
storable_expiry_time = datetime.timestamp(expiry_time)
48+
49+
cred_dict: dict = dict()
50+
cred_dict["authentication_type"] = "oauth2"
51+
cred_dict["tokentype"] = "Bearer"
52+
cred_dict["accesstoken"] = access_token
53+
cred_dict["refreshtoken"] = refresh_token
54+
cred_dict["expirytimetimestampstr"] = storable_expiry_time
55+
56+
print(json.dumps(cred_dict, indent=4, sort_keys=True))
57+
58+
print(f"Writing credentials to file [{file_name}] ...")
59+
with open(file_name, 'w') as wcf:
60+
json.dump(cred_dict, wcf, indent = 4)
61+
print(f"Credentials written to file [{file_name}].")

doc/change-history.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

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

0 commit comments

Comments
 (0)