def printChoice(string, isInt=False, default=None): tmpstr = "" cmdHelper.myprint(string, cmdHelper.TextColor.Yellow, None) if not isInt: return cmdHelper.myinput(tmpstr) else: return cmdHelper.myinputInt(tmpstr, default)
def printSUCCESS(length, elsestr): if systemHelper.isLinux(): cmdHelper.myprint("[SUCCESS]".ljust(length), cmdHelper.TextColor.Green, None) print(elsestr) else: print("[SUCCESS]".ljust(length) + elsestr)
def printChoice(string, isInt=False, default=None): tmpstr = "" if systemHelper.isLinux(): cmdHelper.myprint(string, cmdHelper.TextColor.Yellow, None) else: tmpstr = string if not isInt: return cmdHelper.myinput(tmpstr) else: return cmdHelper.myinputInt(tmpstr, default)
def enter(string): myprint(string, TextColor.Yellow, None) ret = input("") return ret
def printErr(length, elsestr): cmdHelper.myprint("[ERR]".ljust(length), cmdHelper.TextColor.Red, None) print(elsestr)
def printMenu(): print("=====================Choice=========================") cmdHelper.myprint(" Enter '0': ", cmdHelper.TextColor.Green, None) print("Exit.") cmdHelper.myprint(" Enter '1': ", cmdHelper.TextColor.Green, None) print("LogIn And Get SessionID.") cmdHelper.myprint(" Enter '2': ", cmdHelper.TextColor.Green, None) print("Setting(OutputDir/Quality/ThreadNum).") cmdHelper.myprint(" Enter '3': ", cmdHelper.TextColor.Green, None) print("Download Album.") cmdHelper.myprint(" Enter '4': ", cmdHelper.TextColor.Green, None) print("Download Track.") cmdHelper.myprint(" Enter '5': ", cmdHelper.TextColor.Green, None) print("Download PlayList.") cmdHelper.myprint(" Enter '6': ", cmdHelper.TextColor.Green, None) print("Download Video.") cmdHelper.myprint(" Enter '7': ", cmdHelper.TextColor.Green, None) print("Download Favorite.") cmdHelper.myprint(" Enter '8': ", cmdHelper.TextColor.Green, None) print("Download ArtistAlbum.") cmdHelper.myprint(" Enter URL: ", cmdHelper.TextColor.Green, None) print("Download By Url.") print("====================================================")
def printSUCCESS(length, elsestr): cmdHelper.myprint("[SUCCESS]".ljust(length), cmdHelper.TextColor.Green, None) print(elsestr)
def downloadPlaylist(self, playlist_id=None): while True: targetDir = self.config.outputdir + "/Playlist/" if playlist_id is None: print("--------------PLAYLIST-----------------") sID = printChoice("Enter PlayListID(Enter '0' go back):") if sID == '0': return else: sID = playlist_id aPlaylistInfo, aItemInfo = self.tool.getPlaylist(sID) if self.tool.errmsg != "": printErr(0, "Get PlaylistInfo Err! " + self.tool.errmsg) return print("[Title] %s" % (aPlaylistInfo['title'])) print("[Type] %s" % (aPlaylistInfo['type'])) print("[NumberOfTracks] %s" % (aPlaylistInfo['numberOfTracks'])) print("[NumberOfVideos] %s" % (aPlaylistInfo['numberOfVideos'])) print("[Duration] %s\n" % (aPlaylistInfo['duration'])) # Creat OutputDir targetDir = targetDir + pathHelper.replaceLimitChar( aPlaylistInfo['title'], '-') targetDir = os.path.abspath(targetDir).strip() pathHelper.mkdirs(targetDir) # write msg string = self.tool.convertPlaylistInfoToString( aPlaylistInfo, aItemInfo) with codecs.open(targetDir + "/PlaylistInfo.txt", 'w', 'utf-8') as fd: fd.write(string) # download cover coverPath = targetDir + '/' + pathHelper.replaceLimitChar( aPlaylistInfo['title'], '-') + '.jpg' coverUrl = self.tool.getPlaylistArtworkUrl(aPlaylistInfo['uuid']) check = netHelper.downloadFile(coverUrl, coverPath) # download track bBreakFlag = False bFirstTime = True errIndex = [] index = 0 while bBreakFlag is False: self.check.clear() index = 0 tmpcoverpath = [] for item in aItemInfo: type = item['type'] item = item['item'] if type != 'track': continue index = index + 1 if bFirstTime is False: if self.check.isInErr(index - 1, errIndex) == False: continue streamInfo = self.tool.getStreamUrl( str(item['id']), self.config.quality) # streamInfo = self.tool.getStreamUrl(str(item['id']), 'DOLBY_ATMOS') if self.tool.errmsg != "" or not streamInfo: printErr( 14, item['title'] + "(Get Stream Url Err!!" + self.tool.errmsg + ")") continue aAlbumInfo = self.tool.getAlbum(item['album']['id']) fileType = self._getSongExtension(streamInfo['url']) # change targetDir targetDir2 = targetDir if self.config.plfile2arfolder == "True": targetDir2 = self.__creatAlbumDir(aAlbumInfo) filePath = self.__getAlbumSongSavePath( targetDir2, aAlbumInfo, item, fileType) paraList = { 'album': aAlbumInfo, 'title': item['title'], 'trackinfo': item, 'url': streamInfo['url'], 'path': filePath, 'retry': 3, 'key': streamInfo['encryptionKey'] } else: seq = self.tool.getIndexStr(index, len(aItemInfo)) filePath = targetDir2 + '/' + seq + " " + pathHelper.replaceLimitChar( item['title'], '-') + fileType paraList = { 'album': aAlbumInfo, 'index': index, 'title': item['title'], 'trackinfo': item, 'url': streamInfo['url'], 'path': filePath, 'retry': 3, 'key': streamInfo['encryptionKey'] } try: coverPath = targetDir2 + '/' + pathHelper.replaceLimitChar( aAlbumInfo['title'], '-') + '.jpg' coverUrl = self.tool.getAlbumArtworkUrl( aAlbumInfo['cover']) netHelper.downloadFile(coverUrl, coverPath) paraList['coverpath'] = coverPath tmpcoverpath.append(coverPath) except: cmdHelper.myprint( "Could not download artwork for '{}'".format( item['title']), cmdHelper.TextColor.Red, None) if self.config.onlym4a == "True": self.check.addPath(filePath.replace(".mp4", ".m4a")) else: self.check.addPath(filePath) self.thread.start(self.__thradfunc_dl, paraList) self.thread.waitAll() self.tool.removeTmpFile(targetDir) # remove cover if self.config.savephoto != 'True': for item in tmpcoverpath: pathHelper.remove(item) bBreakFlag = True bFirstTime = False # check isErr, errIndex = self.check.checkPaths() if isErr: check = printChoice( "[Err]\t\t" + str(len(errIndex)) + " Tracks Download Failed.Try Again?(y/n):") if check == 'y' or check == 'Y': bBreakFlag = False # download video for item in aItemInfo: type = item['type'] item = item['item'] if type != 'video': continue filePath = targetDir + '/' + pathHelper.replaceLimitChar( item['title'], '-') + ".mp4" filePath = os.path.abspath(filePath) if os.access(filePath, 0): os.remove(filePath) videoID = item['id'] resolutionList, urlList = self.tool.getVideoResolutionList( videoID) if urlList is None: printErr(14, item['title'] + '(' + self.tool.errmsg + ')') else: selectIndex = self.__getVideoResolutionIndex( resolutionList) if self.ffmpeg.mergerByM3u8_Multithreading2( urlList[int(selectIndex)], filePath, showprogress=self.showpro): printSUCCESS(14, item['title']) else: printErr(14, item['title'] + "(Download Or Merger Err!)") if playlist_id is not None: return return
def printWarring(length, elsestr): cmdHelper.myprint("[WARRING]".ljust(length), cmdHelper.TextColor.Red, None) print(elsestr)
def printMenu(): print("=====================Choice=========================") cmdHelper.myprint(" Enter '0' : ", cmdHelper.TextColor.Green, None) print("Exit.") cmdHelper.myprint(" Enter '1' : ", cmdHelper.TextColor.Green, None) print("LogIn And Get SessionID.") cmdHelper.myprint(" Enter '2' : ", cmdHelper.TextColor.Green, None) print("Change Settings.") cmdHelper.myprint(" Enter '3' : ", cmdHelper.TextColor.Green, None) print("Download an Album.") cmdHelper.myprint(" Enter '4' : ", cmdHelper.TextColor.Green, None) print("Download a Track.") cmdHelper.myprint(" Enter '5' : ", cmdHelper.TextColor.Green, None) print("Download a PlayList.") cmdHelper.myprint(" Enter '6' : ", cmdHelper.TextColor.Green, None) print("Download a Video.") cmdHelper.myprint(" Enter '7' : ", cmdHelper.TextColor.Green, None) print("Download a Favorite.") cmdHelper.myprint(" Enter '8' : ", cmdHelper.TextColor.Green, None) print("Download All Albums by an Artist.") cmdHelper.myprint(" Enter '9' : ", cmdHelper.TextColor.Green, None) print("Show Current Config.") cmdHelper.myprint(" Enter URL : ", cmdHelper.TextColor.Green, None) print("Download By URL.") cmdHelper.myprint(" Enter Path: ", cmdHelper.TextColor.Green, None) print("Download By File.") print("====================================================")
def printErr(length, elsestr): if systemHelper.isLinux(): cmdHelper.myprint("[ERR]".ljust(length), cmdHelper.TextColor.Red, None) print(elsestr) else: print("[ERR]".ljust(length) + elsestr)
def printMenu(): if systemHelper.isLinux(): print("=====================Choice=========================") cmdHelper.myprint(" Enter '0': ", cmdHelper.TextColor.Green, None) print("Exit.") cmdHelper.myprint(" Enter '1': ", cmdHelper.TextColor.Green, None) print("LogIn And Get SessionID.") cmdHelper.myprint(" Enter '2': ", cmdHelper.TextColor.Green, None) print("Setting(OutputDir/Quality/ThreadNum).") cmdHelper.myprint(" Enter '3': ", cmdHelper.TextColor.Green, None) print("Download Album.") cmdHelper.myprint(" Enter '4': ", cmdHelper.TextColor.Green, None) print("Download Track.") cmdHelper.myprint(" Enter '5': ", cmdHelper.TextColor.Green, None) print("Download PlayList.") cmdHelper.myprint(" Enter '6': ", cmdHelper.TextColor.Green, None) print("Download Video.") cmdHelper.myprint(" Enter '7': ", cmdHelper.TextColor.Green, None) print("Download Favorite.") print("====================================================") else: print("=====================Choice=========================") print(" Enter '0' : Exit") print(" Enter '1' : LogIn And Get SessionID.") print(" Enter '2' : Setting(OutputDir/Quality/ThreadNum).") print(" Enter '3' : Download Album.") print(" Enter '4' : Download Track.") print(" Enter '5' : Download PlayList.") print(" Enter '6' : Download Video") print(" Enter '7' : Download Favorite") print("====================================================")
def printInfo(length, elsestr): cmdHelper.myprint("[INFO]".ljust(length), cmdHelper.TextColor.Yellow, None) print(elsestr)