Skip to content

Commit 98aaba4

Browse files
committed
fix:whitelist order(#765)
1 parent b5a51b9 commit 98aaba4

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

updates/subscribe/request.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ async def get_channels_by_subscribe_urls(
3030
"""
3131
Get the channels by subscribe urls
3232
"""
33+
if whitelist:
34+
urls.sort(key=lambda url: whitelist.index(url) if url in whitelist else len(whitelist))
3335
subscribe_results = {}
3436
subscribe_urls_len = len(urls)
3537
pbar = tqdm_asyncio(
@@ -43,7 +45,6 @@ async def get_channels_by_subscribe_urls(
4345
f"正在获取{mode_name}源, 共{subscribe_urls_len}{mode_name}源",
4446
0,
4547
)
46-
session = Session()
4748
hotel_name = constants.origin_map["hotel"]
4849
multicast_name = constants.origin_map["multicast"]
4950
subscribe_name = constants.origin_map["subscribe"]
@@ -57,6 +58,7 @@ def process_subscribe_channels(subscribe_info):
5758
subscribe_url = subscribe_info
5859
channels = defaultdict(lambda: defaultdict(lambda: defaultdict(list)))
5960
in_whitelist = whitelist and (subscribe_url in whitelist)
61+
session = Session()
6062
try:
6163
response = None
6264
try:
@@ -100,7 +102,7 @@ def process_subscribe_channels(subscribe_info):
100102
)
101103
)
102104
if in_whitelist:
103-
info = "!" + info
105+
info = "!"
104106
url = add_url_info(url, info)
105107
url = format_url_with_cache(
106108
url, cache=subscribe_url if (multicast or hotel) else None
@@ -122,6 +124,7 @@ def process_subscribe_channels(subscribe_info):
122124
if error_print:
123125
print(f"Error on {subscribe_url}: {e}")
124126
finally:
127+
session.close()
125128
pbar.update()
126129
remain = subscribe_urls_len - pbar.n
127130
if callback:
@@ -138,6 +141,5 @@ def process_subscribe_channels(subscribe_info):
138141
]
139142
for future in futures:
140143
subscribe_results = merge_objects(subscribe_results, future.result())
141-
session.close()
142144
pbar.close()
143145
return subscribe_results

utils/tools.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,7 @@ def merge_dicts(dict1, dict2):
317317
dict1[key].update(value)
318318
elif isinstance(dict1[key], list):
319319
if value:
320-
dict1[key].extend(value)
321-
dict1[key] = list(set(dict1[key]))
320+
dict1[key].extend(x for x in value if x not in dict1[key])
322321
elif value:
323322
dict1[key] = {dict1[key], value}
324323
else:
@@ -477,11 +476,11 @@ def format_url_with_cache(url, cache=None):
477476
return add_url_info(url, f"cache:{cache}") if cache else url
478477

479478

480-
def remove_cache_info(str):
479+
def remove_cache_info(string):
481480
"""
482481
Remove the cache info from the string
483482
"""
484-
return re.sub(r"[^a-zA-Z\u4e00-\u9fa5\$]?cache:.*", "", str)
483+
return re.sub(r"[^a-zA-Z\u4e00-\u9fa5$]?cache:.*", "", string)
485484

486485

487486
def resource_path(relative_path, persistent=False):

0 commit comments

Comments
 (0)