Skip to content

Commit cbf6d58

Browse files
committed
fix:extract_resolution
1 parent 29ebff9 commit cbf6d58

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

main.py

+11-5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from selenium.common.exceptions import NoSuchElementException
1414
from bs4 import BeautifulSoup
1515
from datetime import datetime
16+
import re
1617

1718

1819
class GetSource:
@@ -184,14 +185,19 @@ async def visitPage(self, channelItems):
184185
reverse=True,
185186
) # Sort by date
186187
infoList = await self.compareSpeed(infoList) # Sort by speed
188+
189+
def extract_resolution(resolution_str):
190+
numbers = re.findall(r"\d+x\d+", resolution_str)
191+
if numbers:
192+
width, height = map(int, numbers[0].split("x"))
193+
return width * height
194+
else:
195+
return 0
196+
187197
infoList.sort(
188198
key=lambda x: (
189199
x[2] is not None,
190-
(
191-
int(x[2].split("x")[0]) * int(x[2].split("x")[1])
192-
if x[2]
193-
else 0
194-
),
200+
extract_resolution(x[2]) if x[2] else 0,
195201
),
196202
reverse=True,
197203
) # Sort by resolution

0 commit comments

Comments
 (0)