Skip to content

Instantly share code, notes, and snippets.

@chand1012
Last active September 6, 2021 04:39
Show Gist options
  • Save chand1012/d947537662c7962cb968548c0040306f to your computer and use it in GitHub Desktop.
Save chand1012/d947537662c7962cb968548c0040306f to your computer and use it in GitHub Desktop.
Requires Twitch-Python. Gets all of the top streamer's videos as JSON and outputs a JSON file with the information. See the license here: https://chand1012.mit-license.org/
import os
import json
from twitch import Helix
from twitch.helix.models.video import Video
def video_to_dict(video: Video):
return {
'id': video.id,
'user_id': video.user_id,
'user_name': video.user_name,
'created_at': video.created_at,
'title': video.title,
'type': video.type,
'viewable': video.viewable,
'url': video.url,
'description': video.description,
'view_count': video.view_count,
'published_at': video.published_at,
'thumbnail_url': video.thumbnail_url,
'language': video.language,
'duration': video.duration
}
twitch = Helix(os.environ.get('TWITCH_ID'), os.environ.get('TWITCH_SECRET'))
streamer = twitch.stream()
data = []
user = streamer.user
print(f'Getting data for {user.login}...')
videos = user.videos()
for video in videos:
data += [video_to_dict(video)]
with open(f'{user.login}.json', 'w') as f:
f.write(json.dumps(data, indent=4, sort_keys=True))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment