def downloadArtistAlbum(self, includeSingles=True, artistID=None): while True: print("-------------ARTIST ALBUM--------------") if artistID is not None: sID = artistID else: sID = printChoice("Enter Artist ID(Enter '0' go back):", True, 0) if sID == 0: return array = self.tool.getArtistAlbum(sID, includeSingles) if self.tool.errmsg != "": printErr(0, "Get AlbumList Err! " + self.tool.errmsg) continue redownload = True if artistID is None: check = printChoice("Skip downloaded files?(y/n):") if not cmdHelper.isInputYes(check): redownload = False for index, item in enumerate(array): print("----Album[{0}/{1}]----".format(index + 1, len(array))) self.downloadAlbum(item['id'], redownload) if artistID is not None: # Break out of the function if we are only downloading one artist's albums return
def downloadByFile(self, path): if not os.path.exists(path): return arr = self.tool.parseFile(path) print("----------------FILE------------------") print("[Number of albums] %s" % (len(arr['album']))) print("[Number of artists] %s" % (len(arr['artist']))) print("[Number of tracks] %s" % (len(arr['track']))) print("[Number of videos] %s" % (len(arr['video']))) print("[Number of URLs] %s" % (len(arr['url']))) if len(arr['album']) > 0: redownload = True check = printChoice("Skip downloaded files?(y/n):") if not cmdHelper.isInputYes(check): redownload = False for index, item in enumerate(arr['album']): print("----Album[{0}/{1}]----".format(index + 1, len(arr['album']))) print("[ID] %s" % (item)) self.downloadAlbum(item, redownload) for index, item in enumerate(arr['artist']): print(index) print("----Artist[{0}/{1}]----".format(index + 1, len(arr['artist']))) print("[ID] %s" % (item)) includeSingles = self.config.includesingle == "True" self.downloadArtistAlbum(includeSingles, item) for index, item in enumerate(arr['track']): print("----Track[{0}/{1}]----".format(index + 1, len(arr['track']))) print("[ID] %s" % (item)) self.downloadTrack(item) for index, item in enumerate(arr['video']): print("----Video[{0}/{1}]----".format(index + 1, len(arr['video']))) print("[ID] %s" % (item)) self.downloadVideo(item) for index, item in enumerate(arr['url']): print("----Url[{0}/{1}]----".format(index + 1, len(arr['url']))) print("[link] %s" % (item)) stype, sid = self.tool.parseLink(item) if stype is None or sid is None: printErr(14, 'Link can`t parse!') continue print("[ID] %s" % (sid)) if stype == "album": print("[Type] %s" % ("album")) self.downloadAlbum(sid) if stype == "track": print("[Type] %s" % ("track")) self.downloadTrack(sid) if stype == "video": print("[Type] %s" % ("video")) self.downloadVideo(sid)
def downloadArtistAlbum(self): while True: print("-------------ARTIST ALBUM--------------") sID = printChoice("Enter ArtistID(Enter '0' go back):", True, 0) if sID == 0: return array = self.tool.getArtistAlbum(sID) if self.tool.errmsg != "": printErr(0, "Get AlbumList Err! " + self.tool.errmsg) continue redownload = True check = printChoice("Skip downloaded files?(y/n):") if not cmdHelper.isInputYes(check): redownload = False for index, item in enumerate(array): print("----Album[{0}/{1}]----".format(index + 1, len(array))) self.downloadAlbum(item['id'], redownload)
def downloadAlbum(self, album_id=None, redl_flag=None): while_count = 9999 while while_count > 0: while_count -= 1 if album_id is not None: while_count = 0 sID = album_id else: print("----------------ALBUM------------------") sID = printChoice("Enter AlbumID(Enter '0' go back):", True, 0) if sID == 0: return aAlbumInfo = self.tool.getAlbum(sID) if self.tool.errmsg != "": printErr(0, "Get AlbumInfo Err! " + self.tool.errmsg) continue print("[Title] %s" % (aAlbumInfo['title'])) print("[SongNum] %s\n" % (aAlbumInfo['numberOfTracks'])) # Get Tracks aAlbumTracks = self.tool.getAlbumTracks(sID) if self.tool.errmsg != "": printErr(0, "Get AlbumTracks Err!" + self.tool.errmsg) continue aAlbumVideos = self.tool.getAlbumVideos(sID) # Creat OutputDir targetDir = self.__creatAlbumDir(aAlbumInfo) # write msg string = self.tool.convertAlbumInfoToString( aAlbumInfo, aAlbumTracks) with codecs.open(targetDir + "/AlbumInfo.txt", 'w', 'utf-8') as fd: fd.write(string) # download cover coverPath = targetDir + '/' + pathHelper.replaceLimitChar( aAlbumInfo['title'], '-') + '.jpg' if aAlbumInfo['cover'] is not None: coverUrl = self.tool.getAlbumArtworkUrl(aAlbumInfo['cover']) netHelper.downloadFile(coverUrl, coverPath) # check exist files redownload = True if redl_flag is None: existFiles = pathHelper.getDirFiles(targetDir) for item in existFiles: if '.txt' in item: continue if '.jpg' in item: continue check = printChoice( "Some tracks already exist. Redownload?(y/n):") if not cmdHelper.isInputYes(check): redownload = False break else: redownload = redl_flag # download album tracks for item in aAlbumTracks['items']: streamInfo = self.tool.getStreamUrl(str(item['id']), self.config.quality) if self.tool.errmsg != "" or not streamInfo: printErr( 14, item['title'] + "(Get Stream Url Err!" + self.tool.errmsg + ")") continue fileType = self._getSongExtension(streamInfo['url']) filePath = self.__getAlbumSongSavePath(targetDir, aAlbumInfo, item, fileType) paraList = { 'album': aAlbumInfo, 'redownload': redownload, 'title': item['title'], 'trackinfo': item, 'url': streamInfo['url'], 'path': filePath, 'retry': 3, 'key': streamInfo['encryptionKey'], 'coverpath': coverPath } self.thread.start(self.__thradfunc_dl, paraList) # wait all download thread self.thread.waitAll() self.tool.removeTmpFile(targetDir) # remove cover if self.config.savephoto != 'True': pathHelper.remove(coverPath) # download video for item in aAlbumVideos: item = item['item'] filePath = targetDir + '/' + pathHelper.replaceLimitChar( item['title'], '-') + ".mp4" filePath = os.path.abspath(filePath) if os.access(filePath, 0): os.remove(filePath) try: resolutionList, urlList = self.tool.getVideoResolutionList( item['id']) 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']) except: printErr(14, item['title']) # return return