itv_all(1080).py 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. import time
  2. import concurrent.futures
  3. from selenium import webdriver
  4. from selenium.webdriver.chrome.options import Options
  5. import requests
  6. import re
  7. import os
  8. import threading
  9. from queue import Queue
  10. urls = [
  11. "https://fofa.info/result?qbase64=ImlwdHYvbGl2ZS96aF9jbi5qcyIgJiYgY291bnRyeT0iQ04iICYmIHJlZ2lvbj0iSGViZWki", # Hebei (河北)
  12. "https://fofa.info/result?qbase64=ImlwdHYvbGl2ZS96aF9jbi5qcyIgJiYgY291bnRyeT0iQ04iICYmIHJlZ2lvbj0iYmVpamluZyI%3D", # Beijing (北京)
  13. "https://fofa.info/result?qbase64=ImlwdHYvbGl2ZS96aF9jbi5qcyIgJiYgY291bnRyeT0iQ04iICYmIHJlZ2lvbj0iZ3Vhbmdkb25nIg%3D%3D", # Guangdong (广东)
  14. "https://fofa.info/result?qbase64=ImlwdHYvbGl2ZS96aF9jbi5qcyIgJiYgY291bnRyeT0iQ04iICYmIHJlZ2lvbj0ic2hhbmdoYWki", # Shanghai (上海)
  15. "https://fofa.info/result?qbase64=ImlwdHYvbGl2ZS96aF9jbi5qcyIgJiYgY291bnRyeT0iQ04iICYmIHJlZ2lvbj0idGlhbmppbiI%3D", # Tianjin (天津)
  16. "https://fofa.info/result?qbase64=ImlwdHYvbGl2ZS96aF9jbi5qcyIgJiYgY291bnRyeT0iQ04iICYmIHJlZ2lvbj0iY2hvbmdxaW5nIg%3D%3D", # Chongqing (重庆)
  17. "https://fofa.info/result?qbase64=ImlwdHYvbGl2ZS96aF9jbi5qcyIgJiYgY291bnRyeT0iQ04iICYmIHJlZ2lvbj0ic2hhbnhpIg%3D%3D", # Shanxi (山西)
  18. "https://fofa.info/result?qbase64=ImlwdHYvbGl2ZS96aF9jbi5qcyIgJiYgY291bnRyeT0iQ04iICYmIHJlZ2lvbj0iU2hhYW54aSI%3D", # Shaanxi (陕西)
  19. "https://fofa.info/result?qbase64=ImlwdHYvbGl2ZS96aF9jbi5qcyIgJiYgY291bnRyeT0iQ04iICYmIHJlZ2lvbj0ibGlhb25pbmci", # Liaoning (辽宁)
  20. "https://fofa.info/result?qbase64=ImlwdHYvbGl2ZS96aF9jbi5qcyIgJiYgY291bnRyeT0iQ04iICYmIHJlZ2lvbj0iamlhbmdzdSI%3D", # Jiangsu (江苏)
  21. "https://fofa.info/result?qbase64=ImlwdHYvbGl2ZS96aF9jbi5qcyIgJiYgY291bnRyeT0iQ04iICYmIHJlZ2lvbj0iemhlamlhbmci", # Zhejiang (浙江)
  22. "https://fofa.info/result?qbase64=ImlwdHYvbGl2ZS96aF9jbi5qcyIgJiYgY291bnRyeT0iQ04iICYmIHJlZ2lvbj0i5a6J5b69Ig%3D%3D", # Anhui (安徽)
  23. "https://fofa.info/result?qbase64=ImlwdHYvbGl2ZS96aF9jbi5qcyIgJiYgY291bnRyeT0iQ04iICYmIHJlZ2lvbj0iRnVqaWFuIg%3D%3D", # 福建
  24. "https://fofa.info/result?qbase64=ImlwdHYvbGl2ZS96aF9jbi5qcyIgJiYgY291bnRyeT0iQ04iICYmIHJlZ2lvbj0i5rGf6KW%2FIg%3D%3D", # 江西
  25. "https://fofa.info/result?qbase64=ImlwdHYvbGl2ZS96aF9jbi5qcyIgJiYgY291bnRyeT0iQ04iICYmIHJlZ2lvbj0i5bGx5LicIg%3D%3D", # 山东
  26. "https://fofa.info/result?qbase64=ImlwdHYvbGl2ZS96aF9jbi5qcyIgJiYgY291bnRyeT0iQ04iICYmIHJlZ2lvbj0i5rKz5Y2XIg%3D%3D", # 河南
  27. "https://fofa.info/result?qbase64=ImlwdHYvbGl2ZS96aF9jbi5qcyIgJiYgY291bnRyeT0iQ04iICYmIHJlZ2lvbj0i5rmW5YyXIg%3D%3D", # 湖北
  28. "https://fofa.info/result?qbase64=ImlwdHYvbGl2ZS96aF9jbi5qcyIgJiYgY291bnRyeT0iQ04iICYmIHJlZ2lvbj0i5rmW5Y2XIg%3D%3D", # 湖南
  29. "https://www.zoomeye.org/searchResult?q=%2Fiptv%2Flive%2Fzh_cn.js%20%2Bcountry%3A%22CN%22%20%2Bsubdivisions%3A%22hebei%22", #河北
  30. "https://www.zoomeye.org/searchResult?q=%2Fiptv%2Flive%2Fzh_cn.js%20%2Bcountry%3A%22CN%22%20%2Bsubdivisions%3A%22beijing%22", #北京
  31. "https://www.zoomeye.org/searchResult?q=%2Fiptv%2Flive%2Fzh_cn.js%20%2Bcountry%3A%22CN%22%20%2Bsubdivisions%3A%22guangdong%22", #广东
  32. "https://www.zoomeye.org/searchResult?q=%2Fiptv%2Flive%2Fzh_cn.js%20%2Bcountry%3A%22CN%22%20%2Bsubdivisions%3A%22shanghai%22", #上海
  33. "https://www.zoomeye.org/searchResult?q=%2Fiptv%2Flive%2Fzh_cn.js%20%2Bcountry%3A%22CN%22%20%2Bsubdivisions%3A%22tianjin%22", #天津
  34. "https://www.zoomeye.org/searchResult?q=%2Fiptv%2Flive%2Fzh_cn.js%20%2Bcountry%3A%22CN%22%20%2Bsubdivisions%3A%22chongqing%22", #重庆
  35. "https://www.zoomeye.org/searchResult?q=%2Fiptv%2Flive%2Fzh_cn.js%20%2Bcountry%3A%22CN%22%20%2Bsubdivisions%3A%22shanxi%22", #山西
  36. "https://www.zoomeye.org/searchResult?q=%2Fiptv%2Flive%2Fzh_cn.js%20%2Bcountry%3A%22CN%22%20%2Bsubdivisions%3A%22shaanxi%22", #陕西
  37. "https://www.zoomeye.org/searchResult?q=%2Fiptv%2Flive%2Fzh_cn.js%20%2Bcountry%3A%22CN%22%20%2Bsubdivisions%3A%22liaoning%22", #辽宁
  38. "https://www.zoomeye.org/searchResult?q=%2Fiptv%2Flive%2Fzh_cn.js%20%2Bcountry%3A%22CN%22%20%2Bsubdivisions%3A%22jiangsu%22", #江苏
  39. "https://www.zoomeye.org/searchResult?q=%2Fiptv%2Flive%2Fzh_cn.js%20%2Bcountry%3A%22CN%22%20%2Bsubdivisions%3A%22zhejiang%22", #浙江
  40. "https://www.zoomeye.org/searchResult?q=%2Fiptv%2Flive%2Fzh_cn.js%20%2Bcountry%3A%22CN%22%20%2Bsubdivisions%3A%22anhui%22", #安徽
  41. "https://www.zoomeye.org/searchResult?q=%2Fiptv%2Flive%2Fzh_cn.js%20%2Bcountry%3A%22CN%22%20%2Bsubdivisions%3A%22fujian%22", #福建
  42. "https://www.zoomeye.org/searchResult?q=%2Fiptv%2Flive%2Fzh_cn.js%20%2Bcountry%3A%22CN%22%20%2Bsubdivisions%3A%22jiangxi%22", #江西
  43. "https://www.zoomeye.org/searchResult?q=%2Fiptv%2Flive%2Fzh_cn.js%20%2Bcountry%3A%22CN%22%20%2Bsubdivisions%3A%22shandong%22", #山东
  44. "https://www.zoomeye.org/searchResult?q=%2Fiptv%2Flive%2Fzh_cn.js%20%2Bcountry%3A%22CN%22%20%2Bsubdivisions%3A%22henan%22", #河南
  45. "https://www.zoomeye.org/searchResult?q=%2Fiptv%2Flive%2Fzh_cn.js%20%2Bcountry%3A%22CN%22%20%2Bsubdivisions%3A%22hubei%22", #湖北
  46. "https://www.zoomeye.org/searchResult?q=%2Fiptv%2Flive%2Fzh_cn.js%20%2Bcountry%3A%22CN%22%20%2Bsubdivisions%3A%22hunan%22" #湖南
  47. ]
  48. def modify_urls(url):
  49. modified_urls = []
  50. ip_start_index = url.find("//") + 2
  51. ip_end_index = url.find(":", ip_start_index)
  52. base_url = url[:ip_start_index] # http:// or https://
  53. ip_address = url[ip_start_index:ip_end_index]
  54. port = url[ip_end_index:]
  55. ip_end = "/iptv/live/1000.json?key=txiptv"
  56. for i in range(1, 256):
  57. modified_ip = f"{ip_address[:-1]}{i}"
  58. modified_url = f"{base_url}{modified_ip}{port}{ip_end}"
  59. modified_urls.append(modified_url)
  60. return modified_urls
  61. def is_url_accessible(url):
  62. try:
  63. response = requests.get(url, timeout=0.5)
  64. if response.status_code == 200:
  65. return url
  66. except requests.exceptions.RequestException:
  67. pass
  68. return None
  69. results = []
  70. for url in urls:
  71. # 创建一个Chrome WebDriver实例
  72. chrome_options = Options()
  73. chrome_options.add_argument('--headless')
  74. chrome_options.add_argument('--no-sandbox')
  75. chrome_options.add_argument('--disable-dev-shm-usage')
  76. driver = webdriver.Chrome(options=chrome_options)
  77. # 使用WebDriver访问网页
  78. driver.get(url) # 将网址替换为你要访问的网页地址
  79. time.sleep(10)
  80. # 获取网页内容
  81. page_content = driver.page_source
  82. # 关闭WebDriver
  83. driver.quit()
  84. # 查找所有符合指定格式的网址
  85. pattern = r"http://\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d+" # 设置匹配的格式,如http://8.8.8.8:8888
  86. urls_all = re.findall(pattern, page_content)
  87. # urls = list(set(urls_all)) # 去重得到唯一的URL列表
  88. urls = set(urls_all) # 去重得到唯一的URL列表
  89. x_urls = []
  90. for url in urls: # 对urls进行处理,ip第四位修改为1,并去重
  91. url = url.strip()
  92. ip_start_index = url.find("//") + 2
  93. ip_end_index = url.find(":", ip_start_index)
  94. ip_dot_start = url.find(".") + 1
  95. ip_dot_second = url.find(".", ip_dot_start) + 1
  96. ip_dot_three = url.find(".", ip_dot_second) + 1
  97. base_url = url[:ip_start_index] # http:// or https://
  98. ip_address = url[ip_start_index:ip_dot_three]
  99. port = url[ip_end_index:]
  100. ip_end = "1"
  101. modified_ip = f"{ip_address}{ip_end}"
  102. x_url = f"{base_url}{modified_ip}{port}"
  103. x_urls.append(x_url)
  104. urls = set(x_urls) # 去重得到唯一的URL列表
  105. valid_urls = []
  106. # 多线程获取可用url
  107. with concurrent.futures.ThreadPoolExecutor(max_workers=100) as executor:
  108. futures = []
  109. for url in urls:
  110. url = url.strip()
  111. modified_urls = modify_urls(url)
  112. for modified_url in modified_urls:
  113. futures.append(executor.submit(is_url_accessible, modified_url))
  114. for future in concurrent.futures.as_completed(futures):
  115. result = future.result()
  116. if result:
  117. valid_urls.append(result)
  118. for url in valid_urls:
  119. print(url)
  120. # 遍历网址列表,获取JSON文件并解析
  121. for url in valid_urls:
  122. try:
  123. # 发送GET请求获取JSON文件,设置超时时间为0.5秒
  124. ip_start_index = url.find("//") + 2
  125. ip_dot_start = url.find(".") + 1
  126. ip_index_second = url.find("/", ip_dot_start)
  127. base_url = url[:ip_start_index] # http:// or https://
  128. ip_address = url[ip_start_index:ip_index_second]
  129. url_x = f"{base_url}{ip_address}"
  130. json_url = f"{url}"
  131. response = requests.get(json_url, timeout=0.5)
  132. json_data = response.json()
  133. try:
  134. # 解析JSON文件,获取name和url字段
  135. for item in json_data['data']:
  136. if isinstance(item, dict):
  137. name = item.get('name')
  138. urlx = item.get('url')
  139. if ',' in urlx:
  140. urlx=f"aaaaaaaa"
  141. #if 'http' in urlx or 'udp' in urlx or 'rtp' in urlx:
  142. if 'http' in urlx:
  143. urld = f"{urlx}"
  144. else:
  145. urld = f"{url_x}{urlx}"
  146. if name and urlx:
  147. # 删除特定文字
  148. name = name.replace("cctv", "CCTV")
  149. name = name.replace("中央", "CCTV")
  150. name = name.replace("央视", "CCTV")
  151. name = name.replace("高清", "")
  152. name = name.replace("超高", "")
  153. name = name.replace("HD", "")
  154. name = name.replace("标清", "")
  155. name = name.replace("频道", "")
  156. name = name.replace("-", "")
  157. name = name.replace(" ", "")
  158. name = name.replace("PLUS", "+")
  159. name = name.replace("+", "+")
  160. name = name.replace("(", "")
  161. name = name.replace(")", "")
  162. name = re.sub(r"CCTV(\d+)台", r"CCTV\1", name)
  163. name = name.replace("CCTV1综合", "CCTV1")
  164. name = name.replace("CCTV2财经", "CCTV2")
  165. name = name.replace("CCTV3综艺", "CCTV3")
  166. name = name.replace("CCTV4国际", "CCTV4")
  167. name = name.replace("CCTV4中文国际", "CCTV4")
  168. name = name.replace("CCTV4欧洲", "CCTV4")
  169. name = name.replace("CCTV5体育", "CCTV5")
  170. name = name.replace("CCTV6电影", "CCTV6")
  171. name = name.replace("CCTV7军事", "CCTV7")
  172. name = name.replace("CCTV7军农", "CCTV7")
  173. name = name.replace("CCTV7农业", "CCTV7")
  174. name = name.replace("CCTV7国防军事", "CCTV7")
  175. name = name.replace("CCTV8电视剧", "CCTV8")
  176. name = name.replace("CCTV9记录", "CCTV9")
  177. name = name.replace("CCTV9纪录", "CCTV9")
  178. name = name.replace("CCTV10科教", "CCTV10")
  179. name = name.replace("CCTV11戏曲", "CCTV11")
  180. name = name.replace("CCTV12社会与法", "CCTV12")
  181. name = name.replace("CCTV13新闻", "CCTV13")
  182. name = name.replace("CCTV新闻", "CCTV13")
  183. name = name.replace("CCTV14少儿", "CCTV14")
  184. name = name.replace("CCTV15音乐", "CCTV15")
  185. name = name.replace("CCTV16奥林匹克", "CCTV16")
  186. name = name.replace("CCTV17农业农村", "CCTV17")
  187. name = name.replace("CCTV17农业", "CCTV17")
  188. name = name.replace("CCTV5+体育赛视", "CCTV5+")
  189. name = name.replace("CCTV5+体育赛事", "CCTV5+")
  190. name = name.replace("CCTV5+体育", "CCTV5+")
  191. results.append(f"{name},{urld}")
  192. except:
  193. continue
  194. except:
  195. continue
  196. channels = []
  197. for result in results:
  198. line = result.strip()
  199. if result:
  200. channel_name, channel_url = result.split(',')
  201. channels.append((channel_name, channel_url))
  202. import eventlet
  203. eventlet.monkey_patch()
  204. # 线程安全的队列,用于存储下载任务
  205. task_queue = Queue()
  206. # 线程安全的列表,用于存储结果
  207. results = []
  208. error_channels = []
  209. # 定义工作线程函数
  210. def worker():
  211. while True:
  212. # 从队列中获取一个任务
  213. channel_name, channel_url = task_queue.get()
  214. try:
  215. response = requests.get(channel_url, timeout=1)
  216. if response.status_code == 200:
  217. channel_url_t = channel_url.rstrip(channel_url.split('/')[-1]) # m3u8链接前缀
  218. lines = requests.get(channel_url,timeout=1).text.strip().split('\n') # 获取m3u8文件内容
  219. ts_lists = [line.split('/')[-1] for line in lines if line.startswith('#') == False] # 获取m3u8文件下视频流后缀
  220. file_size = 0
  221. start_time = time.time()
  222. # 多获取的视频数据进行12秒钟限制
  223. with eventlet.Timeout(12, False):
  224. for i in range(len(ts_lists)):
  225. ts_url = channel_url_t + ts_lists[i] # 拼接单个视频片段下载链接
  226. response = requests.get(ts_url, stream=True, timeout=1)
  227. for chunk in response.iter_content(chunk_size=1024):
  228. if chunk:
  229. file_size += len(chunk)
  230. response.close()
  231. end_time = time.time()
  232. response_time = end_time - start_time
  233. if response_time >=12:
  234. file_size = 0
  235. download_speed = file_size / response_time / 1024
  236. normalized_speed =download_speed / 1024 # 将速率从kB/s转换为MB/s
  237. ts_url = channel_url_t + ts_lists[0] # 拼接单个视频片段下载链接
  238. if normalized_speed >= 1:
  239. if file_size >= 12000000:
  240. result = channel_name, channel_url, f"{normalized_speed:.3f} MB/s"
  241. results.append(result)
  242. numberx = (len(results) + len(error_channels)) / len(channels) * 100
  243. print(f"可用频道:{len(results)} , 网速:{normalized_speed:.3f} MB/s , 不可用频道:{len(error_channels)} 个 , 总频道:{len(channels)} 个 ,总进度:{numberx:.2f} %。")
  244. else:
  245. error_channel = channel_name, channel_url
  246. error_channels.append(error_channel)
  247. numberx = (len(results) + len(error_channels)) / len(channels) * 100
  248. print(f"可用频道:{len(results)} 个 , 不可用频道:{len(error_channels)} , 网速:{normalized_speed:.3f} MB/s , 总频道:{len(channels)} 个 ,总进度:{numberx:.2f} %。")
  249. else:
  250. error_channel = channel_name, channel_url
  251. error_channels.append(error_channel)
  252. numberx = (len(results) + len(error_channels)) / len(channels) * 100
  253. print(f"可用频道:{len(results)} 个 , 不可用频道:{len(error_channels)} , 网速:{normalized_speed:.3f} MB/s , 总频道:{len(channels)} 个 ,总进度:{numberx:.2f} %。")
  254. else:
  255. error_channel = channel_name, channel_url
  256. error_channels.append(error_channel)
  257. numberx = (len(results) + len(error_channels)) / len(channels) * 100
  258. print(
  259. f"可用频道:{len(results)} 个 , 不可用频道:{len(error_channels)} 个 , 总频道:{len(channels)} 个 ,总进度:{numberx:.2f} %。")
  260. except:
  261. error_channel = channel_name, channel_url
  262. error_channels.append(error_channel)
  263. numberx = (len(results) + len(error_channels)) / len(channels) * 100
  264. print(f"可用频道:{len(results)} 个 , 不可用频道:{len(error_channels)} 个 , 总频道:{len(channels)} 个 ,总进度:{numberx:.2f} %。")
  265. # 标记任务完成
  266. task_queue.task_done()
  267. # 创建多个工作线程
  268. num_threads = 10
  269. for _ in range(num_threads):
  270. t = threading.Thread(target=worker, daemon=True) # 将工作线程设置为守护线程
  271. t.start()
  272. # 添加下载任务到队列
  273. for channel in channels:
  274. task_queue.put(channel)
  275. # 等待所有任务完成
  276. task_queue.join()
  277. def channel_key(channel_name):
  278. match = re.search(r'\d+', channel_name)
  279. if match:
  280. return int(match.group())
  281. else:
  282. return float('inf') # 返回一个无穷大的数字作为关键字
  283. # 对频道进行排序
  284. results.sort(key=lambda x: (x[0], -float(x[2].split()[0])))
  285. results.sort(key=lambda x: channel_key(x[0]))
  286. result_counter = 8 # 每个频道需要的个数
  287. with open("itvlist.txt", 'w', encoding='utf-8') as file:
  288. channel_counters = {}
  289. file.write('央视频道,#genre#\n')
  290. for result in results:
  291. channel_name, channel_url, speed = result
  292. if 'CCTV' in channel_name:
  293. if channel_name in channel_counters:
  294. if channel_counters[channel_name] >= result_counter:
  295. continue
  296. else:
  297. file.write(f"{channel_name},{channel_url}\n")
  298. channel_counters[channel_name] += 1
  299. else:
  300. file.write(f"{channel_name},{channel_url}\n")
  301. channel_counters[channel_name] = 1
  302. channel_counters = {}
  303. file.write('卫视频道,#genre#\n')
  304. for result in results:
  305. channel_name, channel_url, speed = result
  306. if '卫视' in channel_name:
  307. if channel_name in channel_counters:
  308. if channel_counters[channel_name] >= result_counter:
  309. continue
  310. else:
  311. file.write(f"{channel_name},{channel_url}\n")
  312. channel_counters[channel_name] += 1
  313. else:
  314. file.write(f"{channel_name},{channel_url}\n")
  315. channel_counters[channel_name] = 1
  316. channel_counters = {}
  317. file.write('其他频道,#genre#\n')
  318. for result in results:
  319. channel_name, channel_url, speed = result
  320. if 'CCTV' not in channel_name and '卫视' not in channel_name and '测试' not in channel_name:
  321. if channel_name in channel_counters:
  322. if channel_counters[channel_name] >= result_counter:
  323. continue
  324. else:
  325. file.write(f"{channel_name},{channel_url}\n")
  326. channel_counters[channel_name] += 1
  327. else:
  328. file.write(f"{channel_name},{channel_url}\n")
  329. channel_counters[channel_name] = 1
  330. with open("itvlist.m3u", 'w', encoding='utf-8') as file:
  331. channel_counters = {}
  332. file.write('#EXTM3U\n')
  333. for result in results:
  334. channel_name, channel_url, speed = result
  335. if 'CCTV' in channel_name:
  336. if channel_name in channel_counters:
  337. if channel_counters[channel_name] >= result_counter:
  338. continue
  339. else:
  340. file.write(f"#EXTINF:-1 group-title=\"央视频道\",{channel_name}\n")
  341. file.write(f"{channel_url}\n")
  342. channel_counters[channel_name] += 1
  343. else:
  344. file.write(f"#EXTINF:-1 group-title=\"央视频道\",{channel_name}\n")
  345. file.write(f"{channel_url}\n")
  346. channel_counters[channel_name] = 1
  347. channel_counters = {}
  348. #file.write('卫视频道,#genre#\n')
  349. for result in results:
  350. channel_name, channel_url, speed = result
  351. if '卫视' in channel_name:
  352. if channel_name in channel_counters:
  353. if channel_counters[channel_name] >= result_counter:
  354. continue
  355. else:
  356. file.write(f"#EXTINF:-1 group-title=\"卫视频道\",{channel_name}\n")
  357. file.write(f"{channel_url}\n")
  358. channel_counters[channel_name] += 1
  359. else:
  360. file.write(f"#EXTINF:-1 group-title=\"卫视频道\",{channel_name}\n")
  361. file.write(f"{channel_url}\n")
  362. channel_counters[channel_name] = 1
  363. channel_counters = {}
  364. #file.write('其他频道,#genre#\n')
  365. for result in results:
  366. channel_name, channel_url, speed = result
  367. if 'CCTV' not in channel_name and '卫视' not in channel_name and '测试' not in channel_name:
  368. if channel_name in channel_counters:
  369. if channel_counters[channel_name] >= result_counter:
  370. continue
  371. else:
  372. file.write(f"#EXTINF:-1 group-title=\"其他频道\",{channel_name}\n")
  373. file.write(f"{channel_url}\n")
  374. channel_counters[channel_name] += 1
  375. else:
  376. file.write(f"#EXTINF:-1 group-title=\"其他频道\",{channel_name}\n")
  377. file.write(f"{channel_url}\n")
  378. channel_counters[channel_name] = 1