예제 #1
0
def analyseArgs(args):
    """
    检测传入的参数,返回字典形式的参数列表,如果有检测失败的则返回None
    :param args: 参数
    :return: 无
    """
    if args.url is None:
        print('error: the following arguments are required: URL')
        return None

    Configuration.url = args.url
    Configuration.name = args.name
    Configuration.thread = args.thread
    Configuration.outPath = args.outpath
    Configuration.begin = args.begin
    Configuration.end = args.end
    Configuration.slice = args.slice
    Configuration.timeout = args.timeout
    Configuration.temp = args.temp

    # 简单判断一下url
    if not TextUtil.isUrl(Configuration.url):
        print('error: "%s" is not a correct URL' % Configuration.url)
        print('please check the link for incorrect input')
        return None

    # 名字
    if Configuration.name is None:
        Configuration.name = 'index.ts'
        pass

    # 路径
    if Configuration.outPath is None:
        Configuration.outPath = OSUtil.getPath()
        pass
    elif not TextUtil.isPath(Configuration.outPath):
        print('error: "%s" is not a correct path' % Configuration.outPath)
        return None
        pass

    # 线程数
    if not 0 < Configuration.thread < 256:
        print(
            'error: the number of threads must be greater than 0 and less than or equal to 256'
        )
        return None

    pass
예제 #2
0
    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
예제 #3
0
def analyseArgs(args):
    dit = {
        'url': args.url[0],
        'name': args.name,
        'thread': args.thread,
        'path': args.output
    }

    # 简单判断一下url
    if not TextUtil.isUrl(dit['url']):
        print('error: "%s" is not a correct URL' % dit['url'])
        print('please check the link for incorrect input')
        return None

    # 名字
    if dit['name'] is None:
        dit['name'] = 'index.ts'
        pass

    # 路径
    if dit['path'] is None:
        dit['path'] = OSUtil.getPath()
        pass
    elif not TextUtil.isPath(dit['path']):
        print('error: "%s" is not a correct path' % dit['path'])
        return None
        pass

    # 线程数
    if not 0 < dit['thread'] < 129:
        print(
            'error: the number of threads must be greater than 0 and less than or equal to 128'
        )
        return None

    return dit
예제 #4
0
    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
예제 #5
0
 def __getSpeed(self):
     return TextUtil.byte2Speed(int(self.dataPerInterval / self.interval))
     pass
예제 #6
0
 def __getDuration(self):
     return TextUtil.formatTime(time.time() - self.startTime)
     pass