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')
Exemplo n.º 2
0
    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')
Exemplo n.º 3
0
    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
Exemplo n.º 4
0
    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