Skip to content

Commit 4ab42bf

Browse files
authored
Update main.py
1 parent 29c7844 commit 4ab42bf

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

main.py

+24
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import re
22
import requests
33
from config import Config
4+
from concurrent.futures import ThreadPoolExecutor
45

56
def getChannelItems():
67
"""
@@ -83,7 +84,30 @@ def filter_source_urls(template_file):
8384

8485
return channels, template_channels
8586

87+
def test_url(url):
88+
response = requests.get(url)
89+
if response.status_code == 200:
90+
return True
91+
else:
92+
return False
93+
94+
def test_urls(urls):
95+
with ThreadPoolExecutor(max_workers=10) as executor:
96+
results = executor.map(test_url, urls)
97+
return list(results)
98+
8699
if __name__ == "__main__":
87100
template_file = "demo.txt"
88101
channels, template_channels = filter_source_urls(template_file)
102+
urls_to_test = [url for channel_info in channels.values() for urls in channel_info.values() for url in urls]
103+
results = test_urls(urls_to_test)
104+
105+
# Remove URLs that failed the test
106+
for channel_info in channels.values():
107+
for urls in channel_info.values():
108+
for url in urls.copy():
109+
if not results[0]:
110+
urls.remove(url)
111+
results.pop(0)
112+
89113
updateChannelUrlsM3U(channels, template_channels)

0 commit comments

Comments
 (0)