From cbf6d586f800b8fcd87920adc4599ad3a076ef42 Mon Sep 17 00:00:00 2001 From: "guorong.zheng" <360996299@qq.com> Date: Tue, 27 Feb 2024 15:24:01 +0800 Subject: [PATCH] fix:extract_resolution --- main.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index 9c2e417f6ec..48d9dfe1923 100644 --- a/main.py +++ b/main.py @@ -13,6 +13,7 @@ from selenium.common.exceptions import NoSuchElementException from bs4 import BeautifulSoup from datetime import datetime +import re class GetSource: @@ -184,14 +185,19 @@ async def visitPage(self, channelItems): reverse=True, ) # Sort by date infoList = await self.compareSpeed(infoList) # Sort by speed + + def extract_resolution(resolution_str): + numbers = re.findall(r"\d+x\d+", resolution_str) + if numbers: + width, height = map(int, numbers[0].split("x")) + return width * height + else: + return 0 + infoList.sort( key=lambda x: ( x[2] is not None, - ( - int(x[2].split("x")[0]) * int(x[2].split("x")[1]) - if x[2] - else 0 - ), + extract_resolution(x[2]) if x[2] else 0, ), reverse=True, ) # Sort by resolution