Name is required.
Email address is required.
Invalid email address
Answer is required.
Exceeding max length of 5KB

Batch Upload (python) Delete All Videos or Replace Filenames


Hi,
I am currently testing the JW Platform and weighing out the pros/cons of self hosted vs cloud. I have successfully accomplished batch uploading our videos to the content section of the account but would like to know if it is possible to remove all pre-exisiting videos prior to this process.

Is there a way to issue a "delete all videos" command via python before initiating the batch upload OR if we were to use a standardized filename/tag structure (eg: video1, video2, video3) could these be overwritten ?

6 Community Answers

Todd

JW Player Support Agent  
0 rated :

We do not have a single API call to delete all videos, but my recommendation would be to do a /videos/list call and the loop those results through /videos/delete. Please see our JW Platform API documentation at https://developer.jwplayer.com/jw-platform/reference/v1/methods/videos/list.html and https://developer.jwplayer.com/jw-platform/reference/v1/methods/videos/delete.html for more details.

As for overwriting filenames, this would not work because we assign unique media IDs to each video. Two videos can have the same name without overwriting each other.

x...

User  
0 rated :

Thank you for the response. I have been through the documentation thoroughly and have successfully been able to get the list using:
response = api.call('/videos/list')
pp.pprint(response)

/videos/delete.html documentation was rather vague on the actual process and I could not find another resource for further information. Could you direct me to a code sample needed for this "/videos/delete" loop or even just something that simply demonstrates how to pull just the "video key" from the returned response.

Thanks again!

Todd

JW Player Support Agent  
0 rated :

The Python script for /videos/delete looks like this:

# -*- coding: utf-8 -*-
import os
import hashlib
import pprint

from botr.api import API

pp = pprint.PrettyPrinter()

# Please update kkkk with your key and ssss with your secret
api = API('your_API_key', 'your_API_secret')

call_params = {
    'video_key': 'your_video_ID',
}

response = api.call('/videos/delete', call_params, verbose=True)
pp.pprint(response)

xlinkx

User  
0 rated :

Apologize for the misunderstanding. These part of the documentation I understand. Utilizing /videos/list and /videos/delete individually are straight forward...putting them together is where the root of my question and struggles are. According to documentation it seems to state that you can pass a comma separated string of video_key's into the /video/delete call_params.

Sorry to be a bother...but as a final attempt for clarity...I was hoping for identify on how to loop through and collect every current video_key using /video/list...then issuing either a single /video/delete call with these keys as comma separated values OR if preferred a call /videos/delete for each item individually.

xlinkx

User  
0 rated :

FOR THOSE INTERESTED, HERE IS THE CODE I ENDED UP HAVING TO USE: I'm certain there is a much cleaner approach but not being able to collect addition information on the API...manually digging down through response was only method I could come up with. If anyone has a direct/simplified approach PLEASE PLEASE SHARE :)

------------------------------

import pprint
from botr_py import API

pp = pprint.PrettyPrinter()

# IMPORTANT :: Update kkkk with your key and ssss with your secret
api = API('kkkk', 'ssss')

#FUNCTION FOR PARSING /VIDEOS/LIST RESPONSE
def find(key, dictionary):
for k, v in dictionary.iteritems():
if k == key:
yield v
elif isinstance(v, dict):
for result in find(key, v):
yield result
elif isinstance(v, list):
for d in v:
for result in find(key, d):
yield result

#GET VIDEO LIST / KEYS INTO A SINGLE STRING
response = api.call('/videos/list')
keylist = list(find('key', response))
video_keys = ",".join([str(item) for item in keylist])

#PLACE STRING INTO /VIDEOS/DELETE PARAMS
call_params = {
'video_key': video_keys,
}

#DELETE ALL
response = api.call('/videos/delete', call_params, verbose=True)
pp.pprint(response)

Todd

JW Player Support Agent  
0 rated :

I am certainly not an expert when it comes to Python, but I tested this and it worked. PLEASE BE CAREFUL AS THIS WILL DELETE ALL THE VIDEOS IN YOUR ACCOUNT!

import os
import hashlib
import pprint
import json
from botr.api import API

pp = pprint.PrettyPrinter()

api = API('my_key', 'my_secret')

call_params = {
	'api_format': 'json',
	'result_limit':'999',
	'order_by':'date:desc'
}

response = api.call('/videos/list', call_params, verbose=True)
json = json.loads(response)

for video in json['videos']:
	print "Deleting video ID: "+str(video['key'])
	call_params = {
		'video_key': video['key'],
	}
	response = api.call('/videos/delete', call_params, verbose=True)
	pp.pprint(response)

This question has received the maximum number of answers.