-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclipdownload.py
49 lines (40 loc) · 1.31 KB
/
clipdownload.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
from datetime import date
import requests
import urllib.request
import os
import json
def clipdownload(link, DIRECTORY):
invalid = ['/', '\\', ':', '*', '?', '\"', '<', '>', '|']
payload={}
headers = {
'Client-ID': '',
'Accept': 'application/vnd.twitchtv.v5+json'
}
"""
try:
os.mkdir(DIRECTORY+"\clips\\")
print("Created \"\\clips\"")
except:
print()
"""
try:
temp = link["url"].replace("https://clips.twitch.tv", "https://api.twitch.tv/kraken/clips")
response = (requests.request("GET", temp, headers=headers, data=payload))
#print(response.json())
url = response.json()['thumbnails']['small']
url = url.replace("-preview-260x147.jpg", ".mp4")
name = link["title"]
except:
print("Download unsuccessful\n")
print("Clip not found: 404")
return(404)
invalidtitle = link["title"]
for x in invalid:
invalidtitle = invalidtitle.replace(x, "")
print(("ATTEMPTING TO DOWNLOAD: ") + "{}: ({})\n".format(name,url))
try:
urllib.request.urlretrieve(url, (DIRECTORY+"/clips/"+invalidtitle+".mp4"))
print("Download successful\n")
except:
print("Download unsuccessful\n")
#return (response)