-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathb.py
200 lines (186 loc) · 8.32 KB
/
b.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
import time
import requests
import re
import cv2 # 导入OpenCV库
###urls城市根据自己所处的地理位置修改
urls = [
"https://fofa.info/result?qbase64=InVkcHh5IiAmJiBhc249IjQxMzQiICYmIGNpdHk9cWluaHVhbmdkYW8%3D",#秦皇岛
"https://fofa.info/result?qbase64=InVkcHh5IiAmJiBhc249IjQ4MzciICYmIGNpdHk9InNoaWppYXpodWFuZyI%3D",#石家庄联通
"https://fofa.info/result?qbase64=InVkcHh5IiAmJiBhc249IjQ4MzciICYmIGNpdHk9InRhbmdzaGFuIg%3D%3D",#唐山联通
"https://fofa.info/result?qbase64=InVkcHh5IiAmJiBhc249IjQ4MzciICYmIGNpdHk9IkNhbmd6aG91Ig%3D%3D",#沧州联通
"https://fofa.info/result?qbase64=InVkcHh5IiAmJiBhc249IjQ4MzciICYmIGNpdHk9ImJhb2Rpbmci",#保定联通
"https://fofa.info/result?qbase64=InVkcHh5IiAmJiBhc249IjQ4MzciICYmIGNpdHk9ImhhbmRhbiI%3D"#邯郸联通
]
def extract_unique_ip_ports(url):
try:
response = requests.get(url)
time.sleep(10)
html_content = response.text
# 使用正则表达式匹配IP地址和端口号
ips_ports = re.findall(r'(\d+\.\d+\.\d+\.\d+:\d+)', html_content)
unique_ips_ports = list(set(ips_ports)) # 去除重复的IP地址和端口号
if unique_ips_ports:
return unique_ips_ports
except requests.RequestException as e:
print(f"请求错误: {e}")
return None
# 检查视频流的可达性
def check_video_stream_connectivity(ip_port, urls_udp):
try:
# 构造完整的视频URL
video_url = f"http://{ip_port}{urls_udp}"
# 用OpenCV读取视频
cap = cv2.VideoCapture(video_url)
# 检查视频是否成功打开
if not cap.isOpened():
print(f"视频URL {video_url} 无效")
return None
else:
# 读取视频的宽度和高度
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
print(f"视频URL {video_url} 的分辨率为 {width}x{height}")
# 检查分辨率是否大于0
if width > 0 and height > 0:
return ip_port # 返回有效的IP和端口
# 关闭视频流
cap.release()
except Exception as e:
print(f"访问 {ip_port} 失败: {e}")
return None
# 定义组播地址和端口
urls_udp = "/rtp/239.253.92.83:8012"
# 提取唯一的IP地址和端口号
ip_ports = []
valid_ips = []
for url in urls:
ip_ports = extract_unique_ip_ports(url)
if ip_ports:
print("IP地址和端口号:")
print(ip_ports)
#测试每个IP地址和端口号,直到找到一个可访问的视频流
for ip_port in ip_ports:
valid_ip = check_video_stream_connectivity(ip_port, urls_udp)
if valid_ip:
print(f"找到可访问的视频流服务: {valid_ip}")
valid_ips.append(valid_ip)
channels = []
with open("iptv2.txt", 'r', encoding='utf-8') as file:
lines = file.readlines()
for line in lines:
#print(line)
line = line.strip()
if line:
channel_name,channel_url = line.split(",")
for udpxy_url in valid_ips:
#print(udpxy_url)
channel_udpxy_url = f"{udpxy_url}/{channel_url}"
channel = f"{channel_name},{channel_udpxy_url}"
channels.append(channel)
result_counter = 8 # 每个频道需要的个数
with open("itvlist.txt", 'a', encoding='utf-8') as file:
channel_counters = {}
file.write('央视(联通),#genre#\n')
for channel in channels:
channel_name,channel_url = channel.split(",")
if 'CCTV' in channel_name:
if channel_name in channel_counters:
if channel_counters[channel_name] >= result_counter:
continue
else:
file.write(f"{channel_name},{channel_url}\n")
channel_counters[channel_name] += 1
else:
file.write(f"{channel_name},{channel_url}\n")
channel_counters[channel_name] = 1
channel_counters = {}
file.write('数字(联通),#genre#\n')
for channel in channels:
channel_name, channel_url = channel.split(",")
if '天元' in channel_name or '风云' in channel_name or '球' in channel_name or '影' in channel_name:
if channel_name in channel_counters:
if channel_counters[channel_name] >= result_counter:
continue
else:
file.write(f"{channel_name},{channel_url}\n")
channel_counters[channel_name] += 1
else:
file.write(f"{channel_name},{channel_url}\n")
channel_counters[channel_name] = 1
channel_counters = {}
file.write('卫视(联通),#genre#\n')
for channel in channels:
channel_name,channel_url = channel.split(",")
if '卫视' in channel_name:
if channel_name in channel_counters:
if channel_counters[channel_name] >= result_counter:
continue
else:
file.write(f"{channel_name},{channel_url}\n")
channel_counters[channel_name] += 1
else:
file.write(f"{channel_name},{channel_url}\n")
channel_counters[channel_name] = 1
channel_counters = {}
file.write('其他(联通),#genre#\n')
for channel in channels:
channel_name,channel_url = channel.split(",")
if 'CCTV' not in channel_name and '卫视' not in channel_name and '测试' not in channel_name:
if channel_name in channel_counters:
if channel_counters[channel_name] >= result_counter:
continue
else:
file.write(f"{channel_name},{channel_url}\n")
channel_counters[channel_name] += 1
else:
file.write(f"{channel_name},{channel_url}\n")
channel_counters[channel_name] = 1
with open("itvlist.m3u", 'a', encoding='utf-8') as file:
channel_counters = {}
file.write('#EXTM3U\n')
for channel in channels:
channel_name,channel_url = channel.split(",")
if 'CCTV' in channel_name:
if channel_name in channel_counters:
if channel_counters[channel_name] >= result_counter:
continue
else:
file.write(f"#EXTINF:-1 group-title=\"央视频道\",{channel_name}\n")
file.write(f"{channel_url}\n")
channel_counters[channel_name] += 1
else:
file.write(f"#EXTINF:-1 group-title=\"央视频道\",{channel_name}\n")
file.write(f"{channel_url}\n")
channel_counters[channel_name] = 1
channel_counters = {}
#file.write('卫视频道,#genre#\n')
for channel in channels:
channel_name,channel_url = channel.split(",")
if '卫视' in channel_name:
if channel_name in channel_counters:
if channel_counters[channel_name] >= result_counter:
continue
else:
file.write(f"#EXTINF:-1 group-title=\"卫视频道\",{channel_name}\n")
file.write(f"{channel_url}\n")
channel_counters[channel_name] += 1
else:
file.write(f"#EXTINF:-1 group-title=\"卫视频道\",{channel_name}\n")
file.write(f"{channel_url}\n")
channel_counters[channel_name] = 1
channel_counters = {}
#file.write('其他频道,#genre#\n')
for channel in channels:
channel_name,channel_url = channel.split(",")
if 'CCTV' not in channel_name and '卫视' not in channel_name and '测试' not in channel_name:
if channel_name in channel_counters:
if channel_counters[channel_name] >= result_counter:
continue
else:
file.write(f"#EXTINF:-1 group-title=\"其他频道\",{channel_name}\n")
file.write(f"{channel_url}\n")
channel_counters[channel_name] += 1
else:
file.write(f"#EXTINF:-1 group-title=\"其他频道\",{channel_name}\n")
file.write(f"{channel_url}\n")
channel_counters[channel_name] = 1