Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 200 lines (164 sloc) 6.27 KB
# push metadata to richard (like
# This is just a lib that makes doing REST stuff easier.
import slumber
import pprint
from django.template.defaultfilters import \
linebreaks, urlize, force_escape
from steve.util import scrapevideo
import pw
from process import process
from main.models import Show, Location, Episode
class add_to_richard(process):
ready_state = 5
def process_ep(self, ep):
if self.options.verbose: print "post_to_richard",,
### remove some day....
if ep.host_url.startswith(""):
yt_id = ep.host_url.split('/')[-1]
ep.host_url="" % (yt_id,)
# get the metadata from youtube
# like thumb url and video embed code
yt_meta = scrapevideo(ep.host_url)
if self.options.verbose:
pprint.pprint( yt_meta )
# speakers = [] if ep.authors is None else ep.authors.split(',')
speakers = ep.authors.split(',') if ep.authors else []
tags = ep.tags.split(',')
# remove blacklisted tags,
# and tags with a / in them.
# and strip spaces
tags = [t.strip() for t in tags if t not in [
and '/' not in t
and t]
host = pw.richard[self.options.host_user]
# Create an api object with the target api root url.
endpoint = 'http://%(host)s/api/v1/' % host
api = slumber.API(endpoint)
# make sure the category exists.
# This seems like a terible way to doing this,
# but I need to get something working today!!!
# I am going to regret this later.
# To the future me: Sorry.
if self.options.verbose: print "Show slug:",,
cats = api.category.get(limit=0)
found = False
for cat in cats['objects']:
if self.options.verbose: print cat['id'], cat['slug'], cat['name']
if cat['name'] ==
found = True
if self.options.verbose: print "found"
if not found:
# The category doesn't exist yet, so create it
if self.options.verbose: print "creating..."
cat_data = {
'kind': 1,
# 'name':,
# 'title':,
'description': '',
'url': '',
'whiteboard': '',
# I think start_date should be blank, or .today()
# 'start_date': '2012-07-16',
# 'slug':
# 'slug':
# cat =,
# username=host['user'], api_key=host['api_key'])
# if self.options.verbose: print "created", cat
except Exception as exc:
# TODO: OMG gross.
if exc.content.startswith('\n<!DOCTYPE html>'):
error_lines = [line for line in exc.content.splitlines()
if 'exception_value' in line]
for line in error_lines:
print line
print "exc.content:", exc.content.__repr__()
# cat is now the category we want to use
# either it was existing, or was just added.
# category_key = cat['title']
# category_key = 'PyCon DE 2012'
category_key = 'PyCon CA 2012'
description = (
slug = ep.slug.replace("_","-").lower()
# Let's populate a video object and push it.
video_data = {
'state': 1, # 1=live, 2=draft
'category': category_key,
'summary': description,
# 'slug': slug,
'source_url': ep.host_url,
'copyright_text': ep.license,
'tags': tags,
'speakers': speakers,
'recorded': ep.start.isoformat(),
'language': 'English',
#'language': 'German',
'whiteboard': u'',
'quality_notes': '',
'description': u'',
'thumbnail_url': yt_meta['thumbnail_url'],
'video_ogv_url': ep.archive_ogv_url,
'video_ogv_length': None,
'video_mp4_url': ep.archive_mp4_url,
'video_mp4_download_only': False,
'video_mp4_length': None,
'video_webm_url': u'',
'video_webm_length': None,
'video_flv_url': u'',
'video_flv_length': None,
'embed': yt_meta.get('object_embed_code',''),
if self.options.verbose: pprint.pprint(video_data)
if ep.public_url:
# update
vid_id = ep.public_url.split('/video/')[1].split('/')[0]
vid =,
username=host['user'], api_key=host['api_key'])
ret = vid
# add
vid =,
username=host['user'], api_key=host['api_key'])
self.pvo_url = "http://%s/video/%s/%s" % (
host['host'], vid['id'],vid['slug'])
if self.options.verbose: print self.pvo_url
print self.pvo_url
ep.public_url = self.pvo_url
ret = self.pvo_url
except Exception as exc:
print "exc:", exc
ret = False
import code
# TODO: OMG gross.
if exc.content.startswith('\n<!DOCTYPE html>'):
error_lines = [line for line in exc.content.splitlines()
if 'exception_value' in line]
for line in error_lines:
print line
print "exc.content:", exc.content
return ret
if __name__ == '__main__':
Jump to Line
Something went wrong with that request. Please try again.