-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtwitch_handler.py
More file actions
49 lines (40 loc) · 1.5 KB
/
twitch_handler.py
File metadata and controls
49 lines (40 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import requests
from get_token import get_twitch_token, get_client_id
def get_clip_info(clip_list: list) -> list:
"""
Takes a clip ID.\n
Returns the braodcaster name, language, viewcount, title and url.
"""
CLIENT_ID = get_client_id()
AUTH_TOKEN = get_twitch_token()
API_URL = 'https://api.twitch.tv/helix/clips'
clip_info_list = []
headers = {
'Client-ID': CLIENT_ID,
'Authorization': AUTH_TOKEN,
}
for clip in clip_list:
clip_id = clip.split('/')[-1]
params = {
'id':clip_id,
}
response = requests.get(API_URL, params=params, headers=headers)
# Check if the request was successful
if response.status_code == 200:
# Parse the JSON response
data = response.json()
# Extract the desired values
if data["data"]: # Check if data is not empty
clip_info = {
"broadcaster_name": data["data"][0]["broadcaster_name"],
"language": data["data"][0]["language"],
"view_count": data["data"][0]["view_count"],
"title": data["data"][0]["title"],
"url": data["data"][0]["url"]
}
clip_info_list.append(clip_info)
else:
print(f"No data found for clip ID {clip_id}")
else:
print(f"Failed to retrieve data for {clip}. Status code:", response.status_code)
return clip_info_list