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
|
#!/usr/bin/python
import sys,os,errno
import csv
import string
import urllib
from string import Template
#BASE_URL="http://foursquaregrow.s3-website-us-east-1.amazonaws.com/"
BASE_URL="http://d12xq7pqelpwt.cloudfront.net/"
"""
Create the json file for a particular video. The fields are:
chapter: The chapter (i.e. Seeker, Believer, etc)
videoNumber: The number of the video in the chapter, starting with 1
number: The video number to display to the user. 0 to hide number.
title: The video title.
length: The video length in seconds.
image: The url of the image to display.
pdf: The url of the outline pdf.
videos: A dictionary of mime type to video urls
"""
def mkjson(chapter, videoNumber, number, title, length, image, pdf, videos):
vtemplate = Template("""{
"id": "$id",
"number": "$number",
"title": "$title",
"length": $length,
"image": "$image",
"pdf": "$pdf",
"urls": [""")
# NB we seek backwards to trim the comma after the loop
urltemplate = Template("""{"src":"$src", "type":"$type"},\n""")
directory = string.lower("videos/" + chapter)
try:
os.makedirs(directory)
except OSError as exc:
if exc.errno == errno.EEXIST and os.path.isdir(directory):
pass
else:
raise
filename = string.lower(directory + "/" + chapter + "-" + str(videoNumber) + ".json")
with open(filename, 'w') as outfile:
outfile.write(vtemplate.substitute(dict(id=string.lower(chapter+"-"+str(videoNumber)),
chapter=chapter, number=number, title=title, length=length,
image=BASE_URL + urllib.quote(image), pdf=BASE_URL + urllib.quote(pdf))))
for type,src in videos.iteritems():
outfile.write(urltemplate.substitute(dict(type=type, src=BASE_URL + urllib.quote(src))))
outfile.seek(-2, 2)
outfile.write("]\n}")
# This script reads lines from the given csv file and creates json files for
# each video in the videos/ directory.
filename = sys.argv[1];
with open(filename, 'rb') as csvfile:
videoNumbers = dict()
reader = csv.reader(csvfile)
for row in reader:
chapter = row[0]
number = row[1]
title = row[2]
length = row[3]
image = row[4]
pdf = row[5]
h264 = row[6]
webm = row[7]
# Number the videos in the chapter starting with 1
videoNumber = 1
if chapter in videoNumbers:
videoNumber = videoNumbers[chapter]
# Update the number for the next video
videoNumbers[chapter] = videoNumber + 1
videos = { "video/mp4": h264, "video/webm": webm }
mkjson(chapter, videoNumber, number, title, length, image, pdf, videos)
|