robertoszek / pleroma-bot

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

Tweets with multiple images losing media #9

Closed robertoszek closed 3 years ago

robertoszek commented 3 years ago

On tweets such as this one (https://twitter.com/WoolieWoolz/status/1314252985426489350) that have multiple images only the first one gets posted into the Fediverse account.

JSON:

[
   {
      'created_at':'Thu Oct 08 17:15:04 +0000 2020',
      'id':1314252985426489350,
      'id_str':'1314252985426489350',
      'text':'http://twitch.tv/woolieversus https://t.co/LMXdjjUhUF',
      'truncated':False,
      'entities':{
         'hashtags':[

         ],
         'symbols':[

         ],
         'user_mentions':[

         ],
         'urls':[
            {
               'url':'https://t.co/xuC3tPBiKd',
               'expanded_url':'http://twitch.tv/woolieversus',
               'display_url':'twitch.tv/woolieversus',
               'indices':[
                  0,
                  23
               ]
            }
         ],
         'media':[
            {
               'id':1314252981282500609,
               'id_str':'1314252981282500609',
               'indices':[
                  24,
                  47
               ],
               'media_url':'http://pbs.twimg.com/media/Ej0qH45XcAEyJPw.jpg',
               'media_url_https':'https://pbs.twimg.com/media/Ej0qH45XcAEyJPw.jpg',
               'url':'https://t.co/LMXdjjUhUF',
               'display_url':'pic.twitter.com/LMXdjjUhUF',
               'expanded_url':'https://twitter.com/WoolieWoolz/status/1314252985426489350/photo/1',
               'type':'photo',
               'sizes':{
                  'thumb':{
                     'w':150,
                     'h':150,
                     'resize':'crop'
                  },
                  'small':{
                     'w':376,
                     'h':680,
                     'resize':'fit'
                  },
                  'medium':{
                     'w':434,
                     'h':785,
                     'resize':'fit'
                  },
                  'large':{
                     'w':434,
                     'h':785,
                     'resize':'fit'
                  }
               }
            }
         ]
      },
      'extended_entities':{
         'media':[
            {
               'id':1314252981282500609,
               'id_str':'1314252981282500609',
               'indices':[
                  24,
                  47
               ],
               'media_url':'http://pbs.twimg.com/media/Ej0qH45XcAEyJPw.jpg',
               'media_url_https':'https://pbs.twimg.com/media/Ej0qH45XcAEyJPw.jpg',
               'url':'https://t.co/LMXdjjUhUF',
               'display_url':'pic.twitter.com/LMXdjjUhUF',
               'expanded_url':'https://twitter.com/WoolieWoolz/status/1314252985426489350/photo/1',
               'type':'photo',
               'sizes':{
                  'thumb':{
                     'w':150,
                     'h':150,
                     'resize':'crop'
                  },
                  'small':{
                     'w':376,
                     'h':680,
                     'resize':'fit'
                  },
                  'medium':{
                     'w':434,
                     'h':785,
                     'resize':'fit'
                  },
                  'large':{
                     'w':434,
                     'h':785,
                     'resize':'fit'
                  }
               }
            },
            {
               'id':1314252981274112008,
               'id_str':'1314252981274112008',
               'indices':[
                  24,
                  47
               ],
               'media_url':'http://pbs.twimg.com/media/Ej0qH43XcAgTIk9.jpg',
               'media_url_https':'https://pbs.twimg.com/media/Ej0qH43XcAgTIk9.jpg',
               'url':'https://t.co/LMXdjjUhUF',
               'display_url':'pic.twitter.com/LMXdjjUhUF',
               'expanded_url':'https://twitter.com/WoolieWoolz/status/1314252985426489350/photo/1',
               'type':'photo',
               'sizes':{
                  'large':{
                     'w':1094,
                     'h':1500,
                     'resize':'fit'
                  },
                  'thumb':{
                     'w':150,
                     'h':150,
                     'resize':'crop'
                  },
                  'small':{
                     'w':496,
                     'h':680,
                     'resize':'fit'
                  },
                  'medium':{
                     'w':875,
                     'h':1200,
                     'resize':'fit'
                  }
               }
            }
         ]
      },
      'source':'<a href="http://twitter.com/download/iphone" rel="nofollow">Twitter for iPhone</a>',
      'in_reply_to_status_id':None,
      'in_reply_to_status_id_str':None,
      'in_reply_to_user_id':None,
      'in_reply_to_user_id_str':None,
      'in_reply_to_screen_name':None,
      'user':{
         'id':2562363992,
         'id_str':'2562363992',
         'name':'Woolie Versus',
         'screen_name':'WoolieWoolz',
         'location':'Montreal',
         'description':"Rewinding sucks. Vergil is life. Kirby is hometown. #Punchgirl is truth. Stands are real. {podcasts} {let's plays} {fighting games} https://t.co/CTAE8bMA1Q",
         'url':'https://t.co/S4CsnvPB95',
         'entities':{
            'url':{
               'urls':[
                  {
                     'url':'https://t.co/S4CsnvPB95',
                     'expanded_url':'http://youtube.com/WoolieVersus',
                     'display_url':'youtube.com/WoolieVersus',
                     'indices':[
                        0,
                        23
                     ]
                  }
               ]
            },
            'description':{
               'urls':[
                  {
                     'url':'https://t.co/CTAE8bMA1Q',
                     'expanded_url':'http://linktr.ee/wooliewoolz',
                     'display_url':'linktr.ee/wooliewoolz',
                     'indices':[
                        132,
                        155
                     ]
                  }
               ]
            }
         },
         'protected':False,
         'followers_count':106567,
         'friends_count':701,
         'listed_count':253,
         'created_at':'Thu Jun 12 00:44:01 +0000 2014',
         'favourites_count':2401,
         'utc_offset':None,
         'time_zone':None,
         'geo_enabled':True,
         'verified':False,
         'statuses_count':15789,
         'lang':None,
         'contributors_enabled':False,
         'is_translator':False,
         'is_translation_enabled':False,
         'profile_background_color':'000000',
         'profile_background_image_url':'http://abs.twimg.com/images/themes/theme14/bg.gif',
         'profile_background_image_url_https':'https://abs.twimg.com/images/themes/theme14/bg.gif',
         'profile_background_tile':False,
         'profile_image_url':'http://pbs.twimg.com/profile_images/1257467851184705542/Uw00CuX__normal.jpg',
         'profile_image_url_https':'https://pbs.twimg.com/profile_images/1257467851184705542/Uw00CuX__normal.jpg',
         'profile_banner_url':'https://pbs.twimg.com/profile_banners/2562363992/1598651481',
         'profile_link_color':'19CF86',
         'profile_sidebar_border_color':'000000',
         'profile_sidebar_fill_color':'000000',
         'profile_text_color':'000000',
         'profile_use_background_image':False,
         'has_extended_profile':True,
         'default_profile':False,
         'default_profile_image':False,
         'following':None,
         'follow_request_sent':None,
         'notifications':None,
         'translator_type':'none'
      },
      'geo':None,
      'coordinates':None,
      'place':None,
      'contributors':None,
      'is_quote_status':False,
      'retweet_count':9,
      'favorite_count':110,
      'favorited':False,
      'retweeted':False,
      'possibly_sensitive':False,
      'lang':'und'
   }
]
robertoszek commented 3 years ago

Fixed it by using the 'extended_entities' field on the Twitter's API response, that includes all of the attachments, not only the first one. Link to the commit