fix: play other formats than 16x9 on yattee

reports factually wrong, but close enough resolution. to be removed
when this will be fixed on yattee's end.
This commit is contained in:
2025-11-21 22:38:43 +01:00
parent 2687cc2bdc
commit 900cc92229

View File

@@ -519,6 +519,32 @@ def extractTextFromSimpleOrRuns(obj: dict, default: str = "") -> str:
return text return text
def findNearestResolution(width: int, height: int) -> int:
# Finds the nearest standard resolution (one of 144p, 240p, ...)
# So far only used for Yattee, as it has trouble playing anything
# without one of the standard resolutions. Playback on other
# clients is unaffected.
# failsafe behaviour
try:
width = int(width)
height = int(height)
res = min(width, height)
except:
return 360
standard_resolutions = [144, 240, 360, 720, 1080, 2160, 4320]
if res in standard_resolutions:
return res
# calculate relative distance to one of the standard resolutions
res_normalized = [abs(1 - (x / res)) for x in standard_resolutions]
# pick the one where the distance is the smallest
target_index = res_normalized.index(min(res_normalized))
target_res = standard_resolutions[target_index]
return target_res
def parseFormatStreams(wdata_fstream: dict, ydata_stream: dict) -> dict: def parseFormatStreams(wdata_fstream: dict, ydata_stream: dict) -> dict:
try: try:
@@ -536,7 +562,7 @@ def parseFormatStreams(wdata_fstream: dict, ydata_stream: dict) -> dict:
"bitrate": str(wdata_fstream["bitrate"]), "bitrate": str(wdata_fstream["bitrate"]),
"fps": wdata_fstream["fps"], "fps": wdata_fstream["fps"],
"size": f"{wdata_fstream['width']}x{wdata_fstream['height']}", "size": f"{wdata_fstream['width']}x{wdata_fstream['height']}",
"resolution": f"{wdata_fstream['height'] if wdata_fstream['height'] in (144, 240, 360, 720, 1080, 2160) else 360}p", "resolution": f"{findNearestResolution(wdata_fstream['width'], wdata_fstream['height'])}p", # possibly not really needed here
"qualityLabel": wdata_fstream["qualityLabel"], "qualityLabel": wdata_fstream["qualityLabel"],
"container": safeTraverse(FORMATS.get(wdata_fstream["itag"]), [ "ext"], default="mp4"), # invidious_formats "container": safeTraverse(FORMATS.get(wdata_fstream["itag"]), [ "ext"], default="mp4"), # invidious_formats
"encoding": safeTraverse(FORMATS.get(wdata_fstream["itag"]), ["vcodec"], default="mp4") # invidious_formats "encoding": safeTraverse(FORMATS.get(wdata_fstream["itag"]), ["vcodec"], default="mp4") # invidious_formats
@@ -577,7 +603,7 @@ def parseAdaptiveStreams(wdata_astream: dict, ydata_stream: dict) -> dict:
# video-specific metadata # video-specific metadata
astream["fps"] = wdata_astream["fps"] astream["fps"] = wdata_astream["fps"]
astream["size"] = f"{wdata_astream['width']}x{wdata_astream['height']}" astream["size"] = f"{wdata_astream['width']}x{wdata_astream['height']}"
astream["resolution"] = f"{wdata_astream['height'] if wdata_astream['height'] in (144, 240, 360, 720, 1080, 2160) else 360}p" astream["resolution"] = f"{findNearestResolution(wdata_astream['width'], wdata_astream['height'])}p"
astream["qualityLabel"] = wdata_astream["qualityLabel"] astream["qualityLabel"] = wdata_astream["qualityLabel"]
astream["colorInfo"] = safeTraverse(wdata_astream, ["colorInfo"]) astream["colorInfo"] = safeTraverse(wdata_astream, ["colorInfo"])
else: else: