FixTweet / FxTwitter

Fix broken Twitter/X embeds! Use multiple images, videos, polls, translations and more on Discord, Telegram and others
https://fxtwitter.com
MIT License
2.62k stars 77 forks source link

Request to improve consistency of direct media links #648

Open seriaati opened 8 months ago

seriaati commented 8 months ago

The problem

The readme says adding /photo/{index} after the post ID allows getting the other medias in the post.
For example, this post https://twitter.com/qiandaiyiyu/status/1753349204380938507 has 3 images, and the following can get all 3 of them:

However, if I request to https://d.fxtwitter.com/qiandaiyiyu/status/1753349204380938507/photo/4, fxtwitter will return the first image for some reason, then https://d.fxtwitter.com/qiandaiyiyu/status/1753349204380938507/photo/5 leads to https://github.com/FixTweet/FxTwitter.
My project uses fxtwitter to extract media (URL)s directly from the post and send them in a Discord channel, but with the current behavior, I can only send the first image URL because I don't have a consistent way of knowing how many medias this post has.

My suggestion

Without considering how fxtwitter works internally (I haven't read the code yet), I have 2 suggestions to resolve this issue:

  1. Return 404 when requesting an invalid media index: With the example above, /photo/4 and beyond should return a 404. This way I can iterate through the indexes from 1 and continue until a 404.
  2. Create a GET API that returns information about a post given the post ID: Maybe something like this:
    {
    "id": 12345,
    "content": "something this post says about",
    "medias": [
    "https://pbs.twimg.com/media/GFUk9BRXoAA2zi0",
    "..."
    ]
    }
dangeredwolf commented 8 months ago

About the 2nd point, we actually have an API for FxTwitter (see api.fxtwitter.com). Not sure if that's helpful in your case. It would probably be a good idea to improve direct media's behavior here cause right now it's handled the same as embeds but it would be probably more useful to actually only return the media if it was found

seriaati commented 8 months ago

Nice, the API works for me. It's up to you if you want to fix the direct media links.