-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathupload2dailymotion.py
54 lines (49 loc) · 1.5 KB
/
upload2dailymotion.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
"""
Youtube changed their upload API access (boooo)
Switching to use daily motion
"""
import argparse as ap
import dailymotion as dm
import dailymotion_secrets as dms
import pymysql
def log_video_id(video_id, night):
"""
Log the video ID to the database
"""
qry = """
INSERT INTO daily_movies
(night, youtube_id)
VALUES (%s, %s)
"""
qry_args = (night, video_id,)
with pymysql.connect(host='ds', db='ngts_ops') as cur:
cur.execute(qry, qry_args)
def parse_args():
"""
Parse the command line arguments
"""
p = ap.ArgumentParser()
p.add_argument('file',
type=str,
help='path to video to upload')
p.add_argument('title',
type=str,
help='title for video (e.g. 2020-01-01)')
return p.parse_args()
if __name__ == "__main__":
args = parse_args()
d = dm.Dailymotion()
d.set_grant_type('password',
api_key=dms.api_key,
api_secret=dms.api_secret,
scope=['manage_videos'],
info={'username': dms.username,
'password': dms.password})
url = d.upload(args.file)
res = d.post('/me/videos', {'url': url,
'title': args.title,
'published': 'true',
'channel': 'news'})
movie_id = res['id']
print(movie_id)
log_video_id(movie_id, args.title)