Skip to content

Commit

Permalink
[ytdl] improve error handling (#1680)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed Nov 15, 2021
1 parent 8eaedb0 commit 2076d40
Showing 1 changed file with 27 additions and 14 deletions.
41 changes: 27 additions & 14 deletions gallery_dl/extractor/ytdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,19 @@ def items(self):
set_cookie(cookie)

# extract youtube_dl info_dict
info_dict = ytdl_instance._YoutubeDL__extract_info(
self.ytdl_url,
ytdl_instance.get_info_extractor(self.ytdl_ie_key),
False, {}, True)

if "entries" in info_dict:
try:
info_dict = ytdl_instance._YoutubeDL__extract_info(
self.ytdl_url,
ytdl_instance.get_info_extractor(self.ytdl_ie_key),
False, {}, True)
except ytdl_module.utils.YoutubeDLError:
raise exception.StopExtraction("Failed to extract video data")

if not info_dict:
return
elif "entries" in info_dict:
results = self._process_entries(
ytdl_instance, info_dict["entries"])
ytdl_module, ytdl_instance, info_dict["entries"])
else:
results = (info_dict,)

Expand All @@ -104,15 +109,23 @@ def items(self):
yield Message.Directory, info_dict
yield Message.Url, url, info_dict

def _process_entries(self, ytdl_instance, entries):
def _process_entries(self, ytdl_module, ytdl_instance, entries):
for entry in entries:
if entry.get("_type") in ("url", "url_transparent"):
info_dict = ytdl_instance.extract_info(
entry["url"], False,
ie_key=entry.get("ie_key"))
if "entries" in info_dict:
if not entry:
continue
elif entry.get("_type") in ("url", "url_transparent"):
try:
info_dict = ytdl_instance.extract_info(
entry["url"], False,
ie_key=entry.get("ie_key"))
except ytdl_module.utils.YoutubeDLError:
continue

if not info_dict:
continue
elif "entries" in info_dict:
yield from self._process_entries(
ytdl_instance, info_dict["entries"])
ytdl_module, ytdl_instance, info_dict["entries"])
else:
yield info_dict
else:
Expand Down

0 comments on commit 2076d40

Please sign in to comment.