()
| 780 | return [] |
| 781 | |
| 782 | async def main(): |
| 783 | x_urls = [] |
| 784 | for url in urls: |
| 785 | url = url.strip() |
| 786 | ip_start_index = url.find("//") + 2 |
| 787 | ip_end_index = url.find(":", ip_start_index) |
| 788 | ip_dot_start = url.find(".") + 1 |
| 789 | ip_dot_second = url.find(".", ip_dot_start) + 1 |
| 790 | ip_dot_three = url.find(".", ip_dot_second) + 1 |
| 791 | base_url = url[:ip_start_index] |
| 792 | ip_address = url[ip_start_index:ip_dot_three] |
| 793 | port = url[ip_end_index:] |
| 794 | ip_end = "1" |
| 795 | modified_ip = f"{ip_address}{ip_end}" |
| 796 | x_url = f"{base_url}{modified_ip}{port}" |
| 797 | x_urls.append(x_url) |
| 798 | unique_urls = set(x_urls) |
| 799 | |
| 800 | semaphore = asyncio.Semaphore(500) |
| 801 | async with aiohttp.ClientSession() as session: |
| 802 | valid_urls = await check_urls(session, unique_urls, semaphore) |
| 803 | all_results = [] |
| 804 | tasks = [] |
| 805 | for url in valid_urls: |
| 806 | task = asyncio.create_task(fetch_json(session, url, semaphore)) |
| 807 | tasks.append(task) |
| 808 | results = await asyncio.gather(*tasks) |
| 809 | for sublist in results: |
| 810 | all_results.extend(sublist) |
| 811 | |
| 812 | |
| 813 | eventlet.monkey_patch() |
| 814 | task_queue = eventlet.Queue() |
| 815 | results = [] |
| 816 | error_channels = [] |
| 817 | |
| 818 | def worker(): |
| 819 | while True: |
| 820 | # 从队列中获取一个任务 |
| 821 | channel_name, channel_url = task_queue.get() |
| 822 | try: |
| 823 | channel_url_t = channel_url.rstrip(channel_url.split('/')[-1]) # m3u8链接前缀 |
| 824 | lines = requests.get(channel_url, timeout=1).text.strip().split('\n') # 获取m3u8文件内容 |
| 825 | ts_lists = [line.split('/')[-1] for line in lines if line.startswith('#') == False] # 获取m3u8文件下视频流后缀 |
| 826 | ts_lists_0 = ts_lists[0].rstrip(ts_lists[0].split('.ts')[-1]) # m3u8链接前缀 |
| 827 | ts_url = channel_url_t + ts_lists[0] # 拼接单个视频片段下载链接 |
| 828 | |
| 829 | # 多获取的视频数据进行5秒钟限制 |
| 830 | with eventlet.Timeout(5, False): |
| 831 | start_time = datetime.datetime.now().timestamp() |
| 832 | content = requests.get(ts_url, timeout=1).content |
| 833 | end_time = datetime.datetime.now().timestamp() |
| 834 | response_time = (end_time - start_time) * 1 |
| 835 | |
| 836 | if content: |
| 837 | with open(ts_lists_0, 'ab') as f: |
| 838 | f.write(content) # 写入文件 |
| 839 | file_size = len(content) |
no test coverage detected