-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcatalog.py
77 lines (61 loc) · 2.11 KB
/
catalog.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
from os import listdir
from os.path import isdir
from itertools import cycle
from glob import glob
from random import shuffle
import sys
#force unicode for jinja
reload(sys)
sys.setdefaultencoding('utf-8')
#maps of locations to arrays of content
pic_catalog = {}
vid_catalog = {}
#maps of locations to iterable content
pic_catalog_iter = {}
vid_catalog_iter = {}
def build_content_catalog():
global catalog_build_time
global pic_catalog
global vid_catalog
global pic_catalog_iter
global vid_catalog_iter
print "\n*** BUILDING CONTENT CATALOG ***"
#list contents of media dir
for content_dir in listdir('./media/'):
if isdir('./media/' + content_dir): #if item is a directory
print content_dir, ' - SETTING UP LOCATION'
pics = []
vids = []
#gets common media
if content_dir != 'test':
print content_dir, ' - adding common media'
pics += glob('./media/common/pics/*.[Jj][Pp]*[Gg]') #grab jpegs
pics += glob('./media/common/pics/*.[Pp][Nn][Gg]') #grab + add pngs
vids += glob('./media/common/vids/*.[Mm][Pp]4') #grabs mp4s
vids += glob('./media/common/vids/*.[Ww][Ee][Bb][Mm]') #grab webms
#gets location media
if content_dir != 'common':
print content_dir, ' - adding location media'
pics += glob('./media/' + content_dir + '/pics/*.[Jj][Pp]*[Gg]') #grab jpegs
pics += glob('./media/' + content_dir + '/pics/*.[Pp][Nn][Gg]') #grab + add pngs
vids += glob('./media/' + content_dir + '/vids/*.[Mm][Pp]4') #grabs mp4s
vids += glob('./media/' + content_dir + '/vids/*.[Ww][Ee][Bb][Mm]') #grab webms
#shuffle lists
shuffle(pics)
shuffle(vids)
pic_catalog[content_dir] = pics
vid_catalog[content_dir] = vids
pic_catalog_iter[content_dir] = cycle(pics)
vid_catalog_iter[content_dir] = cycle(vids)
def get_pics(num,loc):
print 'getting', num, 'pics for', loc
selected_pics = []
for i in range (0, num):
selected_pics.append(pic_catalog_iter[loc].next())
return selected_pics
def get_vids(num,loc):
print 'getting', num, 'vids for', loc
selected_vids = []
for i in range (0, num):
selected_vids.append(vid_catalog_iter[loc].next())
return selected_vids