def _downloadHls(self, urls, fileName, headers={}, subtitleUrl=None): print("-- dispatcher/downloadHls") print('匹配到%d段视频,开始下载' % len(urls)) tempFileBase = os.path.join(self.tempFilePath, fileName) fileNames = tools.generateFileNames(urls, tempFileBase) finalFileName = os.path.join(self.videoFilePath, fileName + '.mp4') self.downloader.downloadAll(urls, fileNames, headers, self.hlsThreadCnt) concat, subtitlePath = True, None if subtitleUrl: # 存在字幕文件时,使用二进制合并以生成正确的时间戳 concat = False subtitlePath = os.path.join( self.tempFilePath, fileName + tools.getSuffix(subtitleUrl)) self.downloader.directDownload(subtitleUrl, subtitlePath, headers) tools.mergePartialVideos(fileNames, finalFileName, concat=concat, subtitlePath=subtitlePath) if not self.saveTempFile: tools.removeFiles(fileNames) subtitleUrl and tools.removeFiles(subtitlePath) print('完成\n')
def _downloadDash(self, audioUrls, videoUrls, fileName, headers={}): print("-- dispatcher/downloadDash") tempAudioBase = tools.join(self.tempFilePath, fileName + '.audio') tempVideoBase = tools.join(self.tempFilePath, fileName + '.video') audioNames = tools.generateFileNames(audioUrls, tempAudioBase) videoNames = tools.generateFileNames(videoUrls, tempVideoBase) targetFileName = tools.join(self.videoFilePath, fileName + '.mp4') self.downloader.multiThreadDownloadAll(audioUrls, audioNames, headers, \ self.fragThreadCnt, self.fragmentCnt) self.downloader.multiThreadDownloadAll(videoUrls, videoNames, headers, \ self.fragThreadCnt, self.fragmentCnt) tools.mergeAudio2Video(audioNames, videoNames, targetFileName) self.saveTempFile or tools.removeFiles(audioNames + videoNames) return targetFileName
def _downloadDash(self, audioUrls, videoUrls, fileName, headers={}): print("-- dispatcher/downloadDash") print('匹配到%d段音频和%d段视频,开始下载' % (len(audioUrls), len(videoUrls))) tempAudioBase = os.path.join(self.tempFilePath, fileName + '.audio') tempVideoBase = os.path.join(self.tempFilePath, fileName + '.video') audioNames = tools.generateFileNames(audioUrls, tempAudioBase) videoNames = tools.generateFileNames(videoUrls, tempVideoBase) fileName = os.path.join(self.videoFilePath, fileName + '.mp4') self.downloader.multiThreadDownloadAll(audioUrls, audioNames, headers, \ self.fragThreadCnt, self.fragmentCnt) self.downloader.multiThreadDownloadAll(videoUrls, videoNames, headers, \ self.fragThreadCnt, self.fragmentCnt) tools.mergeAudio2Video(audioNames, videoNames, fileName) self.saveTempFile or tools.removeFiles(audioNames + videoNames) print('完成\n')
def _downloadHls(self, urls, fileName, headers = {}): print("-- dispatcher/downloadHls") print('匹配到%d段视频,开始下载' % len(urls)) tempFileBase = os.path.join(self.tempFilePath, fileName) fileNames = tools.generateFileNames(urls, tempFileBase) fileName = os.path.join(self.videoFilePath, fileName + '.mp4') self.downloader.downloadAll(urls, fileNames, headers, self.hlsThreadCnt) tools.mergePartialVideos(fileNames, fileName) self.saveTempFile or tools.removeFiles(fileNames) print('完成\n')
def _downloadHls(self, urls, fileName, headers={}, concat=True): print("-- dispatcher/downloadHls") tempFileBase = tools.join(self.tempFilePath, fileName) fileNames = tools.generateFileNames(urls, tempFileBase) targetFileName = tools.join(self.videoFilePath, fileName + '.mp4') self.downloader.downloadAll(urls, fileNames, headers, self.hlsThreadCnt) tools.mergePartialVideos(fileNames, targetFileName, concat=concat) self.saveTempFile or tools.removeFiles(fileNames) return targetFileName
def _downloadPartialVideos(self, urls, fileName, headers={}): print("-- dispatcher/downloadPartialVideos") tempFileBase = tools.join(self.tempFilePath, fileName) fileNames = tools.generateFileNames(urls, tempFileBase) suffix = tools.getSuffix(urls[0]) targetFileName = tools.join(self.videoFilePath, fileName + suffix) for i, url in enumerate(urls): self.downloader.multiThreadDownload(url, fileNames[i], headers, \ self.fragThreadCnt, self.fragmentCnt) tools.mergePartialVideos(fileNames, targetFileName) self.saveTempFile or tools.removeFiles(fileNames) return targetFileName