Skip to content

Conversation

rosswintle
Copy link
Contributor

Resolves #17

This is a fairly major refactor of media handling. It enables:

  • Import of mulitple media items for each tweet
  • Import of video media
  • Import of animated GIFs (Twitter converted these to mp4s!)

It saves multiple media items using meta keys:

  • _tweet_media_x
  • _tweet_media_type_x

All media are added to the Tweet using img or video tags.

I've tried to keep to the filtering conventions you have used.

It attempts some optimisation by only updating the post once when processing media for a post, and by changing how files are looped through. Specifically:

  • I now load the media file list on initialization
  • I index the media file list by the Tweet ID
  • I use the index to only loop through the media files for the current Tweet

I did not implement a --import-media flag - this can be done another time.

I bumped the version number and updated the readme.txt

This now VERY NEARLY successfully processes my entire Tweet history and media. There is one media not found error. I've not investigated this yet.

Success: Import Complete!
Success: 61439 tweets processed
Success: 7303 tweets skipped
Success: 2821 media found
Success: 1 media not found
Success: 0 media had an unknown type

I'll leave this with you for review. I shall attempt to provide a minimal subset of my import for testing purposes, if that's helpful? But it's too late to do that today.

Thanks! Hope you like the improvements!


$post_id = $this->process_tweet($tweet, $this->post_author_id);

update_post_meta($post_id, '_tweet_id', $tweet->id);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was in process_media for some reason. I've moved it here.

@rosswintle
Copy link
Contributor Author

Actually... hold off on this. I want to add alt text to images if I can!

Shouldn't take long.

@rosswintle
Copy link
Contributor Author

Actually - looks like alt text isn't in the export. So don't wait for that. I'll still try and make you a test import though.

@rosswintle
Copy link
Contributor Author

rosswintle commented Feb 5, 2023

OK, here's a folder of test material. This includes:

  • A multi-image tweet
  • A tweet with an animated GIF
  • A tweet with a video

It does not include a tweet with multiple videos, but there's no reason I can see that that wouldn't work as well.

twitter-archive.zip

To test this you can just unzip this into the usual location in uploads/twitter-archive and run the importer.

@timnolte
Copy link

@shawnhooper any thoughts on merging in this?

@shawnhooper
Copy link
Owner

@timnolte I sure do! I just haven't had time to test it. I'll try to merge it this week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tweets with multiple media items only import one item
3 participants