Skip to content

Commit

Permalink
upload new version
Browse files Browse the repository at this point in the history
  • Loading branch information
yaronzz committed Nov 30, 2021
1 parent 94139c9 commit 41d7e30
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 14 deletions.
Binary file modified TIDALDL-PY/exe/tidal-dl.exe
Binary file not shown.
25 changes: 22 additions & 3 deletions TIDALDL-PY/tidal_dl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@
from tidal_dl.settings import Settings, TokenSettings, getLogPath
from tidal_dl.tidal import TidalAPI
from tidal_dl.util import API
import tidal_dl.apiKey as apiKey

ssl._create_default_https_context = ssl._create_unverified_context

TOKEN = TokenSettings.read()
CONF = Settings.read()
LANG = initLang(CONF.language)
API.apiKey = apiKey.getItem(CONF.apiKeyIndex)

logging.basicConfig(filename=getLogPath(),
level=logging.INFO,
Expand Down Expand Up @@ -121,6 +123,21 @@ def setAccessToken():
TokenSettings.save(TOKEN)


def setAPIKey():
global LANG
item = apiKey.getItem(CONF.apiKeyIndex)
Printf.info(f'Current APIKeys: {str(CONF.apiKeyIndex)} {item["platform"]}-{item["formats"]}')
Printf.apikeys(apiKey.getItems())
index = int(Printf.enterLimit("APIKEY index:", LANG.MSG_INPUT_ERR, apiKey.getLimitIndexs()))

if index != CONF.apiKeyIndex:
CONF.apiKeyIndex = index
Settings.save(CONF)
API.apiKey = apiKey.getItem(index)
return True
return False


def checkLogin():
if not isNull(TOKEN.accessToken):
# print('Checking Access Token...') #add to translations
Expand Down Expand Up @@ -241,7 +258,6 @@ def debug():
pass



def main():
if len(sys.argv) > 1:
mainCommand()
Expand All @@ -257,8 +273,8 @@ def main():
icmp = cmpVersion(onlineVer, VERSION)
if icmp > 0:
Printf.info(LANG.PRINT_LATEST_VERSION + ' ' + onlineVer)
Printf.info("For some reasons, this version only supports LOSSLESS.")

# Printf.info("For some reasons, this version only supports LOSSLESS.")

while True:
Printf.choices()
Expand All @@ -273,6 +289,9 @@ def main():
checkLogout()
elif choice == "4":
setAccessToken()
elif choice == '5':
if setAPIKey():
checkLogout()
elif choice == "10": # test track
start(TOKEN, CONF, '70973230')
elif choice == "11": # test video
Expand Down
59 changes: 59 additions & 0 deletions TIDALDL-PY/tidal_dl/apiKey.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
"""
@File : apiKey.py
@Date : 2021/11/30
@Author : Yaronzz
@Version : 1.0
@Contact : [email protected]
@Desc :
"""

__API_KEYS__ = [
{
'platform': 'Fire TV',
'formats': 'Normal/High/HiFi(No Master)',
'clientId': 'OmDtrzFgyVVL6uW56OnFA2COiabqm',
'clientSecret': 'zxen1r3pO0hgtOC7j6twMo9UAqngGrmRiWpV7QC1zJ8=',
},
{
'platform': 'Fire TV',
'formats': 'Master-Only(Else Error)',
'clientId': '7m7Ap0JC9j1cOM3n',
'clientSecret': 'vRAdA108tlvkJpTsGZS8rGZ7xTlbJ0qaZ2K9saEzsgY=',
},
{
'platform': 'Android TV',
'formats': 'Normal/High/HiFi(No Master)',
'clientId': 'Pzd0ExNVHkyZLiYN',
'clientSecret': 'W7X6UvBaho+XOi1MUeCX6ewv2zTdSOV3Y7qC3p3675I=',
},
]

__ERROR_KEY__ = {
'platform': 'None',
'formats': '',
'clientId': '',
'clientSecret': '',
},


def getNum():
return len(__API_KEYS__)


def getItem(index: int):
if index < 0 or index >= len(__API_KEYS__):
return __ERROR_KEY__
return __API_KEYS__[index]


def getItems():
return __API_KEYS__


def getLimitIndexs():
array = []
for i in range(len(__API_KEYS__)):
array.append(str(i))
return array
5 changes: 5 additions & 0 deletions TIDALDL-PY/tidal_dl/lang/language.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from tidal_dl.lang.ukrainian import LangUkrainian
from tidal_dl.lang.vietnamese import LangVietnamese
from tidal_dl.lang.korean import LangKorean
from tidal_dl.lang.japanese import LangJapanese

LANG = None

Expand Down Expand Up @@ -74,6 +75,8 @@ def setLang(index):
LANG = LangHungarian()
elif str(index) == '17':
LANG = LangKorean()
elif str(index) == '18':
LANG = LangJapanese()
else:
LANG = LangEnglish()
return LANG
Expand Down Expand Up @@ -121,6 +124,8 @@ def getLangName(index):
return "Hungarian"
if str(index) == '17':
return "Korean"
if str(index) == '18':
return "Japanese"
return ""


Expand Down
18 changes: 17 additions & 1 deletion TIDALDL-PY/tidal_dl/printf.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
from tidal_dl.lang.language import getLangName, getLang
from tidal_dl.model import Album, Track, Video, Artist, StreamUrl, VideoStreamUrl
from tidal_dl.settings import Settings, getSettingsPath
import tidal_dl.apiKey as apiKey


__LOGO__ = '''
/$$$$$$$$ /$$ /$$ /$$ /$$ /$$
Expand All @@ -28,7 +30,7 @@
https://github.com/yaronzz/Tidal-Media-Downloader
'''
VERSION = '2021.11.21.1'
VERSION = '2021.11.30.1'


class Printf(object):
Expand Down Expand Up @@ -88,6 +90,7 @@ def settings(data: Settings):
tb.add_row([LANG.SETTING_ADD_LYRICS, data.addLyrics])
tb.add_row([LANG.SETTING_LYRICS_SERVER_PROXY, data.lyricsServerProxy])
tb.add_row([LANG.SETTINGS_ADD_LRC_FILE, data.lyricFile])
tb.add_row(['APIKey support', apiKey.getItem(data.apiKeyIndex)['formats']])
print(tb)

@staticmethod
Expand All @@ -103,6 +106,7 @@ def choices():
tb.add_row([aigpy.cmd.green(LANG.CHOICE_ENTER + " '2':"), LANG.CHOICE_SETTINGS])
tb.add_row([aigpy.cmd.green(LANG.CHOICE_ENTER + " '3':"), LANG.CHOICE_LOGOUT])
tb.add_row([aigpy.cmd.green(LANG.CHOICE_ENTER + " '4':"), LANG.CHOICE_SET_ACCESS_TOKEN])
tb.add_row([aigpy.cmd.green(LANG.CHOICE_ENTER + " '5':"), 'Select APIKey'])
tb.add_row([aigpy.cmd.green(LANG.CHOICE_ENTER_URLID), LANG.CHOICE_DOWNLOAD_BY_URL])
print(tb)
print("====================================================")
Expand Down Expand Up @@ -270,3 +274,15 @@ def mix(data):
"track num:" + str(len(data.tracks)) + "\n" +
"video num:" + str(len(data.videos)) + "\n" +
"==================================")

@staticmethod
def apikeys(items):
print("-------------API-KEYS---------------")
LANG = getLang()
tb = prettytable.PrettyTable()
tb.field_names = [aigpy.cmd.green('Index'), aigpy.cmd.green('Platform'), aigpy.cmd.green('Formats'), ]
tb.align = 'l'

for index, item in enumerate(items):
tb.add_row([str(index), item["platform"], item["formats"]])
print(tb)
3 changes: 3 additions & 0 deletions TIDALDL-PY/tidal_dl/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class Settings(ModelBase):
showTrackInfo = True
saveAlbumInfo = False
lyricFile = False
apiKeyIndex = 0

@staticmethod
def getDefaultAlbumFolderFormat():
Expand Down Expand Up @@ -132,6 +133,8 @@ def read():
ret.albumFolderFormat = Settings.getDefaultAlbumFolderFormat()
if ret.trackFileFormat is None:
ret.trackFileFormat = Settings.getDefaultTrackFileFormat()
if ret.apiKeyIndex is None:
ret.apiKeyIndex = 0
return ret

@staticmethod
Expand Down
20 changes: 10 additions & 10 deletions TIDALDL-PY/tidal_dl/tidal.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@
from requests.packages import urllib3
from tidal_dl.enums import Type, AudioQuality, VideoQuality
from tidal_dl.model import Album, Track, Video, Artist, Playlist, StreamUrl, VideoStreamUrl, SearchResult, Lyrics, Mix
import tidal_dl.apiKey as apiKey

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

# SSL Warnings
urllib3.disable_warnings()
Expand Down Expand Up @@ -62,6 +61,7 @@ class __StreamRespond__(object):

class TidalAPI(object):
def __init__(self):
self.apiKey = __API_KEY__
self.key = LoginKey()
self.__debugVar = 0

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

def getDeviceCode(self):
data = {
'client_id': __API_KEY__['clientId'],
'client_id': self.apiKey['clientId'],
'scope': 'r_usr+w_usr+w_sub'
}
e, result = self.__post__(__AUTH_URL__ + '/device_authorization', data)
Expand All @@ -190,12 +190,12 @@ def getDeviceCode(self):

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

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

def refreshAccessToken(self, refreshToken):
data = {
'client_id': __API_KEY__['clientId'],
'client_id': self.apiKey['clientId'],
'refresh_token': refreshToken,
'grant_type': 'refresh_token',
'scope': 'r_usr+w_usr+w_sub'
}

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

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

Expand Down
4 changes: 4 additions & 0 deletions TIDALDL-PY/updatelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
TYPE tidal-dl
USE pip3 install tidal-dl --upgrade

#### v2021-11-30
- [x] Add language:Japanese
- [x] Support select apikey(Different keys support different formats)

#### v2021-11-15
- [x] Add language:Korean
- [x] Update vietnamese
Expand Down

0 comments on commit 41d7e30

Please sign in to comment.