Last active
September 6, 2021 04:39
-
-
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/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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