mirror of
https://github.com/mikf/gallery-dl.git
synced 2024-11-25 04:02:32 +01:00
[dl:ytdl] implement explicit HLS/DASH handling
add '_ytdl_manifest' to specify a manifest type to process
This commit is contained in:
parent
67547a659f
commit
1824267447
@ -62,10 +62,18 @@ class YoutubeDLDownloader(DownloaderBase):
|
||||
|
||||
info_dict = kwdict.pop("_ytdl_info_dict", None)
|
||||
if not info_dict:
|
||||
url = url[5:]
|
||||
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:
|
||||
self.log.debug("", exc_info=exc)
|
||||
self.log.warning("%s: %s", exc.__class__.__name__, exc)
|
||||
|
||||
if not info_dict:
|
||||
return False
|
||||
|
||||
@ -134,6 +142,42 @@ class YoutubeDLDownloader(DownloaderBase):
|
||||
ytdl_instance.process_info(entry)
|
||||
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):
|
||||
if info["status"] == "downloading" and \
|
||||
info["elapsed"] >= self.progress:
|
||||
|
@ -171,6 +171,7 @@ class BehanceGalleryExtractor(BehanceExtractor):
|
||||
url = text.extr(page, '<source src="', '"')
|
||||
if text.ext_from_url(url) == "m3u8":
|
||||
url = "ytdl:" + url
|
||||
module["_ytdl_manifest"] = "hls"
|
||||
module["extension"] = "mp4"
|
||||
append((url, module))
|
||||
continue
|
||||
|
@ -56,6 +56,7 @@ class PatreonExtractor(Extractor):
|
||||
text.nameext_from_url(name, post)
|
||||
if text.ext_from_url(url) == "m3u8":
|
||||
url = "ytdl:" + url
|
||||
post["_ytdl_manifest"] = "hls"
|
||||
post["extension"] = "mp4"
|
||||
yield Message.Url, url, post
|
||||
else:
|
||||
|
@ -74,6 +74,7 @@ class PinterestExtractor(Extractor):
|
||||
|
||||
if pin["extension"] == "m3u8":
|
||||
url = "ytdl:" + url
|
||||
pin["_ytdl_manifest"] = "hls"
|
||||
pin["extension"] = "mp4"
|
||||
|
||||
yield Message.Url, url, pin
|
||||
|
@ -211,8 +211,9 @@ class RedditExtractor(Extractor):
|
||||
def _extract_video_dash(self, submission):
|
||||
submission["_ytdl_extra"] = {"title": submission["title"]}
|
||||
try:
|
||||
return (submission["secure_media"]["reddit_video"]["dash_url"] +
|
||||
"#__youtubedl_smuggle=%7B%22to_generic%22%3A+1%7D")
|
||||
url = submission["secure_media"]["reddit_video"]["dash_url"]
|
||||
submission["_ytdl_manifest"] = "dash"
|
||||
return url
|
||||
except Exception:
|
||||
return submission["url"]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user