def changeSettings(): global LANG Printf.settings(CONF) choice = Printf.enter(LANG.CHANGE_START_SETTINGS) if choice == '0': return CONF.downloadPath = Printf.enterPath(LANG.CHANGE_DOWNLOAD_PATH, LANG.MSG_PATH_ERR, '0', CONF.downloadPath) CONF.audioQuality = AudioQuality( int( Printf.enterLimit(LANG.CHANGE_AUDIO_QUALITY, LANG.MSG_INPUT_ERR, ['0', '1', '2', '3']))) CONF.videoQuality = AudioQuality( int( Printf.enterLimit(LANG.CHANGE_VIDEO_QUALITY, LANG.MSG_INPUT_ERR, ['0', '1', '2', '3']))) CONF.onlyM4a = Printf.enter(LANG.CHANGE_ONLYM4A) == '1' CONF.checkExist = Printf.enter(LANG.CHANGE_CHECK_EXIST) == '1' CONF.includeEP = Printf.enter(LANG.CHANGE_INCLUDE_EP) == '1' CONF.saveCovers = Printf.enter(LANG.CHANGE_SAVE_COVERS) == '1' CONF.showProgress = Printf.enter(LANG.CHANGE_SHOW_PROGRESS) == '1' CONF.language = Printf.enter(LANG.CHANGE_LANGUAGE + "(" + getLangChoicePrint() + "):") CONF.albumFolderFormat = Printf.enterFormat( LANG.CHANGE_ALBUM_FOLDER_FORMAT, CONF.albumFolderFormat, Settings.getDefaultAlbumFolderFormat()) CONF.trackFileFormat = Printf.enterFormat( LANG.CHANGE_TRACK_FILE_FORMAT, CONF.trackFileFormat, Settings.getDefaultTrackFileFormat()) LANG = setLang(CONF.language) Settings.save(CONF)
def changeSettings(): global LANG Printf.settings(CONF) choice = Printf.enter(LANG.CHANGE_START_SETTINGS) if choice == '0': return CONF.downloadPath = Printf.enterPath(LANG.CHANGE_DOWNLOAD_PATH, LANG.MSG_PATH_ERR, '0', CONF.downloadPath) CONF.audioQuality = AudioQuality(int(Printf.enterLimit( LANG.CHANGE_AUDIO_QUALITY, LANG.MSG_INPUT_ERR, ['0', '1', '2', '3']))) CONF.videoQuality = VideoQuality(int(Printf.enterLimit( LANG.CHANGE_VIDEO_QUALITY, LANG.MSG_INPUT_ERR, ['1080', '720', '480', '360']))) CONF.onlyM4a = Printf.enter(LANG.CHANGE_ONLYM4A) == '1' CONF.checkExist = Printf.enter(LANG.CHANGE_CHECK_EXIST) == '1' CONF.includeEP = Printf.enter(LANG.CHANGE_INCLUDE_EP) == '1' CONF.saveCovers = Printf.enter(LANG.CHANGE_SAVE_COVERS) == '1' CONF.showProgress = Printf.enter(LANG.CHANGE_SHOW_PROGRESS) == '1' CONF.saveAlbumInfo = Printf.enter(LANG.CHANGE_SAVE_ALBUM_INFO) == '1' CONF.showTrackInfo = Printf.enter(LANG.CHANGE_SHOW_TRACKINFO) == '1' CONF.usePlaylistFolder = Printf.enter(LANG.SETTING_USE_PLAYLIST_FOLDER + "('0'-No,'1'-Yes):") == '1' CONF.language = Printf.enter(LANG.CHANGE_LANGUAGE + "(" + getLangChoicePrint() + "):") CONF.albumFolderFormat = Printf.enterFormat( LANG.CHANGE_ALBUM_FOLDER_FORMAT, CONF.albumFolderFormat, Settings.getDefaultAlbumFolderFormat()) CONF.trackFileFormat = Printf.enterFormat(LANG.CHANGE_TRACK_FILE_FORMAT, CONF.trackFileFormat, Settings.getDefaultTrackFileFormat()) CONF.addLyrics = Printf.enter(LANG.CHANGE_ADD_LYRICS) == '1' CONF.lyricsServerProxy = Printf.enterFormat( LANG.CHANGE_LYRICS_SERVER_PROXY, CONF.lyricsServerProxy, CONF.lyricsServerProxy) CONF.lyricFile = Printf.enter(LANG.CHANGE_ADD_LRC_FILE) == '1' CONF.addTypeFolder = Printf.enter(LANG.CHANGE_ADD_TYPE_FOLDER) == '1' LANG = setLang(CONF.language) Settings.save(CONF)
def changeSettings(): Printf.settings(CONF) choice = Printf.enter(LANG.CHANGE_START_SETTINGS) if choice == '0': return while True: choice = Printf.enter(LANG.CHANGE_DOWNLOAD_PATH) if choice == '0': choice = CONF.downloadPath elif not os.path.isdir(choice): if not mkdirs(choice): Printf.err(LANG.MSG_PATH_ERR) continue CONF.downloadPath = choice break while True: choice = Printf.enter(LANG.CHANGE_AUDIO_QUALITY) if choice != '1' and choice != '2' and choice != '3' and choice != '0': Printf.err(LANG.MSG_INPUT_ERR) continue if choice == '0': CONF.audioQuality = AudioQuality.Normal if choice == '1': CONF.audioQuality = AudioQuality.High if choice == '2': CONF.audioQuality = AudioQuality.HiFi if choice == '3': CONF.audioQuality = AudioQuality.Master break while True: choice = Printf.enter(LANG.CHANGE_VIDEO_QUALITY) if choice != '1' and choice != '2' and choice != '3' and choice != '0': Printf.err(LANG.MSG_INPUT_ERR) continue if choice == '0': CONF.videoQuality = VideoQuality.P1080 if choice == '1': CONF.videoQuality = VideoQuality.P720 if choice == '2': CONF.videoQuality = VideoQuality.P480 if choice == '3': CONF.videoQuality = VideoQuality.P360 break CONF.onlyM4a = Printf.enter(LANG.CHANGE_ONLYM4A) == '1' CONF.addExplicitTag = Printf.enter(LANG.CHANGE_ADD_EXPLICIT_TAG) == '1' CONF.addHyphen = Printf.enter(LANG.CHANGE_ADD_HYPHEN) == '1' CONF.addYear = Printf.enter(LANG.CHANGE_ADD_YEAR) == '1' CONF.useTrackNumber = Printf.enter(LANG.CHANGE_USE_TRACK_NUM) == '1' CONF.checkExist = Printf.enter(LANG.CHANGE_CHECK_EXIST) == '1' CONF.artistBeforeTitle = Printf.enter( LANG.CHANGE_ARTIST_BEFORE_TITLE) == '1' CONF.includeEP = Printf.enter(LANG.CHANGE_INCLUDE_EP) == '1' CONF.addAlbumIDBeforeFolder = Printf.enter( LANG.CHANGE_ALBUMID_BEFORE_FOLDER) == '1' CONF.saveCovers = Printf.enter(LANG.CHANGE_SAVE_COVERS) == '1' CONF.language = Printf.enter(LANG.CHANGE_LANGUAGE) LANG = setLang(CONF.language) Settings.save(CONF)
def setCurVideoQuality(text): if CONF.videoQuality.name == text: return for item in tidal_dl.enums.VideoQuality: if item.name == text: CONF.videoQuality = item break Settings.save(CONF)
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 __getAlbumPath__(conf: Settings, album): base = conf.downloadPath + '/Album/' artist = replaceLimitChar(album.artists[0].name, '-') # album folder pre: [ME][ID] flag = API.getFlag(album, Type.Album, True, "") if conf.audioQuality != AudioQuality.Master: flag = flag.replace("M", "") if not conf.addExplicitTag: flag = flag.replace("E", "") if not isNull(flag): flag = "[" + flag + "] " sid = str(album.id) #album and addyear albumname = replaceLimitChar(album.title, '-') year = getSubOnlyEnd(album.releaseDate, '-') # retpath retpath = conf.albumFolderFormat if retpath is None or len(retpath) <= 0: retpath = Settings.getDefualtAlbumFolderFormat() retpath = retpath.replace(R"{ArtistName}", artist) retpath = retpath.replace(R"{Flag}", flag) retpath = retpath.replace(R"{AlbumID}", sid) retpath = retpath.replace(R"{AlbumYear}", year) retpath = retpath.replace(R"{AlbumTitle}", albumname) retpath = retpath.strip() return base + retpath
def mainCommand(): try: opts, args = getopt.getopt(sys.argv[1:], "ho:l:v:u:p:a:q:r", [ "help", "output=", "link=", "version", "username", "password", "accessToken", "quality", "resolution" ]) link = None for opt, val in opts: if opt in ('-h', '--help'): Printf.usage() return if opt in ('-v', '--version'): Printf.logo() return if opt in ('-l', '--link'): link = val if opt in ('-o', '--output'): CONF.downloadPath = val if opt in ('-u', '--username'): USER.username = val UserSettings.save(USER) if opt in ('-p', '--password'): USER.password = val UserSettings.save(USER) if opt in ('-a', '--accessToken'): USER.assesstoken = val UserSettings.save(USER) if opt in ('-q', '--quality'): CONF.audioQuality = Settings.getAudioQuality(val) if opt in ('-r', '--resolution'): CONF.videoQuality = Settings.getVideoQuality(val) if link is None: Printf.err( "Please enter the link(url/id/path)! Enter 'tidal-dl -h' for help!" ) return if not mkdirs(CONF.downloadPath): Printf.err(LANG.MSG_PATH_ERR + CONF.downloadPath) return checkLogin() start(USER, CONF, link) return except getopt.GetoptError: Printf.err("Argv error! Enter 'tidal -h' for help!")
def getTrackPath(conf: Settings, track, stream, album=None, playlist=None): base = './' if album is not None: base = getAlbumPath(conf, album) + '/' if album.numberOfVolumes > 1: base += 'CD' + str(track.volumeNumber) + '/' if playlist is not None and conf.usePlaylistFolder: base = getPlaylistPath(conf, playlist) # number number = __getIndexStr__(track.trackNumber) if playlist is not None and conf.usePlaylistFolder: number = __getIndexStr__(track.trackNumberOnPlaylist) # artist artists = aigpy.path.replaceLimitChar(getArtistsName(track.artists), '-') artist = aigpy.path.replaceLimitChar( track.artist.name, '-') if track.artist is not None else "" # title title = track.title if not aigpy.string.isNull(track.version): title += ' (' + track.version + ')' title = aigpy.path.replaceLimitChar(title, '-') # get explicit explicit = "(Explicit)" if conf.addExplicitTag and track.explicit else '' # album and addyear albumname = aigpy.path.replaceLimitChar(album.title, '-') year = "" if album.releaseDate is not None: year = aigpy.string.getSubOnlyEnd(album.releaseDate, '-') # extension extension = __getExtension__(stream.url) retpath = conf.trackFileFormat if retpath is None or len(retpath) <= 0: retpath = Settings.getDefaultTrackFileFormat() retpath = retpath.replace(R"{TrackNumber}", number) retpath = retpath.replace(R"{ArtistName}", artist.strip()) retpath = retpath.replace(R"{ArtistsName}", artists.strip()) retpath = retpath.replace(R"{TrackTitle}", title) retpath = retpath.replace(R"{ExplicitFlag}", explicit) retpath = retpath.replace(R"{AlbumYear}", year) retpath = retpath.replace(R"{AlbumTitle}", albumname.strip()) retpath = retpath.replace(R"{AudioQuality}", track.audioQuality) retpath = retpath.replace(R"{DurationSeconds}", str(track.duration)) retpath = retpath.replace(R"{Duration}", __secondsToTimeStr__(track.duration)) retpath = retpath.replace(R"{TrackID}", str(track.id)) retpath = retpath.strip() return base + retpath + extension
def getAlbumPath(conf: Settings, album): base = conf.downloadPath + '/' if conf.addTypeFolder: base = base + 'Album/' artist = aigpy.path.replaceLimitChar(getArtistsName(album.artists), '-') albumArtistName = aigpy.path.replaceLimitChar( album.artist.name, '-') if album.artist is not None else "" # album folder pre: [ME][ID] flag = API.getFlag(album, Type.Album, True, "") if conf.audioQuality != AudioQuality.Master: flag = flag.replace("M", "") if not conf.addExplicitTag: flag = flag.replace("E", "") if not aigpy.string.isNull(flag): flag = "[" + flag + "] " sid = str(album.id) # album and addyear albumname = aigpy.path.replaceLimitChar(album.title, '-') year = "" if album.releaseDate is not None: year = aigpy.string.getSubOnlyEnd(album.releaseDate, '-') # retpath retpath = conf.albumFolderFormat if retpath is None or len(retpath) <= 0: retpath = Settings.getDefaultAlbumFolderFormat() retpath = retpath.replace(R"{ArtistName}", artist.strip()) retpath = retpath.replace(R"{AlbumArtistName}", albumArtistName.strip()) retpath = retpath.replace(R"{Flag}", flag) retpath = retpath.replace(R"{AlbumID}", sid) retpath = retpath.replace(R"{AlbumYear}", year) retpath = retpath.replace(R"{AlbumTitle}", albumname.strip()) retpath = retpath.replace(R"{AudioQuality}", album.audioQuality) retpath = retpath.replace(R"{DurationSeconds}", str(album.duration)) retpath = retpath.replace(R"{Duration}", __secondsToTimeStr__(album.duration)) retpath = retpath.replace(R"{NumberOfTracks}", str(album.numberOfTracks)) retpath = retpath.replace(R"{NumberOfVideos}", str(album.numberOfVideos)) retpath = retpath.replace(R"{NumberOfVolumes}", str(album.numberOfVolumes)) retpath = retpath.replace(R"{ReleaseDate}", str(album.releaseDate)) retpath = retpath.replace(R"{RecordType}", album.type) retpath = retpath.replace(R"{None}", "") retpath = stripPath(retpath.strip()) return base + retpath
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)
def getVideoPath(conf, video, album=None, playlist=None): if album is not None and album.title is not None: base = getAlbumPath(conf, album) elif playlist is not None and conf.usePlaylistFolder: base = getPlaylistPath(conf, playlist) else: base = conf.downloadPath + '/' if conf.addTypeFolder: base = base + 'Video/' # get number number = __getIndexStr__(video.trackNumber) # get artist artists = aigpy.path.replaceLimitChar(getArtistsName(video.artists), '-') artist = aigpy.path.replaceLimitChar( video.artist.name, '-') if video.artist is not None else "" # get explicit explicit = "(Explicit)" if conf.addExplicitTag and video.explicit else '' # title title = aigpy.path.replaceLimitChar(video.title, '-') # year year = "" if video.releaseDate is not None: year = aigpy.string.getSubOnlyEnd(video.releaseDate, '-') # extension extension = ".mp4" retpath = conf.videoFileFormat # R"{VideoNumber} - {ArtistName} - [{ArtistsName}] - {VideoYear} - {VideoID} - {VideoTitle}{ExplicitFlag}" if retpath is None or len(retpath) <= 0: retpath = Settings.getDefaultVideoFileFormat() retpath = retpath.replace(R"{VideoNumber}", number) retpath = retpath.replace(R"{ArtistName}", artist.strip()) retpath = retpath.replace(R"{ArtistsName}", artists.strip()) retpath = retpath.replace(R"{VideoTitle}", title) retpath = retpath.replace(R"{ExplicitFlag}", explicit) retpath = retpath.replace(R"{VideoYear}", year) retpath = retpath.replace(R"{VideoID}", str(video.id)) retpath = retpath.strip() return base + retpath + extension
def __getTrackPath__(conf: Settings, track, stream, album=None, playlist=None): if album is not None: base = __getAlbumPath__(conf, album) + '/' if album.numberOfVolumes > 1: base += 'CD' + str(track.volumeNumber) + '/' if playlist is not None: base = __getPlaylistPath__(conf, playlist) # number number = __getIndexStr__(track.trackNumber) if playlist is not None: number = __getIndexStr__(track.trackNumberOnPlaylist) # artist artist = replaceLimitChar(track.artists[0].name, '-') # title title = track.title if not isNull(track.version): title += ' (' + track.version + ')' title = replaceLimitChar(title, '-') # get explicit explicit = "(Explicit)" if conf.addExplicitTag and track.explicit else '' #album and addyear albumname = replaceLimitChar(album.title, '-') year = "" if album.releaseDate is not None: year = getSubOnlyEnd(album.releaseDate, '-') # extension extension = __getExtension__(stream.url) retpath = conf.trackFileFormat if retpath is None or len(retpath) <= 0: retpath = Settings.getDefaultTrackFileFormat() retpath = retpath.replace(R"{TrackNumber}", number) retpath = retpath.replace(R"{ArtistName}", artist.strip()) retpath = retpath.replace(R"{TrackTitle}", title) retpath = retpath.replace(R"{ExplicitFlag}", explicit) retpath = retpath.replace(R"{AlbumYear}", year) retpath = retpath.replace(R"{AlbumTitle}", albumname.strip()) retpath = retpath.strip() return base + retpath + extension
def changeSettings(): global LANG Printf.settings(CONF) choice = Printf.enter(LANG.CHANGE_START_SETTINGS) if choice == '0': return while True: choice = Printf.enter(LANG.CHANGE_DOWNLOAD_PATH) if choice == '0': choice = CONF.downloadPath elif not os.path.isdir(choice): if not mkdirs(choice): Printf.err(LANG.MSG_PATH_ERR) continue CONF.downloadPath = choice break while True: choice = Printf.enter(LANG.CHANGE_AUDIO_QUALITY) if choice != '1' and choice != '2' and choice != '3' and choice != '0': Printf.err(LANG.MSG_INPUT_ERR) continue if choice == '0': CONF.audioQuality = AudioQuality.Normal if choice == '1': CONF.audioQuality = AudioQuality.High if choice == '2': CONF.audioQuality = AudioQuality.HiFi if choice == '3': CONF.audioQuality = AudioQuality.Master break while True: choice = Printf.enter(LANG.CHANGE_VIDEO_QUALITY) if choice != '1' and choice != '2' and choice != '3' and choice != '0': Printf.err(LANG.MSG_INPUT_ERR) continue if choice == '0': CONF.videoQuality = VideoQuality.P1080 if choice == '1': CONF.videoQuality = VideoQuality.P720 if choice == '2': CONF.videoQuality = VideoQuality.P480 if choice == '3': CONF.videoQuality = VideoQuality.P360 break CONF.onlyM4a = Printf.enter(LANG.CHANGE_ONLYM4A) == '1' # CONF.addExplicitTag = Printf.enter(LANG.CHANGE_ADD_EXPLICIT_TAG) == '1' # CONF.addHyphen = Printf.enter(LANG.CHANGE_ADD_HYPHEN) == '1' # CONF.addYear = Printf.enter(LANG.CHANGE_ADD_YEAR) == '1' # CONF.useTrackNumber = Printf.enter(LANG.CHANGE_USE_TRACK_NUM) == '1' CONF.checkExist = Printf.enter(LANG.CHANGE_CHECK_EXIST) == '1' # CONF.artistBeforeTitle = Printf.enter(LANG.CHANGE_ARTIST_BEFORE_TITLE) == '1' CONF.includeEP = Printf.enter(LANG.CHANGE_INCLUDE_EP) == '1' # CONF.addAlbumIDBeforeFolder = Printf.enter(LANG.CHANGE_ALBUMID_BEFORE_FOLDER) == '1' CONF.saveCovers = Printf.enter(LANG.CHANGE_SAVE_COVERS) == '1' CONF.showProgress = Printf.enter(LANG.CHANGE_SHOW_PROGRESS) == '1' CONF.language = Printf.enter( LANG.CHANGE_LANGUAGE + "('0'-English,'1'-中文,'2'-Turkish,'3'-Italiano,'4'-Czech,'5'-Arabic,'6'-Russian,'7'-Filipino,'8'-Croatian,'9'-Spanish,'10'-Portuguese,'11'-Ukrainian,'12'-Vietnamese,'13'-French,'14'-German):" ) albumFolderFormat = Printf.enter(LANG.CHANGE_ALBUM_FOLDER_FORMAT) if albumFolderFormat == '0': albumFolderFormat = CONF.albumFolderFormat else: CONF.albumFolderFormat = albumFolderFormat trackFileFormat = Printf.enter(LANG.CHANGE_TRACK_FILE_FORMAT) if trackFileFormat == '0': trackFileFormat = CONF.trackFileFormat else: CONF.trackFileFormat = trackFileFormat LANG = setLang(CONF.language) Settings.save(CONF)
from aigpy.pathHelper import mkdirs from aigpy.pipHelper import getLastVersion from aigpy.versionHelper import cmpVersion from tidal_dl.tidal import TidalAPI from tidal_dl.settings import Settings, UserSettings 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() USER = UserSettings.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: value = seconds // count