Skip to content

Commit

Permalink
[twitter] handle errors during file extraction (#6647)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed Jan 21, 2025
1 parent d9c4fcc commit cb1a75e
Showing 1 changed file with 34 additions and 8 deletions.
42 changes: 34 additions & 8 deletions gallery_dl/extractor/twitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,7 @@ def items(self):
txt = data.get("full_text") or data.get("text") or ""
self.log.warning("'%s' (%s)", txt, data["id_str"])

files = []
if "extended_entities" in data:
self._extract_media(
data, data["extended_entities"]["media"], files)
if "card" in tweet and self.cards:
self._extract_card(tweet, files)
if self.twitpic:
self._extract_twitpic(data, files)
files = self._extract_files(data, tweet)
if not files and not self.textonly:
continue

Expand All @@ -143,6 +136,39 @@ def items(self):
text.nameext_from_url(url, file)
yield Message.Url, url, file

def _extract_files(self, data, tweet):
files = []

if "extended_entities" in data:
try:
self._extract_media(
data, data["extended_entities"]["media"], files)
except Exception as exc:
self.log.debug("", exc_info=exc)
self.log.warning(
"%s: Error while extracting media files (%s: %s)",
data["id_str"], exc.__class__.__name__, exc)

if self.cards and "card" in tweet:
try:
self._extract_card(tweet, files)
except Exception as exc:
self.log.debug("", exc_info=exc)
self.log.warning(
"%s: Error while extracting Card files (%s: %s)",
data["id_str"], exc.__class__.__name__, exc)

if self.twitpic:
try:
self._extract_twitpic(data, files)
except Exception as exc:
self.log.debug("", exc_info=exc)
self.log.warning(
"%s: Error while extracting TwitPic files (%s: %s)",
data["id_str"], exc.__class__.__name__, exc)

return files

def _extract_media(self, tweet, entities, files):
for media in entities:

Expand Down

0 comments on commit cb1a75e

Please sign in to comment.