Giter Site home page Giter Site logo

Comments (1)

bashonly avatar bashonly commented on July 19, 2024

Twitter has two different concepts of embedded URLs: a "card", and a pure link. The Meta tweet is an example of a "card": it has a large image (the card) that is also clickable as a link to the content. Your other two examples are pure links.

yt-dlp's Twitter extractor prioritizes cards over pure links, since cards can also be actual embedded videos, Twitter broadcasts, Spaces, etc. It tries to extract the card from the Meta tweet, but it doesn't recognize the card "name", so it returns no formats found (i.e. extracts tweet metadata without a video or URL result).

Adding the missing card name to the extractor's code would fix the inconsistency:

diff --git a/yt_dlp/extractor/twitter.py b/yt_dlp/extractor/twitter.py
index ecc865655..cfd34eff4 100644
--- a/yt_dlp/extractor/twitter.py
+++ b/yt_dlp/extractor/twitter.py
@@ -1499,7 +1499,7 @@ def get_binding_value(k):
                     'url': f'https://twitter.com/i/spaces/{get_binding_value("id")}',
                     'ie_key': TwitterSpacesIE.ie_key(),
                 }
-            elif card_name == 'summary':
+            elif card_name in ('summary', 'summary_large_image'):
                 yield {
                     '_type': 'url',
                     'url': get_binding_value('card_url'),

However, some more investigation should probably be done on other potential card names to be included in this tuple.

I do get the sense that maybe what you really want is to be able to extract tweet metadata for all tweets instead of following any of these redirects. It should be stated that yt-dlp is first and foremost an audio/video downloader, not a metadata extractor. If no video is embedded in the tweet, yt-dlp will (and should) follow the embedded URL to try to find any video at its destination. The ability to extract pure tweet metadata was added to the Twitter extractor as a bonus; it is not the focus. But if you want to be able to extract only twitter metadata from every tweet, this is possible via the yt-dlp Python API and the extract_flat param:

import json
import yt_dlp

URL = 'https://twitter.com/YouTube/status/1780725427520065913'

ydl_opts = {
    'extract_flat': True,
    'ignore_no_formats_error': True,
    'no_warnings': True,
    'quiet': True,
}

with yt_dlp.YoutubeDL(ydl_opts) as ydl:
    info = ydl.extract_info(URL, download=False)
    info = ydl.sanitize_info(info)

print(json.dumps(info))

from yt-dlp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.