def checkLogin(): if not isNull(USER.accessToken): #print('Checking Access Token...') #add to translations msg, check = API.verifyAccessToken(USER.accessToken) if check == True: Printf.info( LANG.MSG_VALID_ACCESSTOKEN.format( displayTime(int(USER.expiresAfter - time.time())))) return else: Printf.info(LANG.MSG_INVAILD_ACCESSTOKEN) msg, check = API.refreshAccessToken(USER.refreshToken) if check == True: Printf.success( LANG.MSG_VALID_ACCESSTOKEN.format( displayTime(int(API.key.expiresIn)))) USER.userid = API.key.userId USER.countryCode = API.key.countryCode USER.accessToken = API.key.accessToken USER.expiresAfter = time.time() + int(API.key.expiresIn) UserSettings.save(USER) return else: Printf.err(msg) tmp = UserSettings() #clears saved tokens UserSettings.save(tmp) login() return
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 main(): if len(sys.argv) > 1: mainCommand() return Printf.logo() Printf.settings(CONF) checkLogin() onlineVer = getLastVersion('tidal-dl') if not isNull(onlineVer): icmp = cmpVersion(onlineVer, VERSION) if icmp > 0: Printf.info(LANG.PRINT_LATEST_VERSION + ' ' + onlineVer) while True: Printf.choices() choice = Printf.enter(LANG.PRINT_ENTER_CHOICE) if choice == "0": return elif choice == "1": checkLogin() elif choice == "2": changeSettings() else: start(USER, CONF, choice)
def downloadTrack(track: Track, album=None, playlist=None, userProgress=None, partSize=1048576): try: msg, stream = API.getStreamUrl(track.id, CONF.audioQuality) if not aigpy.string.isNull(msg) or stream is None: Printf.err(track.title + "." + msg) return False, msg if CONF.showTrackInfo: Printf.track(track, stream) if userProgress is not None: userProgress.updateStream(stream) path = getTrackPath(CONF, track, stream, album, playlist) # check exist if skip(path, stream.url): Printf.success( aigpy.path.getFileName(path) + " (skip:already exists!)") return True, "" # download logging.info("[DL Track] name=" + aigpy.path.getFileName(path) + "\nurl=" + stream.url) tool = aigpy.download.DownloadTool(path + '.part', [stream.url]) tool.setUserProgress(userProgress) tool.setPartSize(partSize) check, err = tool.start(CONF.showProgress) if not check: Printf.err("Download failed! " + aigpy.path.getFileName(path) + ' (' + str(err) + ')') return False, str(err) # encrypted -> decrypt and remove encrypted file encrypted(stream, path + '.part', path) # convert path = convert(path, stream) # contributors msg, contributors = API.getTrackContributors(track.id) msg, tidalLyrics = API.getLyrics(track.id) lyrics = '' if tidalLyrics is None else tidalLyrics.subtitles if CONF.lyricFile: if tidalLyrics is None: Printf.info(f'Failed to get lyrics from tidal!"{track.title}"') else: lrcPath = path.rsplit(".", 1)[0] + '.lrc' aigpy.fileHelper.write(lrcPath, tidalLyrics.subtitles, 'w') setMetaData(track, album, path, contributors, lyrics) Printf.success(aigpy.path.getFileName(path)) return True, "" except Exception as e: Printf.err("Download failed! " + track.title + ' (' + str(e) + ')') return False, str(e)
def main(): if len(sys.argv) > 1: mainCommand() return Printf.logo() Printf.settings(CONF) checkLogin() onlineVer = getLastVersion('tidal-dl') if not isNull(onlineVer): icmp = cmpVersion(onlineVer, VERSION) if icmp > 0: Printf.info(LANG.PRINT_LATEST_VERSION + ' ' + onlineVer) while True: Printf.choices() raw = Printf.enter(LANG.PRINT_ENTER_CHOICE).strip() choice = int(re.sub('[^0-9]', '', raw)) if choice == 0: return elif choice == 1: checkLogin() elif choice == 2: changeSettings() elif choice == 3: checkLogout() elif choice == 4: Printf.searchTypes() searchRaw = Printf.enter(LANG.PRINT_ENTER_CHOICE).strip() searchType = int(re.sub('[^0-9]', '', searchRaw)) if (searchType == 3): searchRaw = Printf.enter("Enter a url or id: ").strip() start(TOKEN, CONF, searchRaw) return field = "track" if searchType == 0 else 'album' if searchType == 1 else 'playlist' if searchType >= 0 and searchType <= 2: song = Printf.enter("Enter the song name: ") searchTrack(TOKEN, LANG.PRINT_ENTER_CHOICE, field, song, CONF) else: os.system('clear') Printf.err("Invalid option!") else: os.system('clear') Printf.err("Invalid option!")
def autoGetAccessToken(): array = API.tryGetAccessToken(USER.userid) if len(array) <= 0: return for item in array: msg, check = API.loginByAccessToken(item, USER.userid) if check == False: continue if item != USER.assesstoken: USER.assesstoken = item UserSettings.save(USER) Printf.info("Auto get accesstoken from tidal cache success!") return
def setAPIKey(): global LANG item = apiKey.getItem(CONF.apiKeyIndex) ver = apiKey.getVersion() Printf.info(f'Current APIKeys: {str(CONF.apiKeyIndex)} {item["platform"]}-{item["formats"]}') Printf.info(f'Current Version: {str(ver)}') 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 main(): if len(sys.argv) > 1: mainCommand() return Printf.logo() Printf.settings(CONF) checkLogin() onlineVer = getLastVersion('tidal-dl') if not isNull(onlineVer): icmp = cmpVersion(onlineVer, VERSION) if icmp > 0: Printf.info(LANG.PRINT_LATEST_VERSION + ' ' + onlineVer) while True: Printf.choices() choice = Printf.enter(LANG.PRINT_ENTER_CHOICE) if choice == "0": return elif choice == "1": checkLogin() elif choice == "2": changeSettings() elif choice == "3": 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 start(TOKEN, CONF, '188932980') elif choice == "12": # test album start(TOKEN, CONF, '58138532') elif choice == "13": # test playlist start(TOKEN, CONF, '98235845-13e8-43b4-94e2-d9f8e603cee7') elif choice == "14": # test playlist start(TOKEN, CONF, '01453963b7dbd41c8b82ccb678d127') else: start(TOKEN, CONF, choice)
def main(): if len(sys.argv) > 1: mainCommand() return Printf.logo() Printf.settings(CONF) checkLogin() autoGetAccessToken() onlineVer = getLastVersion('tidal-dl') if not isNull(onlineVer): icmp = cmpVersion(onlineVer, VERSION) if icmp > 0: Printf.info(LANG.PRINT_LATEST_VERSION + ' ' + onlineVer) while True: Printf.choices() choice = Printf.enter(LANG.PRINT_ENTER_CHOICE) if choice == "0": return elif choice == "1": login() elif choice == "2": changeSettings() elif choice == "3": setAccessToken() elif choice == "4": #batch processing try: with open('batch.txt') as batchfile: line = batchfile.readline() while line: if len(line.strip()) > 0: print('\033[1m' + f"Batching {line.strip()}" + '\033[0m') start(USER, CONF, line.strip()) line = batchfile.readline() except: traceback.print_exc() else: start(USER, CONF, choice)
def mainCommand(): try: opts, args = getopt.getopt( sys.argv[1:], "hvl:o:q:r:", ["help", "version", "link=", "output=", "quality", "resolution"]) except getopt.GetoptError as errmsg: Printf.err(vars(errmsg)['msg'] + ". Use 'tidal-dl -h' for useage.") return link = None for opt, val in opts: if opt in ('-h', '--help'): Printf.usage() continue if opt in ('-v', '--version'): Printf.logo() continue if opt in ('-l', '--link'): checkLogin() link = val continue if opt in ('-o', '--output'): CONF.downloadPath = val Settings.save(CONF) continue if opt in ('-q', '--quality'): CONF.audioQuality = Settings.getAudioQuality(val) Settings.save(CONF) continue if opt in ('-r', '--resolution'): CONF.videoQuality = Settings.getVideoQuality(val) Settings.save(CONF) continue if not mkdirs(CONF.downloadPath): Printf.err(LANG.MSG_PATH_ERR + CONF.downloadPath) return if link is not None: Printf.info(LANG.SETTING_DOWNLOAD_PATH + ':' + CONF.downloadPath) start(TOKEN, CONF, link)