/
add_to_richard.py
executable file
·155 lines (128 loc) · 4.78 KB
/
add_to_richard.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/usr/bin/python
# push metadata to richard (like pyvideo.org)
# This is just a lib that makes doing REST stuff easier.
import slumber
import pprint
from steve.util import scrapevideo
import json
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", ep.id, ep.name
# get the metadata from youtube
# like thumb url and video embed code
json_data = scrapevideo(ep.host_url)
yt_meta = json.loads( json_data )
# pprint.pprint( yt_meta )
host = pw.richard[self.options.host_user]
pprint.pprint(host)
# Create an api object with the target api root url.
api = slumber.API(host['url'])
# 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.
cats = api.category.get()
found = False
for cat in cats['objects']:
if cat['slug'] == ep.show.slug:
found = True
if not found:
cat_data = {
'kind': 1,
'name': ep.show.name,
'title': ep.show.name,
'description': '',
'url': 'http://conference.scipy.org/scipy2012/',
'whiteboard': '',
'start_date': '2012-07-16',
'slug': ep.show.slug
}
cat = api.category.post(cat_data,
username=host['user'],
api_key=host['api_key'])
# Let's populate a video object and push it.
video_data = {
'state': 1,
'title': ep.name,
'category': ep.show.name,
'summary': ep.description,
'slug': ep.slug,
'source_url': ep.host_url,
'copyright_text': ep.license,
'tags': ep.tags.split(','),
'speakers': ep.authors.split(','),
# 'added': '2012-06-15T20:34:32',
'recorded': ep.start.isoformat(),
'language': 'English',
'whiteboard': u'',
'quality_notes': '',
'description': u'',
'thumbnail_url': yt_meta['thumbnail_url'],
'video_ogv_url': u'',
'video_ogv_length': None,
'video_mp4_url': ep.archive_url,
'video_mp4_download_only': True,
'video_mp4_length': None,
'video_webm_url': u'',
'video_webm_length': None,
'video_flv_url': u'',
'video_flv_length': None,
'embed': yt_meta['object_embed_code'],
}
video_data = {
'category': u'Chipy_aug_2012',
'copyright_text': u'',
'description': u'',
'embed': u'<object width="640" height="390"><param name="movie" value="http://youtube.com/v/0CZgmbl47xw?version=3&hl=en_US"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://youtube.com/v/0CZgmbl47xw?version=3&hl=en_US" type="application/x-shockwave-flash" width="640" height="390" allowscriptaccess="always" allowfullscreen="true"></embed></object>',
'language': 'English',
'quality_notes': '',
'recorded': '2012-08-09T20:00:00',
'slug': u'Mono_to_IronPython',
'source_url': u'https://www.youtube.com/watch?v=0CZgmbl47xw',
'speakers': [u'Fawad Halim'],
'state': 1,
'summary': u'Introduction to Mono, what it means in relation to .NET, with a segway into IronPython.',
'tags': [],
'thumbnail_url': u'http://i1.ytimg.com/vi/0CZgmbl47xw/hqdefault.jpg',
'title': u'Mono to IronPython',
'video_flv_length': None,
'video_flv_url': u'',
'video_mp4_download_only': True,
'video_mp4_length': None,
'video_mp4_url': u'http://test.bucket.s3.us.archive.org/chipy/chipy_aug_2012/Mono_to_IronPython?Signature=%2FejIq9oN0LEH5OR6OSiRzqr8td8%3D&Expires=1344725073&AWSAccessKeyId=FEWGReWX3QbNk0h3',
'video_ogv_length': None,
'video_ogv_url': u'',
'video_webm_length': None,
'video_webm_url': u'',
'whiteboard': u''}
pprint.pprint(video_data)
# Let's create this video with an HTTP POST.
try:
print "trying..."
vid = api.video.post(video_data,
username=host['user'],
api_key=host['api_key'])
except Exception as exc:
print "caught!"
# TODO: OMG gross.
import code
code.interact(local=locals())
error_lines = [line for line in exc.content.splitlines()
if 'exception_value' in line]
if error_lines:
for line in error_lines:
print line
raise
print "Created video: ", vid
ep.public_url = vid
ep.save()
ret = True
return ret
if __name__ == '__main__':
p=add_to_richard()
p.main()