def encrypted(stream, srcPath, descPath): if aigpy.string.isNull(stream.encryptionKey): os.replace(srcPath, descPath) else: key, nonce = decrypt_security_token(stream.encryptionKey) decrypt_file(srcPath, descPath, key, nonce) os.remove(srcPath)
def __downloadTrack__(conf, track, album=None, playlist=None): msg, stream = API.getStreamUrl(track.id, conf.audioQuality) if not isNull(msg): Printf.err(track.title + "." + msg) return path = __getTrackPath__(conf, track, stream, album, playlist) # Printf.info("Download \"" + track.title + "\" Codec: " + stream.codec) check, err = downloadFileRetErr(stream.url, path + '.part', showprogress=True, stimeout=20) if not check: Printf.err("\n Download failed!" + getFileName(path)) return # encrypted -> decrypt and remove encrypted file if isNull(stream.encryptionKey): os.replace(path + '.part', path) else: key, nonce = decrypt_security_token(stream.encryptionKey) decrypt_file(path + '.part', path, key, nonce) os.remove(path + '.part') path = __convertToM4a__(path, stream.codec) __setMetaData__(track, album, path) Printf.success(getFileName(path))
def __thradfunc_dl(self, paraList): count = 1 printRet = True pstr = paraList['title'] + "(Download Err!)" redownload = True needDl = True bIsSuccess = False albumInfo = None index = None coverpath = None if 'redownload' in paraList: redownload = paraList['redownload'] if 'retry' in paraList: count = count + paraList['retry'] if 'show' in paraList: printRet = paraList['show'] if 'album' in paraList: albumInfo = paraList['album'] if 'index' in paraList: index = paraList['index'] if 'coverpath' in paraList: coverpath = paraList['coverpath'] if redownload is False: needDl = self.__isNeedDownload(paraList['path'], paraList['url']) if needDl: try: while count > 0: count = count - 1 check = netHelper.downloadFile(paraList['url'], paraList['path']) if check is True: if paraList['key'] == '': break key, nonce = decrypt_security_token(paraList['key']) decrypt_file(paraList['path'], key, nonce) break if check: self.tool.setTrackMetadata(paraList['trackinfo'], paraList['path'], albumInfo, index, coverpath) pstr = paraList['title'] bIsSuccess = True except: pass else: pstr = paraList['title'] bIsSuccess = True if printRet: if (bIsSuccess): printSUCCESS(14, pstr) else: printErr(14, pstr) return
def __downloadTrack__(conf: Settings, track: Track, album=None, playlist=None): try: if track.allowStreaming is False: Printf.err("Download failed! " + track.title + ' not allow streaming.') return msg, stream = API.getStreamUrl(track.id, conf.audioQuality) Printf.track(track, stream) if not aigpy.string.isNull(msg) or stream is None: Printf.err(track.title + "." + msg) return path = __getTrackPath__(conf, track, stream, album, playlist) # check exist if conf.checkExist and __isNeedDownload__(path, stream.url) == False: Printf.success( aigpy.path.getFileName(path) + " (skip:already exists!)") return logging.info("[DL Track] name=" + aigpy.path.getFileName(path) + "\nurl=" + stream.url) tool = aigpy.download.DownloadTool(path + '.part', [stream.url]) check, err = tool.start(conf.showProgress) if not check: Printf.err("Download failed! " + aigpy.path.getFileName(path) + ' (' + str(err) + ')') return # encrypted -> decrypt and remove encrypted file if aigpy.string.isNull(stream.encryptionKey): os.replace(path + '.part', path) else: key, nonce = decrypt_security_token(stream.encryptionKey) decrypt_file(path + '.part', path, key, nonce) os.remove(path + '.part') path = __convertToM4a__(path, stream.codec) # contributors contributors = API.getTrackContributors(track.id) lyrics = '' if conf.addLyrics: lyrics = __getLyrics__(track.title, track.artists[0].name, conf.lyricsServerProxy) __setMetaData__(track, album, path, contributors, lyrics) Printf.success(aigpy.path.getFileName(path)) except Exception as e: Printf.err("Download failed! " + track.title + ' (' + str(e) + ')')
def __downloadTrack__(conf: Settings, track, album=None, playlist=None): try: msg, stream = API.getStreamUrl(track.id, conf.audioQuality) if not isNull(msg) or stream is None: Printf.err(track.title + "." + msg) return path = __getTrackPath__(conf, track, stream, album, playlist) # check exist if conf.checkExist and __isNeedDownload__(path, stream.url) == False: playSong(track, path) Printf.success(getFileName(path) + " (skip:already exists!)") return # Printf.info("Download \"" + track.title + "\" Codec: " + stream.codec) if conf.multiThreadDownload: check, err = downloadFileMultiThread( stream.url, path + '.part', stimeout=20, showprogress=conf.showProgress) else: check, err = downloadFile(stream.url, path + '.part', stimeout=20, showprogress=conf.showProgress) if not check: Printf.err("Download failed! " + getFileName(path) + ' (' + str(err) + ')') return # encrypted -> decrypt and remove encrypted file if isNull(stream.encryptionKey): os.replace(path + '.part', path) else: key, nonce = decrypt_security_token(stream.encryptionKey) decrypt_file(path + '.part', path, key, nonce) os.remove(path + '.part') path = __convertToM4a__(path, stream.codec) # contributors contributors = API.getTrackContributors(track.id) __setMetaData__(track, album, path, contributors) # Printf.success(getFileName()) playSong(track, path) except Exception as e: Printf.err("Download failed! " + track.title + ' (' + str(e) + ')')
def __thradfunc_dl(self, paraList): count = 1 printRet = True pstr = paraList['title'] + "(Download Err!)" redownload = True needDl = True bIsSuccess = False albumInfo = None index = None coverpath = None if 'redownload' in paraList: redownload = paraList['redownload'] if 'retry' in paraList: count = count + paraList['retry'] if 'show' in paraList: printRet = paraList['show'] if 'album' in paraList: albumInfo = paraList['album'] if 'index' in paraList: index = paraList['index'] if 'coverpath' in paraList: coverpath = paraList['coverpath'] if redownload is False: needDl = self.__isNeedDownload(paraList['path'], paraList['url']) # DEBUG # self.tool.setTrackMetadata(paraList['trackinfo'], paraList['path'], albumInfo, index, coverpath) showprogress = False if int(self.config.threadnum) <= 1 and self.showpro: showprogress = True Contributors = self.tool.getTrackContributors( paraList['trackinfo']['id']) if needDl: try: while count > 0: count = count - 1 check = netHelper.downloadFile(paraList['url'], paraList['path'] + '.part', showprogress=showprogress, stimeout=20) if check is True: if paraList['key'] == '': # unencrypted -> just move into place os.replace(paraList['path'] + '.part', paraList['path']) break else: # encrypted -> decrypt and remove encrypted file key, nonce = decrypt_security_token( paraList['key']) decrypt_file(paraList['path'] + '.part', paraList['path'], key, nonce) os.remove(paraList['path'] + '.part') break if check: bIsSuccess = True paraList['path'] = self.tool.covertMp4toM4a( paraList['path']) self.tool.setTrackMetadata(paraList['trackinfo'], paraList['path'], albumInfo, index, coverpath, Contributors) pstr = paraList['title'] except Exception as e: printErr(14, str(e) + " while downloading " + paraList['url']) else: pstr = paraList['title'] bIsSuccess = True if printRet: if (bIsSuccess): printSUCCESS(14, pstr) else: printErr(14, pstr) return