-
Notifications
You must be signed in to change notification settings - Fork 5
/
gdiptv.py
190 lines (172 loc) · 7.63 KB
/
gdiptv.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
import requests
import re
import cv2 # 导入OpenCV库
import datetime
#取时间
now = (datetime.datetime.now() + datetime.timedelta(hours=8)).strftime('[%m/%d %H:%M]Updated.')
# 定义组播地址和端口
urls_udp = "/udp/239.77.0.1:5146"
# 定义fofa链接
fofa_url = 'https://fofa.info/result?qbase64=InVkcHh5IiAmJiBwcm90b2NvbD0iaHR0cCIgJiYgcmVnaW9uPSJHdWFuZ2RvbmciICYmIG9yZz0iQ2hpbmFuZXQi'
fofa_url_jm = 'https://fofa.info/result?qbase64=InVkcHh5IiAmJiBwcm90b2NvbD0iaHR0cCIgJiYgY2l0eT0iSmlhbmdtZW4iICYmIG9yZz0iQ2hpbmFuZXQi'
fofa_url_fs = 'https://fofa.info/result?qbase64=InVkcHh5IiAmJiBwcm90b2NvbD0iaHR0cCIgJiYgY2l0eT0iRm9zaGFuIiAmJiBvcmc9IkNoaW5hbmV0Ig%3D%3D'
fofa_url_mz = 'https://fofa.info/result?qbase64=InVkcHh5IiAmJiBjaXR5PSJTaGVuemhlbiIgICYmIG9yZz0iQ2hpbmFuZXQi'
# 尝试从fofa链接提取IP地址和端口号,并去除重复项
def extract_unique_ip_ports(fofa_url):
try:
response = requests.get(fofa_url)
html_content = response.text
# 使用正则表达式匹配IP地址和端口号
middle = re.findall(r'Array.*</script>', html_content)
if not middle:
print(f"未能提取到有效数据,FOFA URL: {fofa_url}")
return None
ips_ports = re.findall(r'(\d+\.\d+\.\d+\.\d+:\d+)', middle[0])
return ips_ports if ips_ports else None
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)
cap2 = cv2.VideoCapture(f"http://{ip_port}/udp/239.77.0.112:5146")
# 检查视频是否成功打开
if not cap.isOpened():
print(f"视频URL:{video_url} 无效")
return None
else:
# 获取视频帧率
fps = cap.get(cv2.CAP_PROP_FPS)
fps2 = cap2.get(cv2.CAP_PROP_FPS)
# 读取视频的宽度和高度
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}","[广东珠江]帧率: {:.2f}".format(fps),"[广东体育]帧率: {:.2f}".format(fps2))
# 检查分辨率是否大于0
if width > 0 and height > 0 and fps < 40 and fps2 < 40:
return ip_port # 返回有效的IP和端口
# 关闭视频流
cap.release()
except Exception as e:
print(f"访问 {ip_port} 失败: {e}")
return None
# 更新文件中的IP地址和端口号
def update_files(accessible_ip_port,ip_port_pattern,ip_port_repl):
global updated_content
global updated_content_3
group = re.findall('A|E|J|B',ip_port_pattern)[0]
#for file_info in files_to_update:
try:
# 读取原始文件内容
response = requests.get('https://xiaotan8.github.io/gdiptv.txt')
if updated_content:
file_content = updated_content
else:
file_content = response.text
# 替换文件中的IP地址和端口号
updated_content = re.sub(ip_port_pattern, ip_port_repl, file_content)
updated_content = re.sub(r'\[\d+\/\d+ \d+\:\d+\]Updated\.', now, updated_content)
#失效标记
if ip_port_repl == '88.88.88.88:8888':
updated_content = re.sub(f'频道.?{group}(失效|)',f'频道[{group}失效', updated_content)
else:
updated_content = re.sub(f'频道.?{group}(失效|)',f'频道[{group}', updated_content)
# 保存更新后的内容到新文件
with open('gdiptv.txt', 'w', encoding='utf-8') as file:
file.write(updated_content)
print(f"{group}:文件gdiptv.txt已更新并保存。")
except requests.RequestException as e:
print(f"无法更新文件gdiptv.txt,错误: {e}")
try:
# 读取原始文件内容
response = requests.get('https://xiaotan8.github.io/gdiptv.m3u')
if updated_content_3:
file_content = updated_content_3
else:
file_content = response.text
# 替换文件中的IP地址和端口号
updated_content_3 = re.sub(ip_port_pattern, ip_port_repl, file_content)
updated_content_3 = re.sub(r'\[\d+\/\d+ \d+\:\d+\]Updated\.', now, updated_content_3)
#失效标记
if ip_port_repl == '88.88.88.88:8888':
updated_content_3 = re.sub(f'频道.?{group}(失效|)',f'频道[{group}失效', updated_content_3)
else:
updated_content_3 = re.sub(f'频道.?{group}(失效|)',f'频道[{group}', updated_content_3)
# 保存更新后的内容到新文件
with open('gdiptv.m3u', 'w', encoding='utf-8') as file:
file.write(updated_content_3)
print(f"{group}:文件gdiptv.m3u已更新并保存。")
except requests.RequestException as e:
print(f"无法更新文件gdiptv.m3u,错误: {e}")
def findtheone(unique_ips_ports):
if unique_ips_ports:
print("提取到的唯一IP地址和端口号:")
for ip_port in unique_ips_ports:
print(ip_port)
# 测试每个IP地址和端口号,直到找到一个可访问的视频流
valid_ip = None
for ip_port in unique_ips_ports:
valid_ip = check_video_stream_connectivity(ip_port, urls_udp)
if valid_ip:
break # 找到有效的IP后,不再继续循环
if valid_ip:
print(f"找到可访问的视频流服务: {valid_ip}")
else:
valid_ip = '88.88.88.88:8888'
print("没有找到可访问的视频流服务。")
else:
print("没有提取到IP地址和端口号。")
return valid_ip
# 提取唯一的IP地址和端口号
# 定义需要更新的文件列表
files_to_update = [
{'url': 'https://xiaotan8.github.io/gdiptv.txt', 'filename': 'gdiptv.txt'}
]
#定义正则
ip_port_pattern = r'((?<=\[A\](\,|\n)http://)\d+\.\d+\.\d+\.\d+:\d+)'
ip_port_pattern_fs = r'((?<=\[E\](\,|\n)http://)\d+\.\d+\.\d+\.\d+:\d+)'
ip_port_pattern_jm = r'((?<=\[J\](\,|\n)http://)\d+\.\d+\.\d+\.\d+:\d+)'
ip_port_pattern_mz = r'((?<=\[B\](\,|\n)http://)\d+\.\d+\.\d+\.\d+:\d+)'
# 更新文件中的IP地址和端口号
updated_content = ''
updated_content_3 = ''
try:
unique_ips_ports = extract_unique_ip_ports(fofa_url)
print(unique_ips_ports)
valid_ip = findtheone(unique_ips_ports)
ip_port_repl = valid_ip
print(valid_ip)
update_files(valid_ip,ip_port_pattern,ip_port_repl)
except requests.RequestException as e:
print(f"错误: {e}")
try:
unique_ips_ports_fs = extract_unique_ip_ports(fofa_url_fs)
print(unique_ips_ports_fs)
valid_ip_fs = findtheone(unique_ips_ports_fs)
ip_port_repl_fs = valid_ip_fs
print(valid_ip_fs)
update_files(valid_ip_fs,ip_port_pattern_fs,ip_port_repl_fs)
except requests.RequestException as e:
print(f"错误: {e}")
try:
unique_ips_ports_jm = extract_unique_ip_ports(fofa_url_jm)
print(unique_ips_ports_jm)
valid_ip_jm = findtheone(unique_ips_ports_jm)
ip_port_repl_jm = valid_ip_jm
print(valid_ip_jm)
update_files(valid_ip_jm,ip_port_pattern_jm,ip_port_repl_jm)
except requests.RequestException as e:
print(f"错误: {e}")
try:
unique_ips_ports_mz = extract_unique_ip_ports(fofa_url_mz)
print(unique_ips_ports_mz)
valid_ip_mz = findtheone(unique_ips_ports_mz)
ip_port_repl_mz = valid_ip_mz
print(valid_ip_mz)
update_files(valid_ip_mz,ip_port_pattern_mz,ip_port_repl_mz)
except requests.RequestException as e:
print(f"错误: {e}")