-
Notifications
You must be signed in to change notification settings - Fork 0
/
gfycat.py
37 lines (27 loc) · 948 Bytes
/
gfycat.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
import requests
from data_manager import DataStore
import utils
BASE_URL = 'https://api.gfycat.com/v1'
def upload(file_path):
"""Uploads a video to gfycat
Args:
file_path (string): Path to the video to be uploaded.
Returns:
A string representing the url to the uploaded video.
"""
filename = utils.get_filename(file_path)
body = {
'title': filename,
'tags': ['leagueoflegends', 'League of Legends'],
'noMd5': True
}
token = DataStore.get_gfycat_token()
auth_header = {'Authorization': f'Bearer {token}'}
url = f'{BASE_URL}/gfycats'
response = requests.post(url, json=body, headers=auth_header)
gfyname = response.json()['gfyname']
upload_url = f'https://filedrop.gfycat.com/{gfyname}'
with open(file_path, 'rb') as video:
response = requests.put(upload_url, video)
video_url = f'https://gfycat.com/{gfyname}'
return video_url