Skip to content

Commit 41d7e30

Browse files
committed
upload new version
1 parent 94139c9 commit 41d7e30

File tree

8 files changed

+120
-14
lines changed

8 files changed

+120
-14
lines changed

TIDALDL-PY/exe/tidal-dl.exe

5.92 MB
Binary file not shown.

TIDALDL-PY/tidal_dl/__init__.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@
2727
from tidal_dl.settings import Settings, TokenSettings, getLogPath
2828
from tidal_dl.tidal import TidalAPI
2929
from tidal_dl.util import API
30+
import tidal_dl.apiKey as apiKey
3031

3132
ssl._create_default_https_context = ssl._create_unverified_context
3233

3334
TOKEN = TokenSettings.read()
3435
CONF = Settings.read()
3536
LANG = initLang(CONF.language)
37+
API.apiKey = apiKey.getItem(CONF.apiKeyIndex)
3638

3739
logging.basicConfig(filename=getLogPath(),
3840
level=logging.INFO,
@@ -121,6 +123,21 @@ def setAccessToken():
121123
TokenSettings.save(TOKEN)
122124

123125

126+
def setAPIKey():
127+
global LANG
128+
item = apiKey.getItem(CONF.apiKeyIndex)
129+
Printf.info(f'Current APIKeys: {str(CONF.apiKeyIndex)} {item["platform"]}-{item["formats"]}')
130+
Printf.apikeys(apiKey.getItems())
131+
index = int(Printf.enterLimit("APIKEY index:", LANG.MSG_INPUT_ERR, apiKey.getLimitIndexs()))
132+
133+
if index != CONF.apiKeyIndex:
134+
CONF.apiKeyIndex = index
135+
Settings.save(CONF)
136+
API.apiKey = apiKey.getItem(index)
137+
return True
138+
return False
139+
140+
124141
def checkLogin():
125142
if not isNull(TOKEN.accessToken):
126143
# print('Checking Access Token...') #add to translations
@@ -241,7 +258,6 @@ def debug():
241258
pass
242259

243260

244-
245261
def main():
246262
if len(sys.argv) > 1:
247263
mainCommand()
@@ -257,8 +273,8 @@ def main():
257273
icmp = cmpVersion(onlineVer, VERSION)
258274
if icmp > 0:
259275
Printf.info(LANG.PRINT_LATEST_VERSION + ' ' + onlineVer)
260-
261-
Printf.info("For some reasons, this version only supports LOSSLESS.")
276+
277+
# Printf.info("For some reasons, this version only supports LOSSLESS.")
262278

263279
while True:
264280
Printf.choices()
@@ -273,6 +289,9 @@ def main():
273289
checkLogout()
274290
elif choice == "4":
275291
setAccessToken()
292+
elif choice == '5':
293+
if setAPIKey():
294+
checkLogout()
276295
elif choice == "10": # test track
277296
start(TOKEN, CONF, '70973230')
278297
elif choice == "11": # test video

TIDALDL-PY/tidal_dl/apiKey.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/usr/bin/env python
2+
# -*- encoding: utf-8 -*-
3+
"""
4+
@File : apiKey.py
5+
@Date : 2021/11/30
6+
@Author : Yaronzz
7+
@Version : 1.0
8+
@Contact : yaronhuang@foxmail.com
9+
@Desc :
10+
"""
11+
12+
__API_KEYS__ = [
13+
{
14+
'platform': 'Fire TV',
15+
'formats': 'Normal/High/HiFi(No Master)',
16+
'clientId': 'OmDtrzFgyVVL6uW56OnFA2COiabqm',
17+
'clientSecret': 'zxen1r3pO0hgtOC7j6twMo9UAqngGrmRiWpV7QC1zJ8=',
18+
},
19+
{
20+
'platform': 'Fire TV',
21+
'formats': 'Master-Only(Else Error)',
22+
'clientId': '7m7Ap0JC9j1cOM3n',
23+
'clientSecret': 'vRAdA108tlvkJpTsGZS8rGZ7xTlbJ0qaZ2K9saEzsgY=',
24+
},
25+
{
26+
'platform': 'Android TV',
27+
'formats': 'Normal/High/HiFi(No Master)',
28+
'clientId': 'Pzd0ExNVHkyZLiYN',
29+
'clientSecret': 'W7X6UvBaho+XOi1MUeCX6ewv2zTdSOV3Y7qC3p3675I=',
30+
},
31+
]
32+
33+
__ERROR_KEY__ = {
34+
'platform': 'None',
35+
'formats': '',
36+
'clientId': '',
37+
'clientSecret': '',
38+
},
39+
40+
41+
def getNum():
42+
return len(__API_KEYS__)
43+
44+
45+
def getItem(index: int):
46+
if index < 0 or index >= len(__API_KEYS__):
47+
return __ERROR_KEY__
48+
return __API_KEYS__[index]
49+
50+
51+
def getItems():
52+
return __API_KEYS__
53+
54+
55+
def getLimitIndexs():
56+
array = []
57+
for i in range(len(__API_KEYS__)):
58+
array.append(str(i))
59+
return array

TIDALDL-PY/tidal_dl/lang/language.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from tidal_dl.lang.ukrainian import LangUkrainian
2828
from tidal_dl.lang.vietnamese import LangVietnamese
2929
from tidal_dl.lang.korean import LangKorean
30+
from tidal_dl.lang.japanese import LangJapanese
3031

3132
LANG = None
3233

@@ -74,6 +75,8 @@ def setLang(index):
7475
LANG = LangHungarian()
7576
elif str(index) == '17':
7677
LANG = LangKorean()
78+
elif str(index) == '18':
79+
LANG = LangJapanese()
7780
else:
7881
LANG = LangEnglish()
7982
return LANG
@@ -121,6 +124,8 @@ def getLangName(index):
121124
return "Hungarian"
122125
if str(index) == '17':
123126
return "Korean"
127+
if str(index) == '18':
128+
return "Japanese"
124129
return ""
125130

126131

TIDALDL-PY/tidal_dl/printf.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
from tidal_dl.lang.language import getLangName, getLang
1616
from tidal_dl.model import Album, Track, Video, Artist, StreamUrl, VideoStreamUrl
1717
from tidal_dl.settings import Settings, getSettingsPath
18+
import tidal_dl.apiKey as apiKey
19+
1820

1921
__LOGO__ = '''
2022
/$$$$$$$$ /$$ /$$ /$$ /$$ /$$
@@ -28,7 +30,7 @@
2830
2931
https://github.com/yaronzz/Tidal-Media-Downloader
3032
'''
31-
VERSION = '2021.11.21.1'
33+
VERSION = '2021.11.30.1'
3234

3335

3436
class Printf(object):
@@ -88,6 +90,7 @@ def settings(data: Settings):
8890
tb.add_row([LANG.SETTING_ADD_LYRICS, data.addLyrics])
8991
tb.add_row([LANG.SETTING_LYRICS_SERVER_PROXY, data.lyricsServerProxy])
9092
tb.add_row([LANG.SETTINGS_ADD_LRC_FILE, data.lyricFile])
93+
tb.add_row(['APIKey support', apiKey.getItem(data.apiKeyIndex)['formats']])
9194
print(tb)
9295

9396
@staticmethod
@@ -103,6 +106,7 @@ def choices():
103106
tb.add_row([aigpy.cmd.green(LANG.CHOICE_ENTER + " '2':"), LANG.CHOICE_SETTINGS])
104107
tb.add_row([aigpy.cmd.green(LANG.CHOICE_ENTER + " '3':"), LANG.CHOICE_LOGOUT])
105108
tb.add_row([aigpy.cmd.green(LANG.CHOICE_ENTER + " '4':"), LANG.CHOICE_SET_ACCESS_TOKEN])
109+
tb.add_row([aigpy.cmd.green(LANG.CHOICE_ENTER + " '5':"), 'Select APIKey'])
106110
tb.add_row([aigpy.cmd.green(LANG.CHOICE_ENTER_URLID), LANG.CHOICE_DOWNLOAD_BY_URL])
107111
print(tb)
108112
print("====================================================")
@@ -270,3 +274,15 @@ def mix(data):
270274
"track num:" + str(len(data.tracks)) + "\n" +
271275
"video num:" + str(len(data.videos)) + "\n" +
272276
"==================================")
277+
278+
@staticmethod
279+
def apikeys(items):
280+
print("-------------API-KEYS---------------")
281+
LANG = getLang()
282+
tb = prettytable.PrettyTable()
283+
tb.field_names = [aigpy.cmd.green('Index'), aigpy.cmd.green('Platform'), aigpy.cmd.green('Formats'), ]
284+
tb.align = 'l'
285+
286+
for index, item in enumerate(items):
287+
tb.add_row([str(index), item["platform"], item["formats"]])
288+
print(tb)

TIDALDL-PY/tidal_dl/settings.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ class Settings(ModelBase):
105105
showTrackInfo = True
106106
saveAlbumInfo = False
107107
lyricFile = False
108+
apiKeyIndex = 0
108109

109110
@staticmethod
110111
def getDefaultAlbumFolderFormat():
@@ -132,6 +133,8 @@ def read():
132133
ret.albumFolderFormat = Settings.getDefaultAlbumFolderFormat()
133134
if ret.trackFileFormat is None:
134135
ret.trackFileFormat = Settings.getDefaultTrackFileFormat()
136+
if ret.apiKeyIndex is None:
137+
ret.apiKeyIndex = 0
135138
return ret
136139

137140
@staticmethod

TIDALDL-PY/tidal_dl/tidal.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,13 @@
1919
from requests.packages import urllib3
2020
from tidal_dl.enums import Type, AudioQuality, VideoQuality
2121
from tidal_dl.model import Album, Track, Video, Artist, Playlist, StreamUrl, VideoStreamUrl, SearchResult, Lyrics, Mix
22+
import tidal_dl.apiKey as apiKey
2223

2324
__VERSION__ = '1.9.1'
2425
__URL_PRE__ = 'https://api.tidalhifi.com/v1/'
2526
__AUTH_URL__ = 'https://auth.tidal.com/v1/oauth2'
26-
# known API key for Fire Stick HD(MQA, Dolby Vision enabled)
27-
__API_KEY__ = {'clientId': 'OmDtrzFgyVVL6uW56OnFA2COiabqm',
28-
'clientSecret': 'zxen1r3pO0hgtOC7j6twMo9UAqngGrmRiWpV7QC1zJ8='}
29-
# __API_KEY__ = {'clientId': 'aR7gUaTK1ihpXOEP', 'clientSecret': 'eVWBEkuL2FCjxgjOkR3yK0RYZEbcrMXRc2l8fU3ZCdE='}
27+
__API_KEY__ = {'clientId': '7m7Ap0JC9j1cOM3n',
28+
'clientSecret': 'vRAdA108tlvkJpTsGZS8rGZ7xTlbJ0qaZ2K9saEzsgY='}
3029

3130
# SSL Warnings
3231
urllib3.disable_warnings()
@@ -62,6 +61,7 @@ class __StreamRespond__(object):
6261

6362
class TidalAPI(object):
6463
def __init__(self):
64+
self.apiKey = __API_KEY__
6565
self.key = LoginKey()
6666
self.__debugVar = 0
6767

@@ -171,7 +171,7 @@ def __post__(self, url, data, auth=None):
171171

172172
def getDeviceCode(self):
173173
data = {
174-
'client_id': __API_KEY__['clientId'],
174+
'client_id': self.apiKey['clientId'],
175175
'scope': 'r_usr+w_usr+w_sub'
176176
}
177177
e, result = self.__post__(__AUTH_URL__ + '/device_authorization', data)
@@ -190,12 +190,12 @@ def getDeviceCode(self):
190190

191191
def checkAuthStatus(self):
192192
data = {
193-
'client_id': __API_KEY__['clientId'],
193+
'client_id': self.apiKey['clientId'],
194194
'device_code': self.key.deviceCode,
195195
'grant_type': 'urn:ietf:params:oauth:grant-type:device_code',
196196
'scope': 'r_usr+w_usr+w_sub'
197197
}
198-
e, result = self.__post__(__AUTH_URL__ + '/token', data, (__API_KEY__['clientId'], __API_KEY__['clientSecret']))
198+
e, result = self.__post__(__AUTH_URL__ + '/token', data, (self.apiKey['clientId'], self.apiKey['clientSecret']))
199199
if e is not None:
200200
return str(e), False
201201

@@ -222,17 +222,17 @@ def verifyAccessToken(self, accessToken):
222222

223223
def refreshAccessToken(self, refreshToken):
224224
data = {
225-
'client_id': __API_KEY__['clientId'],
225+
'client_id': self.apiKey['clientId'],
226226
'refresh_token': refreshToken,
227227
'grant_type': 'refresh_token',
228228
'scope': 'r_usr+w_usr+w_sub'
229229
}
230230

231-
e, result = self.__post__(__AUTH_URL__ + '/token', data, (__API_KEY__['clientId'], __API_KEY__['clientSecret']))
231+
e, result = self.__post__(__AUTH_URL__ + '/token', data, (self.apiKey['clientId'], self.apiKey['clientSecret']))
232232
if e is not None:
233233
return str(e), False
234234

235-
# result = requests.post(__AUTH_URL__ + '/token', data=data, auth=(__API_KEY__['clientId'], __API_KEY__['clientSecret'])).json()
235+
# result = requests.post(__AUTH_URL__ + '/token', data=data, auth=(self.apiKey['clientId'], self.apiKey['clientSecret'])).json()
236236
if 'status' in result and result['status'] != 200:
237237
return "Refresh failed. Please log in again.", False
238238

TIDALDL-PY/updatelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
TYPE tidal-dl
22
USE pip3 install tidal-dl --upgrade
33

4+
#### v2021-11-30
5+
- [x] Add language:Japanese
6+
- [x] Support select apikey(Different keys support different formats)
7+
48
#### v2021-11-15
59
- [x] Add language:Korean
610
- [x] Update vietnamese

0 commit comments

Comments
 (0)