def __getList(self): """ 匹配类似下面的序列 #EXTINF:1.000000, xxxxxxxxx.ts """ self.__innerUrlPre = getPre(self.__innerUrl) reg = r'#EXTINF:(.*?),\n(.*?\.ts)' res = re.findall(reg, self.__content) self.__tsList = [] i = 0 for item in res: duration = float(item[0]) self.__tsList.append({ 'index': i, 'name': item[1], 'duration': duration, 'url': self.__innerUrlPre + item[1] }) # 依次相加时长 self.__durationSec += duration i += 1 pass # 计算时长 self.__duration = TextUrl.formatTime(self.getDurationSecond()) return self.__tsList
def download(self): print('output: [' + self.outPath + ']') self.startTime = time.time() # 在路径里创建临时文件夹 os.mkdir(self.tmpPath) # 开启线程池进行下载 executor = ThreadPoolExecutor(max_workers=self.maxWorkers) for tmp in self.tsList: executor.submit(self._download, tmp) pass # 显示进度 self.showProgress() executor.shutdown() self.endTime = time.time() print('download complete, took %s' % TextUtil.formatTime(self.endTime - self.startTime)) self.merge() pass
def __getDuration(self): return TextUtil.formatTime(time.time() - self.startTime) pass