def video_update(user_jwt, video_id, videoName, videoDesc, videoLoc, videoOwner, videoSubject, videoViewers, videoGroups): # # Updates a specified video file in the medvid.io API # input: # user_jwt - properly formed medvid.io JWT for Application User updating the video (will be set as owner) # MVID - Unique medvid.io user ID of Application User specified in user_jwt (will be set as 'owner_id') # videoName - Name of video file to be uploaded (will be set as 'title') # videoDesc - Description of video file to be uploaded (will be set as 'description') # videoLoc - "Filming Location" of video file to be uploaded (will be set as 'location') # videoPath - Path to file to be uploaded # videoSubject - Subject of video # videoViewers - Comma seperated list of video viewers medvid.io IDs # videoGroups - Comma seperated list of video group # output: # Api Reponse Status (boolean), # New Video Data {"video_title":video_title, # "video_id":video_id, # "MVID":MVID, # "video_created_at":video_created_at} # or None # Error Message (str) or None # Api Message (dict) # headers = { 'Content-Type': 'application/json', 'Accept': 'application/json', 'Authorization': 'Bearer ' + str(user_jwt) } uri = keys.apollo_root path = '/video/' + str(video_id) target = urlparse(uri + path) method = "PUT" user_viewer_ids = None if videoViewers: parsedVideoViewers = api_tools.api_parse_csv(videoViewers) if parsedVideoViewers and len(parsedVideoViewers) > 0: user_viewer_ids = parsedVideoViewers group_viewer_ids = None if videoGroups: parsedGroupViewers = api_tools.api_parse_csv(videoGroups) if parsedGroupViewers and len(parsedGroupViewers) > 0: group_viewer_ids = parsedGroupViewers body = { 'video': { 'title': videoName, 'description': videoDesc, 'location': videoLoc, 'user_viewer_ids': user_viewer_ids, 'group_viewer_ids': group_viewer_ids } } # Render human readable API message for output api_msg = api_tools.api_msg_render(headers, body, method, target.geturl()) #return False, p_id, None, api_msg h = httplib2.Http() response, content = h.request(target.geturl(), method, json.dumps(body), headers) # Response error; return fail if not content: return False, None, str(response), api_msg elif response.get("status") == "200": # Successful response; parse JSON data data = json.loads(content) video_data = data.get('video') output_data = {"video_id": video_data.get('id')} return True, output_data, None, api_msg # invalid response return False, None, "Response: " + str(response) + " Content: " + str( content), api_msg
def video_update(user_jwt, video_id, videoName, videoDesc, videoLoc, videoOwner, videoSubject, videoViewers, videoGroups): # # Updates a specified video file in the medvid.io API # input: # user_jwt - properly formed medvid.io JWT for Application User updating the video (will be set as owner) # MVID - Unique medvid.io user ID of Application User specified in user_jwt (will be set as 'owner_id') # videoName - Name of video file to be uploaded (will be set as 'title') # videoDesc - Description of video file to be uploaded (will be set as 'description') # videoLoc - "Filming Location" of video file to be uploaded (will be set as 'location') # videoPath - Path to file to be uploaded # videoSubject - Subject of video # videoViewers - Comma seperated list of video viewers medvid.io IDs # videoGroups - Comma seperated list of video group # output: # Api Reponse Status (boolean), # New Video Data {"video_title":video_title, # "video_id":video_id, # "MVID":MVID, # "video_created_at":video_created_at} # or None # Error Message (str) or None # Api Message (dict) # headers = { 'Content-Type': 'application/json', 'Accept': 'application/json', 'Authorization': 'Bearer ' + str(user_jwt) } uri = keys.apollo_root path = '/video/' + str(video_id) target = urlparse(uri+path) method = "PUT" user_viewer_ids = None if videoViewers: parsedVideoViewers = api_tools.api_parse_csv(videoViewers) if parsedVideoViewers and len(parsedVideoViewers) > 0: user_viewer_ids = parsedVideoViewers group_viewer_ids = None if videoGroups: parsedGroupViewers = api_tools.api_parse_csv(videoGroups) if parsedGroupViewers and len(parsedGroupViewers) > 0: group_viewer_ids = parsedGroupViewers body = { 'video':{ 'title':videoName, 'description':videoDesc, 'location':videoLoc, 'user_viewer_ids':user_viewer_ids, 'group_viewer_ids':group_viewer_ids } } # Render human readable API message for output api_msg = api_tools.api_msg_render(headers, body, method, target.geturl()) #return False, p_id, None, api_msg h = httplib2.Http() response, content = h.request(target.geturl(), method, json.dumps(body), headers) # Response error; return fail if not content: return False, None, str(response), api_msg elif response.get("status") == "200": # Successful response; parse JSON data data = json.loads(content) video_data = data.get('video') output_data = { "video_id":video_data.get('id') } return True, output_data, None, api_msg # invalid response return False, None, "Response: " + str(response) + " Content: "+ str(content), api_msg
def video_post(user_jwt, MVID, videoName, videoDesc, videoLoc, videoPath, videoSubject, videoViewers, videoGroups): # # Uploads a server side video file to the medvid.io API # input: # user_jwt - properly formed medvid.io JWT for Application User uploading the video (will be set as owner) # MVID - Unique medvid.io user ID of Application User specified in user_jwt (will be set as 'owner_id') # videoName - Name of video file to be uploaded (will be set as 'title') # videoDesc - Description of video file to be uploaded (will be set as 'description') # videoLoc - "Filming Location" of video file to be uploaded (will be set as 'location') # videoPath - Path to file to be uploaded # videoSubject - Subject of video # videoViewers - Comma seperated list of video viewers medvid.io IDs # videoGroups - Comma seperated list of video group # output: # Api Reponse Status (boolean), # New Video Data {"video_title":video_title, # "video_id":video_id, # "MVID":MVID, # "video_created_at":video_created_at} # or None # Error Message (str) or None # Api Message (dict) # headers = { 'Accept': 'application/json', 'Authorization': 'Bearer ' + str(user_jwt) } uri = keys.apollo_root path = '/video' url = uri + path # Attempt conversion to int; abondon and default to str if needed try: MVID = int(MVID) except: MVID = str(MVID) try: videoSubject = int(videoSubject) except: videoSubject = str(videoSubject) json_data = { "owner_id": MVID, "title": videoName, } if videoDesc: json_data.update({"description": videoDesc}) if videoLoc: json_data.update({"location": videoLoc}) if videoSubject: json_data.update({"subject_id": videoSubject}) if videoViewers: parsedVideoViewers = api_tools.api_parse_csv(videoViewers) if parsedVideoViewers and len(parsedVideoViewers) > 0: json_data.update({"user_viewer_ids": parsedVideoViewers}) if videoGroups: parsedVideoGroups = api_tools.api_parse_csv(videoGroups) if parsedVideoGroups and len(parsedVideoGroups) > 0: json_data.update({"group_viewer_ids": parsedVideoGroups}) # Assemble data for human readable cURL info temp_body = { '--form': "json=%s" % json.dumps(json_data), '-F': "media=@%s" % videoPath } # Render human readable API message for output api_msg = api_tools.api_msg_render(headers, temp_body, None, url) try: response = requests.post(url, data={"json": json.dumps(json_data)}, files={"media": open(videoPath, 'rb')}, headers=headers) except: return False, None, "Error: Request exception", api_msg if response.status_code != 201: return False, None, "Response: " + str( response.status_code) + " Content: " + str(response.text), api_msg # Successful Upload, parse JSON temp_data = response.json() output_data = { "video_title": str(temp_data['video']['title']), "video_id": str(temp_data['video']['id']), "MVID": str(MVID), "video_created_at": str(temp_data['video']['created_at']) } return True, output_data, None, api_msg
def video_post(user_jwt, MVID, videoName, videoDesc, videoLoc, videoPath, videoSubject, videoViewers, videoGroups): # # Uploads a server side video file to the medvid.io API # input: # user_jwt - properly formed medvid.io JWT for Application User uploading the video (will be set as owner) # MVID - Unique medvid.io user ID of Application User specified in user_jwt (will be set as 'owner_id') # videoName - Name of video file to be uploaded (will be set as 'title') # videoDesc - Description of video file to be uploaded (will be set as 'description') # videoLoc - "Filming Location" of video file to be uploaded (will be set as 'location') # videoPath - Path to file to be uploaded # videoSubject - Subject of video # videoViewers - Comma seperated list of video viewers medvid.io IDs # videoGroups - Comma seperated list of video group # output: # Api Reponse Status (boolean), # New Video Data {"video_title":video_title, # "video_id":video_id, # "MVID":MVID, # "video_created_at":video_created_at} # or None # Error Message (str) or None # Api Message (dict) # headers = { 'Accept': 'application/json', 'Authorization': 'Bearer ' + str(user_jwt) } uri = keys.apollo_root path = '/video' url = uri + path # Attempt conversion to int; abondon and default to str if needed try: MVID = int(MVID) except: MVID = str(MVID) try: videoSubject = int(videoSubject) except: videoSubject = str(videoSubject) json_data = { "owner_id":MVID, "title":videoName, } if videoDesc: json_data.update({"description":videoDesc}) if videoLoc: json_data.update({"location":videoLoc}) if videoSubject: json_data.update({"subject_id":videoSubject}) if videoViewers: parsedVideoViewers = api_tools.api_parse_csv(videoViewers) if parsedVideoViewers and len(parsedVideoViewers) > 0: json_data.update({"user_viewer_ids":parsedVideoViewers}) if videoGroups: parsedVideoGroups = api_tools.api_parse_csv(videoGroups) if parsedVideoGroups and len(parsedVideoGroups) > 0: json_data.update({"group_viewer_ids":parsedVideoGroups}) # Assemble data for human readable cURL info temp_body = { '--form':"json=%s" % json.dumps(json_data), '-F':"media=@%s" % videoPath } # Render human readable API message for output api_msg = api_tools.api_msg_render(headers, temp_body, None, url) try: response = requests.post(url, data={"json":json.dumps(json_data)}, files={"media": open(videoPath, 'rb')}, headers=headers) except: return False, None, "Error: Request exception", api_msg if response.status_code != 201: return False, None, "Response: " + str(response.status_code) + " Content: "+ str(response.text), api_msg # Successful Upload, parse JSON temp_data = response.json() output_data = { "video_title":str(temp_data['video']['title']), "video_id":str(temp_data['video']['id']), "MVID":str(MVID), "video_created_at":str(temp_data['video']['created_at']) } return True, output_data, None, api_msg