robertoszek / pleroma-bot

Bot for mirroring one or multiple Twitter accounts in Pleroma/Mastodon/Misskey.
https://robertoszek.github.io/pleroma-bot
MIT License
102 stars 19 forks source link

had some issues with media causing a hang #90

Closed tewhalen closed 1 year ago

tewhalen commented 1 year ago

I ran across a tweet which caused the program to hang at "Processing tweets..." --

tweet # 1591637643376267265, which claims to contain a photo... but the "url" seems to point to a tweet (https://t.co/BMw6NhM0Ll), not to an image. I made a quick edit to _download_media that seemed to solve the problem by preferring a "media_url" if one is present, but not sure if it would screw up something else...

def _download_media(self, media, tweet):
    for idx, item in enumerate(media):
        if item["type"] != "video" and item["type"] != "animated_gif":
            if "media_url" in item:
                media_url = item['media_url']
            else:
                media_url = item["url"]
robertoszek commented 1 year ago

Hi, Thanks for reporting this! Nice find!

You're indeed correct, this video (seems to be published from Twitter Media Studio) unfortunately reports itself as a photo in the API (both in v1.1 and v2) and the "url" points to the same tweet.

Your workaround seems like the best approach at getting at least some media in return. And as far as affecting other media elements I think it's actually fine, the 'photo' type usually doesn't include a "media_url":

[
   {
      "type":"photo",
      "height":1000,
      "media_key":"3_1574898376952487965",
      "url":"https://pbs.twimg.com/media/FdspusuXoB0wfEH.jpg",
      "alt_text":"Alt text",
      "width":680
   }
]

And if they do, it's probably something funky like the example video you provided. In which case we'll prefer using "media_url" over "url" if it exists.

Do you want to create a merge request to the develop branch so you're properly credited for the change? Either that or if you don't have the time to do it, I could commit the change myself and credit you on the release changes as well if you prefer.

Thanks once again!

tewhalen commented 1 year ago

please commit it yourself, i'm not interested in credit

robertoszek commented 1 year ago

Sounds good, I'll get to it. Thanks for your contribution!