-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfind_vod.py
61 lines (50 loc) · 2.37 KB
/
find_vod.py
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
50
51
52
53
54
55
56
57
58
59
60
61
import requests
import _constants
class Vods:
def __init__(self, vod_id, vod_date, vod_name, vod_link, channel_name, vod_lenght, channel_id, vodtype):
msk_date = vod_date.split("T")[0]
msk_hour = str(int(vod_date.split("T")[1].split(":")[0]) + 3)
msk_min = vod_date.split("T")[1].split(":")[1]
msk_sec = vod_date.split("T")[1].split(":")[2]
self.vod_date = f"{msk_date} {msk_hour}:{msk_min}:{msk_sec[:-1]}"
self.vod_id = vod_id[1:]
self.vod_name = vod_name
if vodtype == "archive":
self.vod_link = vod_link + "{res_fps}/index-dvr.m3u8"
elif vodtype == "highlight":
self.vod_link = vod_link + "{res_fps}" + f"/highlight-{self.vod_id}.m3u8"
elif vodtype == "upload":
self.vod_link = vod_link + "720p60/index-dvr.m3u8"
self.channel = channel_name
self.channelid = channel_id
self.vod_lenght = vod_lenght
def __str__(self):
return self.vod_name[:35] + "... | " + self.vod_date
def vod_list_creater(channel_name, vodtype):
# Request headers.
headers = {'Accept': _constants.application,
'Client-ID': _constants.client_id}
# Requesting channel id from api, using channel name.
id_req_link = f"https://api.twitch.tv/kraken/users?login={channel_name}"
id_req = requests.get(id_req_link, headers=headers).json()
if 'error' in id_req:
return "Invalid channel name, try again..."
if id_req['_total'] == 0:
return "Invalid channel name, try again..."
channel_id = id_req['users'][0]['_id']
# Requesting links of vods from api, using channel id.
video_req_link = f"https://api.twitch.tv/kraken/channels/{channel_id}/videos?broadcast_type={vodtype}&limit=100"
video_req = requests.get(video_req_link, headers=headers).json()
if len(dict(video_req)["videos"]) == 0:
return "Vod list is empty,try again..."
# Creating list of Vod objects.
dict_resp = dict(video_req)
vod_list = []
for vod in dict_resp["videos"]:
vod_lenght = int(vod['length'])
vod_id = str(vod["_id"])
vod_date = str(vod["created_at"])
vod_name = str(vod["title"])
vod_link = str(vod['seek_previews_url'].split("storyboards")[0])
vod_list.append(Vods(vod_id, vod_date, vod_name, vod_link, channel_name, vod_lenght, channel_id, vodtype))
return vod_list