From 64efc67e6a29b8fd927eec29971a2054aebd35ba Mon Sep 17 00:00:00 2001 From: Lovi <62809003+Lovi-0@users.noreply.github.com> Date: Sat, 29 Mar 2025 09:02:26 +0100 Subject: [PATCH] core: HLS fix custom resolution parsing like 854x480 --- .../Api/Site/mostraguarda/__init__.py | 2 +- .../Lib/Downloader/HLS/downloader.py | 8 +---- StreamingCommunity/Lib/M3U8/parser.py | 32 +++++++++++++++---- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/StreamingCommunity/Api/Site/mostraguarda/__init__.py b/StreamingCommunity/Api/Site/mostraguarda/__init__.py index d08e8d1..656e29e 100644 --- a/StreamingCommunity/Api/Site/mostraguarda/__init__.py +++ b/StreamingCommunity/Api/Site/mostraguarda/__init__.py @@ -21,7 +21,7 @@ from .film import download_film # Variable indice = 7 _useFor = "film" -_deprecate = False +_deprecate = True _priority = 2 _engineDownload = "hls" diff --git a/StreamingCommunity/Lib/Downloader/HLS/downloader.py b/StreamingCommunity/Lib/Downloader/HLS/downloader.py index eee41dc..a6ed152 100644 --- a/StreamingCommunity/Lib/Downloader/HLS/downloader.py +++ b/StreamingCommunity/Lib/Downloader/HLS/downloader.py @@ -189,16 +189,10 @@ class M3U8Manager: tuple_available_resolution = self.parser._video.get_list_resolution() list_available_resolution = [f"{r[0]}x{r[1]}" for r in tuple_available_resolution] - # Check if self.video_res is not None - if self.video_res is not None: - video_resolution = f"{self.video_res[0]}x{self.video_res[1]}" - else: - video_resolution = "Not set" - console.print( f"[cyan bold]Video [/cyan bold] [green]Available:[/green] [purple]{', '.join(list_available_resolution)}[/purple] | " f"[red]Set:[/red] [purple]{FILTER_CUSTOM_REOLUTION}[/purple] | " - f"[yellow]Downloadable:[/yellow] [purple]{video_resolution}[/purple]" + f"[yellow]Downloadable:[/yellow] [purple]{self.video_res[0]}x{self.video_res[1]}[/purple]" ) if self.parser.codec is not None: diff --git a/StreamingCommunity/Lib/M3U8/parser.py b/StreamingCommunity/Lib/M3U8/parser.py index 5d40e9b..0a083e8 100644 --- a/StreamingCommunity/Lib/M3U8/parser.py +++ b/StreamingCommunity/Lib/M3U8/parser.py @@ -1,6 +1,6 @@ # 20.04.25 -import sys +import re import logging @@ -418,18 +418,38 @@ class M3U8_Parser: - uri (str): The URI containing video information. Returns: - int: The video resolution if found, otherwise 0. + tuple: The video resolution (width, height) if found, otherwise (0, 0). """ - # Log logging.info(f"Try extract resolution from: {uri}") - + + # First try: Check for known resolutions for resolution in RESOLUTIONS: if "http" in str(uri): if str(resolution[1]) in uri: return resolution - - # Default resolution return (not best) + + # Pattern to match common resolution formats like 854x480, 1280x720, etc. + resolution_patterns = [ + r'(\d+)x(\d+)', # Match format: 854x480 + r'(\d+)p', # Match format: 480p, 720p, etc. + r'_(\d+)x(\d+)' # Match format: _854x480 + ] + + for pattern in resolution_patterns: + matches = re.findall(pattern, uri) + if matches: + if len(matches[0]) == 2: # Format like 854x480 + width, height = int(matches[0][0]), int(matches[0][1]) + return (width, height) + + elif len(matches[0]) == 1: # Format like 480p + height = int(matches[0]) + + # Estimate width based on common aspect ratios (16:9) + width = int(height * 16 / 9) + return (width, height) + logging.warning("No resolution found with custom parsing.") return (0, 0)