Skip to content

Commit 64efc67

Browse files
committed
core: HLS fix custom resolution parsing like 854x480
1 parent 4789c14 commit 64efc67

File tree

3 files changed

+28
-14
lines changed

3 files changed

+28
-14
lines changed

StreamingCommunity/Api/Site/mostraguarda/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
# Variable
2222
indice = 7
2323
_useFor = "film"
24-
_deprecate = False
24+
_deprecate = True
2525
_priority = 2
2626
_engineDownload = "hls"
2727

StreamingCommunity/Lib/Downloader/HLS/downloader.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -189,16 +189,10 @@ def log_selection(self):
189189
tuple_available_resolution = self.parser._video.get_list_resolution()
190190
list_available_resolution = [f"{r[0]}x{r[1]}" for r in tuple_available_resolution]
191191

192-
# Check if self.video_res is not None
193-
if self.video_res is not None:
194-
video_resolution = f"{self.video_res[0]}x{self.video_res[1]}"
195-
else:
196-
video_resolution = "Not set"
197-
198192
console.print(
199193
f"[cyan bold]Video [/cyan bold] [green]Available:[/green] [purple]{', '.join(list_available_resolution)}[/purple] | "
200194
f"[red]Set:[/red] [purple]{FILTER_CUSTOM_REOLUTION}[/purple] | "
201-
f"[yellow]Downloadable:[/yellow] [purple]{video_resolution}[/purple]"
195+
f"[yellow]Downloadable:[/yellow] [purple]{self.video_res[0]}x{self.video_res[1]}[/purple]"
202196
)
203197

204198
if self.parser.codec is not None:

StreamingCommunity/Lib/M3U8/parser.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# 20.04.25
22

3-
import sys
3+
import re
44
import logging
55

66

@@ -418,18 +418,38 @@ def extract_resolution(uri: str) -> int:
418418
- uri (str): The URI containing video information.
419419
420420
Returns:
421-
int: The video resolution if found, otherwise 0.
421+
tuple: The video resolution (width, height) if found, otherwise (0, 0).
422422
"""
423-
424423
# Log
425424
logging.info(f"Try extract resolution from: {uri}")
426-
425+
426+
# First try: Check for known resolutions
427427
for resolution in RESOLUTIONS:
428428
if "http" in str(uri):
429429
if str(resolution[1]) in uri:
430430
return resolution
431-
432-
# Default resolution return (not best)
431+
432+
# Pattern to match common resolution formats like 854x480, 1280x720, etc.
433+
resolution_patterns = [
434+
r'(\d+)x(\d+)', # Match format: 854x480
435+
r'(\d+)p', # Match format: 480p, 720p, etc.
436+
r'_(\d+)x(\d+)' # Match format: _854x480
437+
]
438+
439+
for pattern in resolution_patterns:
440+
matches = re.findall(pattern, uri)
441+
if matches:
442+
if len(matches[0]) == 2: # Format like 854x480
443+
width, height = int(matches[0][0]), int(matches[0][1])
444+
return (width, height)
445+
446+
elif len(matches[0]) == 1: # Format like 480p
447+
height = int(matches[0])
448+
449+
# Estimate width based on common aspect ratios (16:9)
450+
width = int(height * 16 / 9)
451+
return (width, height)
452+
433453
logging.warning("No resolution found with custom parsing.")
434454
return (0, 0)
435455

0 commit comments

Comments
 (0)