1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-22 02:32:33 +01:00

[dl:ytdl] implement explicit HLS/DASH handling

add '_ytdl_manifest' to specify a manifest type to process
This commit is contained in:
Mike Fährmann 2024-10-15 21:54:05 +02:00
parent 67547a659f
commit 1824267447
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88
5 changed files with 51 additions and 3 deletions

View File

@ -62,10 +62,18 @@ class YoutubeDLDownloader(DownloaderBase):
info_dict = kwdict.pop("_ytdl_info_dict", None) info_dict = kwdict.pop("_ytdl_info_dict", None)
if not info_dict: if not info_dict:
url = url[5:]
try: try:
info_dict = ytdl_instance.extract_info(url[5:], download=False) manifest = kwdict.pop("_ytdl_manifest", None)
if manifest:
info_dict = self._extract_manifest(
ytdl_instance, url, manifest)
else:
info_dict = self._extract_info(ytdl_instance, url)
except Exception as exc: except Exception as exc:
self.log.debug("", exc_info=exc) self.log.debug("", exc_info=exc)
self.log.warning("%s: %s", exc.__class__.__name__, exc)
if not info_dict: if not info_dict:
return False return False
@ -134,6 +142,42 @@ class YoutubeDLDownloader(DownloaderBase):
ytdl_instance.process_info(entry) ytdl_instance.process_info(entry)
return True return True
def _extract_info(self, ytdl, url):
return ytdl.extract_info(url, download=False)
def _extract_manifest(self, ytdl, url, manifest):
extr = ytdl.get_info_extractor("Generic")
video_id = extr._generic_id(url)
if manifest == "hls":
try:
formats, subtitles = extr._extract_m3u8_formats_and_subtitles(
url, video_id, "mp4")
except AttributeError:
formats = extr._extract_m3u8_formats(url, video_id, "mp4")
subtitles = None
elif manifest == "dash":
try:
formats, subtitles = extr._extract_mpd_formats_and_subtitles(
url, video_id)
except AttributeError:
formats = extr._extract_mpd_formats(url, video_id)
subtitles = None
else:
self.log.error("Unsupported manifest type '%s'", manifest)
return None
info_dict = {
"id" : video_id,
"title" : video_id,
"formats" : formats,
"subtitles": subtitles,
}
# extr._extra_manifest_info(info_dict, url)
return ytdl.process_ie_result(info_dict, download=False)
def _progress_hook(self, info): def _progress_hook(self, info):
if info["status"] == "downloading" and \ if info["status"] == "downloading" and \
info["elapsed"] >= self.progress: info["elapsed"] >= self.progress:

View File

@ -171,6 +171,7 @@ class BehanceGalleryExtractor(BehanceExtractor):
url = text.extr(page, '<source src="', '"') url = text.extr(page, '<source src="', '"')
if text.ext_from_url(url) == "m3u8": if text.ext_from_url(url) == "m3u8":
url = "ytdl:" + url url = "ytdl:" + url
module["_ytdl_manifest"] = "hls"
module["extension"] = "mp4" module["extension"] = "mp4"
append((url, module)) append((url, module))
continue continue

View File

@ -56,6 +56,7 @@ class PatreonExtractor(Extractor):
text.nameext_from_url(name, post) text.nameext_from_url(name, post)
if text.ext_from_url(url) == "m3u8": if text.ext_from_url(url) == "m3u8":
url = "ytdl:" + url url = "ytdl:" + url
post["_ytdl_manifest"] = "hls"
post["extension"] = "mp4" post["extension"] = "mp4"
yield Message.Url, url, post yield Message.Url, url, post
else: else:

View File

@ -74,6 +74,7 @@ class PinterestExtractor(Extractor):
if pin["extension"] == "m3u8": if pin["extension"] == "m3u8":
url = "ytdl:" + url url = "ytdl:" + url
pin["_ytdl_manifest"] = "hls"
pin["extension"] = "mp4" pin["extension"] = "mp4"
yield Message.Url, url, pin yield Message.Url, url, pin

View File

@ -211,8 +211,9 @@ class RedditExtractor(Extractor):
def _extract_video_dash(self, submission): def _extract_video_dash(self, submission):
submission["_ytdl_extra"] = {"title": submission["title"]} submission["_ytdl_extra"] = {"title": submission["title"]}
try: try:
return (submission["secure_media"]["reddit_video"]["dash_url"] + url = submission["secure_media"]["reddit_video"]["dash_url"]
"#__youtubedl_smuggle=%7B%22to_generic%22%3A+1%7D") submission["_ytdl_manifest"] = "dash"
return url
except Exception: except Exception:
return submission["url"] return submission["url"]