Skip to content

Commit

Permalink
[twitter] add 'url' to user objects (#1532, #1787)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed Aug 23, 2021
1 parent 5919dc5 commit 7c0ae88
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions gallery_dl/extractor/twitter.py
Expand Up @@ -214,6 +214,8 @@ def _transform_user(self, user):
pass

uid = user["id_str"]
entities = user["entities"]

self._user_cache[uid] = udata = {
"id" : text.parse_int(uid),
"name" : user["screen_name"],
Expand All @@ -233,6 +235,10 @@ def _transform_user(self, user):
"media_count" : user["media_count"],
"statuses_count" : user["statuses_count"],
}

if "url" in entities:
udata["url"] = entities["url"]["urls"][0]["expanded_url"]

return udata

def _users_result(self, users):
Expand Down

2 comments on commit 7c0ae88

@ImportTaste
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sometimes getting this error during extraction, I'll open an issue if needed:

[twitter][error] An unexpected error occurred: KeyError - 'expanded_url'. Please run gallery-dl again with the --verbose flag, copy its output and report this issue on https://github.com/mikf/gallery-dl/issues .
[twitter][debug]
Traceback (most recent call last):
  File "gallery_dl\job.py", line 80, in run
  File "gallery_dl\extractor\twitter.py", line 75, in items
  File "gallery_dl\extractor\twitter.py", line 172, in _transform_tweet
  File "gallery_dl\extractor\twitter.py", line 246, in _transform_user
KeyError: 'expanded_url'

@mikf
Copy link
Owner Author

@mikf mikf commented on 7c0ae88 Aug 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 6651da2 There aren't all that many users where this happens, it seems. Took a while to find one.

Please sign in to comment.