I was able to download Twitch clips and entire VODs using this library as an embed code in my program written in Python.
The download_clip function takes input from the link, which extracts the slug from the clip, rearranging the link used for the download itself.
I was reading the tool repository and I can't find any information if there is any way to query the game information on such clips.
Specifically, I need to know what game was being played during the livestream so I can validate my analysis later.
I am able to download clips using the following code:
def download_clip(link: str):
clip_id = get_clip_slug(link)
url = f'https://clips.twitch.tv/{clip_id}'
ydl_opts = {'format': 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best'}
try:
with YoutubeDL(ydl_opts) as ydl:
ydl.download([url])
except:
print('Not working..')
I also took a look at the youtube-dl and its exactly the same thing.. I can't find any info about it. Any workaround or tips?
Unfortunately only videos with chapters provide the info I was looking for (while utilizing yt_dlp) and since I'm working with Twitch clips I decided to give a try to the official Twitch API.
I was able to request the infos desired with the following code:
def check_game_id(link):
slug = obter_id_clip(link)
headers = {'Authorization': f'Bearer {access_token}', 'Client-Id': client_id}
params = {'id': slug}
response = requests.get('https://api.twitch.tv/helix/clips', params=params, headers=headers)
informacoes = response.json()
game_id = informacoes['data'][0]['game_id']
return game_id