Skip to content

Commit

Permalink
[twitter] changes to 'cards' option
Browse files Browse the repository at this point in the history
- change default value to 'true'
- only invoke youtube-dl for cards unsupported by gallery
  when 'cards' is set to "ytdl"

"cards": true   --> only download card images
"cards": "ytdl" --> download card images and
                    use youtube_dl on otherwise unsupported cards
  • Loading branch information
mikf committed Jan 15, 2022
1 parent 2d34d8f commit f2e8aed
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
10 changes: 7 additions & 3 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2030,11 +2030,15 @@ Description
extractor.twitter.cards
-----------------------
Type
``bool``
``bool`` or ``string``
Default
``false``
``true``
Description
Fetch media from `Cards <https://developer.twitter.com/en/docs/twitter-for-websites/cards/overview/abouts-cards>`__.
Controls how to handle `Twitter Cards <https://developer.twitter.com/en/docs/twitter-for-websites/cards/overview/abouts-cards>`__.

* ``false``: Ignore cards
* ``true``: Download image content from supported cards
* ``"ytdl"``: Additionally download video content from unsupported cards using `youtube-dl`_


extractor.twitter.conversations
Expand Down
2 changes: 1 addition & 1 deletion docs/gallery-dl.conf
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@
{
"username": null,
"password": null,
"cards": false,
"cards": true,
"conversations": false,
"pinned": false,
"quoted": false,
Expand Down
4 changes: 2 additions & 2 deletions gallery_dl/extractor/twitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def __init__(self, match):
self.pinned = self.config("pinned", False)
self.quoted = self.config("quoted", False)
self.videos = self.config("videos", True)
self.cards = self.config("cards", False)
self.cards = self.config("cards", True)
self._user_cache = {}
self._init_sizes()

Expand Down Expand Up @@ -165,7 +165,7 @@ def _extract_card(self, tweet, files):
tweet, data["media_entities"].values(), files)
return

if self.videos:
if self.cards == "ytdl":
url = "ytdl:{}/i/web/status/{}".format(self.root, tweet["id_str"])
files.append({"url": url})

Expand Down

1 comment on commit f2e8aed

@God-damnit-all
Copy link
Contributor

Choose a reason for hiding this comment

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

Cards are currently not using fallback urls, example:

Doesn't work: https://pbs.twimg.com/card_img/1480683103182295041/3-FwSZII?format=jpg&name=orig
Doesn't work:
Works: https://pbs.twimg.com/card_img/1480683103182295041/3-FwSZII?format=jpg&name=medium

(However, gallery-dl reports 404.)

Please sign in to comment.