Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 76 lines (65 sloc) 2.104 kb
c1d0e9f [ITDEVOPS-601] Integrating video-thumbnail script from @onufryk.
Arthur Evans authored
1 #!/usr/bin/env python
2 #
3 # Copyright (c) 2012 Appcelerator, Inc. All Rights Reserved.
4 # Licensed under the Apache Public License (version 2)
5
6 import json
7 import pycurl
8 import StringIO
9 from optparse import OptionParser
10
11 parser = OptionParser()
12 parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False, help="verbose output")
13 parser.add_option("-i", "--input", dest="input_file", default='videos.json', help="Input file")
14 parser.add_option("-o", "--output", dest="output_file", default='video_thumbs.json', help="Output file")
15
16 (options, args) = parser.parse_args()
17
18 try:
19 video_list_file = open(options.input_file, 'r')
20 except:
21 print ('Failed to open input file: %s' % options.input_file)
657ee8a TIDOC-849 Fail fast if video thumbnail script fails.
Arthur Evans authored
22 exit(1)
c1d0e9f [ITDEVOPS-601] Integrating video-thumbnail script from @onufryk.
Arthur Evans authored
23
24 try:
25 result_file = open(options.output_file, 'w')
26 except:
27 print ('Failed to open output file: %s' % options.output_file)
657ee8a TIDOC-849 Fail fast if video thumbnail script fails.
Arthur Evans authored
28 exit(1)
c1d0e9f [ITDEVOPS-601] Integrating video-thumbnail script from @onufryk.
Arthur Evans authored
29
30 try:
31 video_list_json = video_list_file.read()
32 except:
33 print ('Failed to read source file')
657ee8a TIDOC-849 Fail fast if video thumbnail script fails.
Arthur Evans authored
34 exit(1)
c1d0e9f [ITDEVOPS-601] Integrating video-thumbnail script from @onufryk.
Arthur Evans authored
35 finally:
36 video_list_file.close()
37
38 video_list = json.loads(video_list_json)
39
40 for ii in range(len(video_list)):
41 chapter = video_list[ii]
42 if (options.verbose):
43 print ('Processing chapter ' + chapter['title'] + '...')
44
45 for jj in range(len(chapter['items'])):
46 video = chapter['items'][jj]
47 if (options.verbose):
48 print ('\tFetching '+video['title'] + '...'),
49 url = str("http://vimeo.com/api/v2/video/" + video['id'] + ".json")
50 try:
51 request = pycurl.Curl()
52 request.setopt(pycurl.URL, str(url))
53 response = StringIO.StringIO()
54 request.setopt(pycurl.WRITEFUNCTION, response.write)
55 request.perform()
56 video_info = json.loads(response.getvalue())
57 if (options.verbose):
58 print (video_info[0]['thumbnail_small']),
59 video_list[ii]['items'][jj]['thumb'] = video_info[0]['thumbnail_small']
60 if (options.verbose):
61 print ('OK')
62 except pycurl.error as e:
63 if (options.verbose):
64 print (e[1])
657ee8a TIDOC-849 Fail fast if video thumbnail script fails.
Arthur Evans authored
65 exit(1)
c1d0e9f [ITDEVOPS-601] Integrating video-thumbnail script from @onufryk.
Arthur Evans authored
66 finally:
67 request.close()
68
69 try:
70 result_file.write(json.dumps(video_list, indent=2))
71 except:
72 print ('Failed to write results to %s' % options.output_file)
657ee8a TIDOC-849 Fail fast if video thumbnail script fails.
Arthur Evans authored
73 exit(1)
c1d0e9f [ITDEVOPS-601] Integrating video-thumbnail script from @onufryk.
Arthur Evans authored
74 finally:
75 result_file.close()
Something went wrong with that request. Please try again.