-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdm_update_metadata.py
More file actions
50 lines (37 loc) · 1.25 KB
/
dm_update_metadata.py
File metadata and controls
50 lines (37 loc) · 1.25 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
50
# -*- coding: utf-8 -*-
import json
import re
import config
import csv
import pandas as pd
import dailymotion
import argparse
parser = argparse.ArgumentParser(description='Update video metadata using a CSV.')
parser.add_argument('csv_file', type=str, help='CSV file with metadata')
args = parser.parse_args()
CSV_FILE = args.csv_file
DEST_PATH = ''
DM_PLAYLIST_API = '/video/{0}'
d = dailymotion.Dailymotion()
api_key = config.CLIENT_ID
api_secret = config.CLIENT_SECRET
api_username = config.USERNAME
api_password = config.PASSWORD
api_url = config.BASE_URL
d.set_grant_type('password', api_key, api_secret,
scope=['manage_videos'], info={'username': api_username, 'password': api_password})
def read_from_csv(csv_file):
video_df = pd.read_csv(csv_file, encoding='utf-8')
return video_df
def update_video_metadata(video_df):
for row in video_df.itertuples(index=False, name='video_to_update'):
print(f'Updating {row.video_title}')
d.post(DM_PLAYLIST_API.format(row.video_id),
{'description' : getattr(row, 'video_description'),
'title' : getattr(row, 'video_title')})
def main():
video_df = read_from_csv(CSV_FILE)
print(video_df)
update_video_metadata(video_df)
if __name__ == "__main__":
main()