Skip to content

Instantly share code, notes, and snippets.

@lunasorcery
Created November 11, 2022 03:14
Show Gist options
  • Save lunasorcery/caeff957c35fb066e0a64b0bd90ade18 to your computer and use it in GitHub Desktop.
Save lunasorcery/caeff957c35fb066e0a64b0bd90ade18 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import os
import json
with open('tweets.js') as f:
tweets_str = f.read()
# assume the prefix is universally the same ('window.YTD.tweets.part0 = ')
tweets_json = json.loads(tweets_str[26:])
tweets_media = [{
'tweet': {
'id': tweet['tweet']['id'],
'id_str': tweet['tweet']['id_str'],
#'entities': tweet['tweet']['entities'],
'extended_entities': tweet['tweet']['extended_entities'],
}
} for tweet in tweets_json if 'media' in tweet['tweet']['entities']]
with open('./tweets-media.js', 'w') as f:
f.write('window.YTD.tweets.part0 = ')
f.write(json.dumps(tweets_media, indent=4))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment