Created
June 24, 2014 06:06
-
-
Save sinkers/5fae09f089f746c9fcaf to your computer and use it in GitHub Desktop.
Creating XML for Brightcove Once
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from lxml import etree | |
import brightcove | |
''' | |
This script extracts data from a given brightcove account and formats a request suitable for ingest into Brightcove ONCE | |
Sample format: | |
<items> | |
<!-- | |
fetched from https://api.brightcove.com/services/library?command=search_videos&all=the%20battles&none=blind&all=series:the%20voice&video_fields=lastModifiedDate,name,referenceid,renditions,id,cuepoints&media_delivery=http&sort_by=MODIFIED_DATE:DSC&token=& | |
--> | |
<item> | |
<name>Ep 12: The Battles</name> | |
<videoId>3588568300001</videoId> | |
<referenceId>BpanUxbjofkMEroeNfkKZv0KSf09hoPU</referenceId> | |
<lastModified>1401779132729</lastModified> | |
<url> | |
http://progressive.download.com.au/hds/1622448031001/201405/758/1622448031001_3588752319001_329b1114-18de-97cf-51af-b4332cf83fec.mp4 | |
</url> | |
<cuepoints> | |
<cuepoint>0</cuepoint> | |
<cuepoint>805</cuepoint> | |
<cuepoint>1299</cuepoint> | |
<cuepoint>1787</cuepoint> | |
<cuepoint>2530</cuepoint> | |
<cuepoint>3026</cuepoint> | |
<cuepoint>3512</cuepoint> | |
<cuepoint>3875</cuepoint> | |
<cuepoint>4187</cuepoint> | |
</cuepoints> | |
</item> | |
</items> | |
''' | |
BC_API_KEY = "" | |
#Setup XML document | |
def create_once_xml(): | |
root = etree.Element("items") | |
assets = brightcove.get_latest(BC_API_KEY, count=10) | |
for item in assets["items"]: | |
if not item["sharedByExternalAcct"]: | |
this_item = etree.SubElement(root, "item") | |
url = etree.SubElement(this_item, "url") | |
url.text = item["videoFullLength"]["url"] | |
name = etree.SubElement(this_item, "name") | |
name.text = item["name"] | |
referenceId = etree.SubElement(this_item, "referenceId") | |
referenceId.text = item["referenceId"] | |
lastModifiedDate = etree.SubElement(this_item, "lastModifiedDate") | |
lastModifiedDate.text = item["lastModifiedDate"] | |
#print item["renditions"] | |
cuepoints = [] | |
for cuepoint in item["cuePoints"]: | |
cuepoints.append(int(cuepoint["time"])) | |
cuepoints = sorted(cuepoints) | |
cuepoints_xml = etree.SubElement(this_item, "cuepoints") | |
for cuepoint in cuepoints: | |
cuepoint_xml = etree.SubElement(cuepoints_xml, "cuepoint") | |
cuepoint_xml.text = str(cuepoint) | |
return etree.tostring(root) | |
def write_once_xml(): | |
f = open("once.xml","w") | |
f.write() | |
f.close() | |
xml = create_once_xml() | |
write_once_xml(xml) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment