Skip to content
Snippets Groups Projects
Commit d16ac203 authored by MARCHAL Julien's avatar MARCHAL Julien
Browse files

lot of changes

parent 140590d7
No related branches found
No related tags found
No related merge requests found
import requests
from requests_toolbelt.multipart.encoder import MultipartEncoder
import csv
import sys
import json
import os
import config
headers_json={
'Content-Type':'application/json',
'Authorization': 'Token {}'.format(config.POD_TOKEN)
}
try:
inputCsvFile=sys.argv[1]
except IndexError as e:
sys.exit('No file name in input param')
# READ CSV FILE
try:
with open(inputCsvFile, newline='') as csvfile:
reader = csv.reader(csvfile, delimiter=',', quotechar='|')
for row in reader:
if(row[0].startswith("#") != True):
username=row[0]
video_type=row[1]
video_title=row[2]
video_description=row[3]
video_allow_downloading=row[4]
video_is_draft=row[5]
video_file=row[6]
# print("%s %s %s %s %s %s %s" % (username, video_type, video_title, video_description, video_allow_downloading, video_is_draft, video_file))
# TEST IF USER EXIST
payload_search_user={
"username": username
}
response = requests.get(config.POD_API_USERS, headers=headers_json, params=payload_search_user)
if(response.status_code != 200):
print("ERROR Test User exists [%s] : [CODE:%s] [MSG:%s]" % (username,response.status_code, json.loads(response.content.decode("utf-8"))))
else:
result = json.loads(response.content.decode("utf-8"))
if(result['count'] != 1):
print("User not found [%s] [%s]" % (username, video_file))
else:
# print(result)
user_url=result['results'][0]['url']
# INSERT NEW VIDEO
stream_video_file = open(video_file, 'rb')
name_video_file = os.path.basename(video_file)
multipart_data = MultipartEncoder(
fields={
'owner': user_url,
'type': config.VIDEO_TYPE_BASE+video_type+"/",
'title': video_title,
'description': video_description,
'allow_downloading': video_allow_downloading,
'is_draft': video_is_draft,
'sites': config.VIDEO_SITE,
'video': (name_video_file, stream_video_file, 'text/plain')
}
)
headers_multipart=headers_json
headers_multipart['Content-Type']=multipart_data.content_type
response = requests.post(config.POD_API_UPLOAD_VIDEO, headers=headers_multipart, data=multipart_data)
if(response.status_code != 201):
print("ERROR Insert video [%s] : [CODE:%s] [MSG:%s]" % (username,response.status_code, json.loads(response.content.decode("utf-8"))))
else:
result = json.loads(response.content.decode("utf-8"))
slug = result['slug']
print("Insert video [USER:%s] [FILE:%s] [SLUG:%s]" % (username, video_file, slug))
# LAUNCH VIDEO ENCODE
if(config.LAUNCH_ENCODE_AFTER_PUT):
payload_encode_video={
"slug": slug
}
response = requests.get(config.POD_API_LAUNCH_ENCODE, headers=headers_json, params=payload_encode_video)
if(response.status_code != 200):
print("ERROR Launch encode video [%s] : [CODE:%s] [MSG:%s]" % (username,response.status_code, json.loads(response.content.decode("utf-8"))))
else:
print("Encode video is launch [USER:%s] [FILE:%s] [SLUG:%s]" % (username, video_file, slug))
except FileNotFoundError as e:
print('File [%s] not found' % inputCsvFile)
\ No newline at end of file
......@@ -45,7 +45,7 @@ try:
else:
result = json.loads(response.content.decode("utf-8"))
if(result['count'] != 1):
print("User not foung [%s] [%s]" % (username))
print("User not found [%s] [%s]" % (username, video_file))
else:
# print(result)
......@@ -79,14 +79,15 @@ try:
print("Insert video [USER:%s] [FILE:%s] [SLUG:%s]" % (username, video_file, slug))
# LAUNCH VIDEO ENCODE
payload_encode_video={
"slug": slug
}
response = requests.get(config.POD_API_LAUNCH_ENCODE, headers=headers_json, params=payload_encode_video)
if(response.status_code != 200):
print("ERROR Launch encode video [%s] : [CODE:%s] [MSG:%s]" % (username,response.status_code, json.loads(response.content.decode("utf-8"))))
else:
print("Encode video is launch [USER:%s] [FILE:%s] [SLUG:%s]" % (username, video_file, slug))
if(config.LAUNCH_ENCODE_AFTER_PUT):
payload_encode_video={
"slug": slug
}
response = requests.get(config.POD_API_LAUNCH_ENCODE, headers=headers_json, params=payload_encode_video)
if(response.status_code != 200):
print("ERROR Launch encode video [%s] : [CODE:%s] [MSG:%s]" % (username,response.status_code, json.loads(response.content.decode("utf-8"))))
else:
print("Encode video is launch [USER:%s] [FILE:%s] [SLUG:%s]" % (username, video_file, slug))
except FileNotFoundError as e:
print('File [%s] not found' % inputCsvFile)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment