twitter-archive-to-wp icon indicating copy to clipboard operation
twitter-archive-to-wp copied to clipboard

Tweets with multiple media items only import one item

Open rosswintle opened this issue 2 years ago • 1 comments

The code for importing media looks for foreach($tweet->entities->media as $media) {

I think this should look for foreach($tweet->extended_entities->media as $media) {

Example JSON code with multiple media items
{
    "tweet": {
        "edit_info": {
            "initial": {
                "editTweetIds": [
                    "1585687394283552796"
                ],
                "editableUntil": "2022-10-27T18:08:30.000Z",
                "editsRemaining": "5",
                "isEditEligible": false
            }
        },
        "retweeted": false,
        "source": "<a href=\"http://tapbots.com/tweetbot\" rel=\"nofollow\">Tweetbot for iΟS</a>",
        "entities": {
            "user_mentions": [
                {
                    "name": "Michelle Frechette",
                    "screen_name": "michelleames",
                    "indices": [
                        "0",
                        "13"
                    ],
                    "id_str": "19908128",
                    "id": "19908128"
                }
            ],
            "urls": [],
            "symbols": [],
            "media": [
                {
                    "expanded_url": "https://twitter.com/magicroundabout/status/1585687394283552796/photo/1",
                    "indices": [
                        "181",
                        "204"
                    ],
                    "url": "https://t.co/pe65eRH3i9",
                    "media_url": "http://pbs.twimg.com/media/FgF-QToWAA0aB5f.jpg",
                    "id_str": "1585687362423619597",
                    "id": "1585687362423619597",
                    "media_url_https": "https://pbs.twimg.com/media/FgF-QToWAA0aB5f.jpg",
                    "sizes": {
                        "large": {
                            "w": "2048",
                            "h": "1536",
                            "resize": "fit"
                        },
                        "medium": {
                            "w": "1200",
                            "h": "900",
                            "resize": "fit"
                        },
                        "thumb": {
                            "w": "150",
                            "h": "150",
                            "resize": "crop"
                        },
                        "small": {
                            "w": "680",
                            "h": "510",
                            "resize": "fit"
                        }
                    },
                    "type": "photo",
                    "display_url": "pic.twitter.com/pe65eRH3i9"
                }
            ],
            "hashtags": []
        },
        "display_text_range": [
            "0",
            "204"
        ],
        "favorite_count": "2",
        "in_reply_to_status_id_str": "1585309586810376197",
        "id_str": "1585687394283552796",
        "in_reply_to_user_id": "19908128",
        "truncated": false,
        "retweet_count": "0",
        "id": "1585687394283552796",
        "in_reply_to_status_id": "1585309586810376197",
        "possibly_sensitive": false,
        "created_at": "Thu Oct 27 17:38:30 +0000 2022",
        "favorited": false,
        "full_text": "@michelleames Mine is an App Launcher/Switcher. No Apple Dock. No Spotlight or Alfred. No Cmd-Tab. Just straight to where you need to be!\n\nAlso: Quick shortcuts for my code editor. https://t.co/pe65eRH3i9",
        "lang": "en",
        "in_reply_to_screen_name": "michelleames",
        "in_reply_to_user_id_str": "19908128",
        "extended_entities": {
            "media": [
                {
                    "expanded_url": "https://twitter.com/magicroundabout/status/1585687394283552796/photo/1",
                    "indices": [
                        "181",
                        "204"
                    ],
                    "url": "https://t.co/pe65eRH3i9",
                    "media_url": "http://pbs.twimg.com/media/FgF-QToWAA0aB5f.jpg",
                    "id_str": "1585687362423619597",
                    "id": "1585687362423619597",
                    "media_url_https": "https://pbs.twimg.com/media/FgF-QToWAA0aB5f.jpg",
                    "sizes": {
                        "large": {
                            "w": "2048",
                            "h": "1536",
                            "resize": "fit"
                        },
                        "medium": {
                            "w": "1200",
                            "h": "900",
                            "resize": "fit"
                        },
                        "thumb": {
                            "w": "150",
                            "h": "150",
                            "resize": "crop"
                        },
                        "small": {
                            "w": "680",
                            "h": "510",
                            "resize": "fit"
                        }
                    },
                    "type": "photo",
                    "display_url": "pic.twitter.com/pe65eRH3i9"
                },
                {
                    "expanded_url": "https://twitter.com/magicroundabout/status/1585687394283552796/photo/1",
                    "indices": [
                        "181",
                        "204"
                    ],
                    "url": "https://t.co/pe65eRH3i9",
                    "media_url": "http://pbs.twimg.com/media/FgF-QV9WAAMkPtX.jpg",
                    "id_str": "1585687363048570883",
                    "id": "1585687363048570883",
                    "media_url_https": "https://pbs.twimg.com/media/FgF-QV9WAAMkPtX.jpg",
                    "sizes": {
                        "medium": {
                            "w": "1200",
                            "h": "900",
                            "resize": "fit"
                        },
                        "small": {
                            "w": "680",
                            "h": "510",
                            "resize": "fit"
                        },
                        "thumb": {
                            "w": "150",
                            "h": "150",
                            "resize": "crop"
                        },
                        "large": {
                            "w": "2048",
                            "h": "1536",
                            "resize": "fit"
                        }
                    },
                    "type": "photo",
                    "display_url": "pic.twitter.com/pe65eRH3i9"
                }
            ]
        }
    }
}

But I think there's more to it than that.

I'll see if I can put together a PR that fixes this and allows multiple media Tweets.

Would you also be up for adding a flag the imports media to the media library?

rosswintle avatar Feb 02 '23 21:02 rosswintle

@rosswintle It'd be great if you could put together a PR for that. And yeah, a flag for --import-media would be great. I don't want that as the default, as it would really clutter up the media library, especially if imported into someone's main site.

shawnhooper avatar Feb 02 '23 23:02 shawnhooper