Commit 4ab42bf 1 parent 29c7844 commit 4ab42bf Copy full SHA for 4ab42bf
File tree 1 file changed +24
-0
lines changed
1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change 1
1
import re
2
2
import requests
3
3
from config import Config
4
+ from concurrent .futures import ThreadPoolExecutor
4
5
5
6
def getChannelItems ():
6
7
"""
@@ -83,7 +84,30 @@ def filter_source_urls(template_file):
83
84
84
85
return channels , template_channels
85
86
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
+
86
99
if __name__ == "__main__" :
87
100
template_file = "demo.txt"
88
101
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
+
89
113
updateChannelUrlsM3U (channels , template_channels )
You can’t perform that action at this time.
0 commit comments