def checkLogin(): if not isNull(TOKEN.accessToken): #print('Checking Access Token...') #add to translations msg, check = API.verifyAccessToken(TOKEN.accessToken) if check == True: Printf.info( LANG.MSG_VALID_ACCESSTOKEN.format( displayTime(int(TOKEN.expiresAfter - time.time())))) return else: Printf.info(LANG.MSG_INVAILD_ACCESSTOKEN) msg, check = API.refreshAccessToken(TOKEN.refreshToken) if check == True: Printf.success( LANG.MSG_VALID_ACCESSTOKEN.format( displayTime(int(API.key.expiresIn)))) TOKEN.userid = API.key.userId TOKEN.countryCode = API.key.countryCode TOKEN.accessToken = API.key.accessToken TOKEN.expiresAfter = time.time() + int(API.key.expiresIn) TokenSettings.save(TOKEN) return else: Printf.err(msg) tmp = TokenSettings() #clears saved tokens TokenSettings.save(tmp) login() return
def loginByWeb(): start = time.time() elapsed = 0 while elapsed < API.key.authCheckTimeout: elapsed = time.time() - start msg, check = API.checkAuthStatus() if not check: if msg == "pending": time.sleep(API.key.authCheckInterval + 1) continue return False if check: Printf.success( LANG.MSG_VALID_ACCESSTOKEN.format( displayTime(int(API.key.expiresIn)))) TOKEN.userid = API.key.userId TOKEN.countryCode = API.key.countryCode TOKEN.accessToken = API.key.accessToken TOKEN.refreshToken = API.key.refreshToken TOKEN.expiresAfter = time.time() + int(API.key.expiresIn) TokenSettings.save(TOKEN) return True Printf.err(LANG.AUTH_TIMEOUT) return False
def loginByConfig(): if aigpy.stringHelper.isNull(TOKEN.accessToken): return False msg, check = API.verifyAccessToken(TOKEN.accessToken) if check: Printf.info( LANG.MSG_VALID_ACCESSTOKEN.format( displayTime(int(TOKEN.expiresAfter - time.time())))) API.key.countryCode = TOKEN.countryCode API.key.userId = TOKEN.userid API.key.accessToken = TOKEN.accessToken return True Printf.info(LANG.MSG_INVAILD_ACCESSTOKEN) msg, check = API.refreshAccessToken(TOKEN.refreshToken) if check: Printf.success( LANG.MSG_VALID_ACCESSTOKEN.format( displayTime(int(API.key.expiresIn)))) TOKEN.userid = API.key.userId TOKEN.countryCode = API.key.countryCode TOKEN.accessToken = API.key.accessToken TOKEN.expiresAfter = time.time() + int(API.key.expiresIn) TokenSettings.save(TOKEN) return True else: tmp = TokenSettings() # clears saved tokens TokenSettings.save(tmp) return False
def login(): print(LANG.AUTH_START_LOGIN) msg, check = API.getDeviceCode() if check == False: Printf.err(msg) return print(LANG.AUTH_LOGIN_CODE.format(green(API.key.userCode))) print(LANG.AUTH_NEXT_STEP.format(green(API.key.verificationUrl), yellow(displayTime(API.key.authCheckTimeout)))) print(LANG.AUTH_WAITING) start = time.time() elapsed = 0 while elapsed < API.key.authCheckTimeout: elapsed = time.time() - start # print("Check auth status...") msg, check = API.checkAuthStatus() if check == False: if msg == "pending": time.sleep(API.key.authCheckInterval + 1) continue Printf.err(msg) break if check == True: Printf.success(LANG.MSG_VALID_ACCESSTOKEN.format(displayTime(int(API.key.expiresIn)))) TOKEN.userid = API.key.userId TOKEN.countryCode = API.key.countryCode TOKEN.accessToken = API.key.accessToken TOKEN.refreshToken = API.key.refreshToken TOKEN.expiresAfter = time.time() + int(API.key.expiresIn) TokenSettings.save(TOKEN) break if elapsed >= API.key.authCheckTimeout: Printf.err(LANG.AUTH_TIMEOUT) return
def setAccessToken(): while True: print("-------------AccessToken---------------") token = Printf.enter("accessToken('0' go back):") if token == '0': return msg, check = API.loginByAccessToken(token, TOKEN.userid) if check == False: Printf.err(msg) continue break print("-------------RefreshToken---------------") refreshToken = Printf.enter("refreshToken('0' to skip):") if refreshToken == '0': refreshToken = TOKEN.refreshToken TOKEN.assesstoken = token TOKEN.refreshToken = refreshToken TOKEN.expiresAfter = 0 TokenSettings.save(TOKEN)
from aigpy.pathHelper import mkdirs from aigpy.pipHelper import getLastVersion from aigpy.versionHelper import cmpVersion from aigpy.cmdHelper import red, green, blue, yellow, TextColor from tidal_dl.tidal import TidalAPI from tidal_dl.settings import Settings, TokenSettings from tidal_dl.printf import Printf, VERSION from tidal_dl.download import start from tidal_dl.enum import AudioQuality, VideoQuality from tidal_dl.lang.language import getLang, setLang, initLang ssl._create_default_https_context = ssl._create_unverified_context API = TidalAPI() TOKEN = TokenSettings.read() CONF = Settings.read() LANG = initLang(CONF.language) def displayTime(seconds, granularity=2): result = [] intervals = ( ('weeks', 604800), ('days', 86400), ('hours', 3600), ('minutes', 60), ('seconds', 1), ) for name, count in intervals: