feat: preliminary DASH support (for freetube/yattee, no manifest)

rewrites struct returned by innertube with video url retrieved by yt-dlp
works on freetube with proxying disabled; enabling proxying causes
horrible performance. yattee seems unaffected.
This commit is contained in:
2025-11-06 21:53:32 +01:00
parent 05b81e55da
commit da2daab16a
3 changed files with 112 additions and 214 deletions

View File

@@ -1,5 +1,6 @@
from ythdd_globals import safeTraverse
from html import escape
from invidious_formats import FORMATS
from ythdd_globals import safeTraverse
import json
import dateparser
import ythdd_globals
@@ -516,3 +517,76 @@ def extractTextFromSimpleOrRuns(obj: dict, default: str = "") -> str:
else:
print(f"error(extractTextFromSimpleOrRuns): text extraction failed for {obj}")
return text
def parseFormatStreams(wdata_fstream: dict, ydata_stream: dict) -> dict:
try:
stream_url = ydata_stream["url"]
except:
ythdd_globals.print_debug( "could not extract format stream URL from yt-dlp response:")
ythdd_globals.print_debug(f"wdata: {wdata_fstream}")
ythdd_globals.print_debug(f"ydata: {ydata_stream}")
fstream = {
"url": stream_url,
"itag": wdata_fstream["itag"],
"type": wdata_fstream["mimeType"],
"quality": wdata_fstream["quality"],
"bitrate": str(wdata_fstream["bitrate"]),
"fps": wdata_fstream["fps"],
"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",
"qualityLabel": wdata_fstream["qualityLabel"],
"container": safeTraverse(FORMATS.get(wdata_fstream["itag"]), [ "ext"], default="mp4"), # invidious_formats
"encoding": safeTraverse(FORMATS.get(wdata_fstream["itag"]), ["vcodec"], default="mp4") # invidious_formats
}
return fstream
def parseAdaptiveStreams(wdata_astream: dict, ydata_stream: dict) -> dict:
try:
stream_url = ydata_stream["url"]
except:
ythdd_globals.print_debug( "could not extract adaptive stream URL from yt-dlp response:")
ythdd_globals.print_debug(f"wdata: {wdata_fstream}")
ythdd_globals.print_debug(f"ydata: {ydata_stream}")
astream_common = {
"init": f"{wdata_astream[ 'initRange']['start']}-{wdata_astream[ 'initRange']['end']}",
"index": f"{wdata_astream['indexRange']['start']}-{wdata_astream['indexRange']['end']}",
"bitrate": str(wdata_astream["bitrate"]),
"url": stream_url,
"itag": str(wdata_astream["itag"]),
"type": wdata_astream["mimeType"],
"clen": wdata_astream["contentLength"],
"lmt": wdata_astream["lastModified"],
"projectionType": wdata_astream["projectionType"],
"container": safeTraverse(FORMATS.get(wdata_astream["itag"]), [ "ext"], default="mp4"), # invidious_formats,
"encoding": safeTraverse(FORMATS.get(wdata_astream["itag"]), ["vcodec"], default="mp4") # invidious_formats,
}
isVideo = True
if "audioQuality" in wdata_astream:
isVideo = False
if isVideo:
astream = astream_common
# video-specific metadata
astream["fps"] = wdata_astream["fps"]
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["qualityLabel"] = wdata_astream["qualityLabel"]
astream["colorInfo"] = safeTraverse(wdata_astream, ["colorInfo"])
else:
astream = astream_common
# audio-specific metadata
astream["audioQuality"] = wdata_astream["audioQuality"],
astream["audioSampleRate"] = int(wdata_astream["audioSampleRate"]),
astream["audioChannels"] = wdata_astream["audioChannels"]
# breakpoint()
return astream