本文整理汇总了Python中youtube_dl.YoutubeDL.process_info方法的典型用法代码示例。如果您正苦于以下问题:Python YoutubeDL.process_info方法的具体用法?Python YoutubeDL.process_info怎么用?Python YoutubeDL.process_info使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类youtube_dl.YoutubeDL
的用法示例。
在下文中一共展示了YoutubeDL.process_info方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: YoutubeDLDownloader
# 需要导入模块: from youtube_dl import YoutubeDL [as 别名]
# 或者: from youtube_dl.YoutubeDL import process_info [as 别名]
class YoutubeDLDownloader(DownloaderBase):
scheme = "ytdl"
def __init__(self, extractor, output):
DownloaderBase.__init__(self, extractor, output)
options = {
"format": self.config("format") or None,
"ratelimit": text.parse_bytes(self.config("rate"), None),
"retries": self.config("retries", extractor._retries),
"socket_timeout": self.config("timeout", extractor._timeout),
"nocheckcertificate": not self.config("verify", extractor._verify),
"nopart": not self.part,
}
options.update(self.config("raw-options") or {})
if self.config("logging", True):
options["logger"] = self.log
self.ytdl = YoutubeDL(options)
def download(self, url, pathfmt):
try:
info_dict = self.ytdl.extract_info(url[5:], download=False)
except Exception:
return False
if "entries" in info_dict:
index = pathfmt.keywords.get("_ytdl_index")
if index is None:
return self._download_playlist(pathfmt, info_dict)
else:
info_dict = info_dict["entries"][index]
return self._download_video(pathfmt, info_dict)
def _download_video(self, pathfmt, info_dict):
pathfmt.set_extension(info_dict["ext"])
if pathfmt.exists():
pathfmt.temppath = ""
return True
if self.part and self.partdir:
pathfmt.temppath = os.path.join(
self.partdir, pathfmt.filename)
self.ytdl.params["outtmpl"] = pathfmt.temppath.replace("%", "%%")
self.out.start(pathfmt.path)
try:
self.ytdl.process_info(info_dict)
except Exception:
self.log.debug("Traceback", exc_info=True)
return False
return True
def _download_playlist(self, pathfmt, info_dict):
pathfmt.set_extension("%(playlist_index)s.%(ext)s")
self.ytdl.params["outtmpl"] = pathfmt.realpath
for entry in info_dict["entries"]:
self.ytdl.process_info(entry)
return True