This commit is contained in:
j 2017-02-17 20:17:55 +00:00
parent e4a99312d5
commit afb4454bfc
4 changed files with 347 additions and 176 deletions

View file

@ -1,162 +1,300 @@
from collections import defaultdict from collections import defaultdict
import re import re
KEYWORDS = defaultdict(list) KEYWORDS = {
for line in ''' "A": [
1900-1947 (L) "anarchism",
aerial shot (I, M, N) "animism",
agriculture (B, I) "aporia",
air (C) "archipelago",
air conditioner (H) "ascending/descending",
anarchism (A) "assimilation",
animal (Z) "diagram",
animism (A, S) "mountain",
aporia (A) "piracy",
archipelago (A, Z) "water",
ascending/descending (A) "zomia"
assimilation (A) ],
authors/writing (G, I, L) "B": [
balinese painting (P) "agriculture",
bateson (P) "barbarian",
barbarian (B) "bondage",
becoming-animal (X) "boundary",
body in water (L, W) "buffalo",
bondage (B) "colonialism",
boundary (B) "forest",
buffalo (B, P) "peasants",
burial/grave (D) "royalty",
circle (C) "shadow puppet",
colonialism (B, L, P, Q, T) "tiger"
construction (I) ],
contagion (C, E) "C": [
corruption (C) "air",
cosmology (C, M, S) "circle",
cmp (G, L, T) "contagion",
mpc (G, L, T) "corruption",
mpaja (G, L, T) "cosmology",
decay (D) "modern leader",
deleuze/guattari (P) "money",
deleuzian diagram (P) "royalty",
diagram (A, H) "transmission"
dispersal/disaggregation (D) ],
ecology (E) "D": [
efficacy (E) "burial/grave",
emanation of power (S) "decay",
espionage (G, L, T) "dispersal", "disaggregation",
evasion (E, Z) "forensics",
family (K) "human remains",
fanaticism (S) "humidity",
fiction (F) "rain",
fire (V) "river",
first contact (X, Y) "soil"
flight (F) ],
flora/fauna (F) "E": [
fluidity (F) "evasion",
foreigner (X, Y) "epidemic",
forensics (D) "contagion",
forest (B, F, T, Z) "ecology",
friction (F) "efficacy",
frontier (F) "transmission of ideology"
geography (G) ],
ghost/spirit (G, S) "F": [
gong (R) "fiction",
guerilla (G, L) "flight",
heat (H) "flora", "fauna",
highland tribe (P) "fluidity",
human remains (D) "forest",
humidity (D, H) "friction",
hydrology (H) "frontier",
identity (I) "magic/shamans",
imitation (I) "outlaw"
india/china (O) ],
india bce (M) "G": [
indian prisoners (T) "authors/writing",
inscription (I) "cmp",
intercourse (X) "mpc",
invulnerability (I) "mpaja",
irrigation (H, I, P) "espionage",
japanese occupation (L, T) "geography",
jellyfish (J, Z) "ghost", "spirit",
kinship/kingship (K) "guerilla",
landscape (H) "transmission"
legibility (L) ],
magic/shamans (F, M, W, Y) "H": [
malacca (U) "air conditioner",
mandala (M, S) "diagram",
manpower (M) "heat",
map (M, S, T) "humidity",
metal (R) "hydrology",
mobility (M) "irrigation",
modern leader (C) "landscape",
modern nepotism (K, Z) "oppression",
money (C) "rain",
mountain (A, Z) "river",
narcotics (N) "sweat", "labor",
narration (N) "trade",
nationalism (N) "water"
network (M, S) ],
obedience (S, Y) "I": [
ocean (O, Q, U) "aerial shot",
opium (O) "agriculture",
opium war (O) "authors/writing",
oppression (H, Z) "construction",
orality (O) "identity",
origin (O, U) "imitation",
outlaw (F) "inscription",
padi (P) "invulnerability",
peasants (B, P) "irrigation",
periphery (P) "tattoo",
piracy (A) "unreadable sign"
plateau (P) ],
politics (P) "J": [
pontianak (V) "jellyfish",
pollution (J) "pollution",
queen (Q) "shape-shifter",
question (Q) "zomia"
quotation (Q) ],
rain (D, H) "K": [
ritual (R, W) "family",
river (D, H, L, P) "kinship/kingship",
royalty (B, C, K, P, Q, S, U, Z) "modern nepotism",
sea (S) "royalty"
shadow puppet (B) ],
shape-shifter (J, L, Z) "L": [
singapore (U) "1900-1947",
singapore before 1900 (T) "authors/writing",
slavery (S, T) "body in water",
society/state (S) "colonialism",
soil (D) "cmp",
soul (S) "mpc",
sumatra (U) "mpaja",
survey (M, N, T) "espionage",
sweat/labor (H) "guerilla",
swidden agriculture (P) "japanese occupation",
tamil tigers (W) "legibility",
tattoo (I) "river",
tiger (B, P, T, W) "shape-shifter",
trade (H) "unreadable sign"
transmission (C, G) ],
transmission of ideology (E) "M": [
underwater (Q) "aerial shot",
unreadable sign (I, L) "cosmology",
utama (U) "india bce",
vagina (V) "magic/shamans",
vampire (V) "mandala",
voice (V) "manpower",
water (A, H, T, W, Z) "map",
water kingdom (Q, U) "mobility",
weretiger (W, Z) "network",
women (Q) "survey"
women with white males (Q) ],
xenophilia/xenophopia (X) "N": [
yielding (Y) "aerial shot",
zomia (A, J, Z) "narcotics",
zoophilia (Z) "narration",
zombie (Z) "nationalism",
"survey"
'''.strip().split('\n'): ],
m = re.compile('(.*?) \((.*?)\)').findall(line) "O": [
term = m[0][0] "india", "china",
for id in m[0][1].split(','): "ocean",
id = id.strip() "opium",
KEYWORDS[id].append(term) "opium war",
"orality",
"origin"
],
"P": [
"balinese painting",
"bateson",
"buffalo",
"colonialism",
"deleuze/guattari",
"deleuzian diagram",
"highland tribe",
"irrigation",
"padi",
"peasants",
"periphery",
"plateau",
"politics",
"river",
"royalty",
"swidden agriculture",
"tiger"
],
"Q": [
"colonialism",
"ocean",
"queen",
"question",
"quotation",
"royalty",
"underwater",
"water kingdom",
"women",
"women with white males"
],
"R": [
"gong",
"metal",
"ritual"
],
"S": [
"animism",
"cosmology",
"emanation of power",
"fanaticism",
"ghost", "spirit",
"mandala",
"map",
"network",
"obedience",
"royalty",
"sea",
"slavery",
"society", "state",
"soul"
],
"T": [
"tiger",
"tiger",
"tiger",
"tiger",
"tiger",
"tiger",
"tiger",
"colonialism",
"cpm/mcp/mpaja",
"espionage",
"forest",
"indian prisoners",
"japanese occupation",
"map",
"singapore before 1900",
"slavery",
"survey",
"theodolite",
"water"
],
"U": [
"malacca",
"ocean",
"origin",
"royalty",
"singapore",
"sumatra",
"utama",
"water kingdom"
],
"V": [
"fire",
"pontianak",
"vagina",
"vampire",
"voice"
],
"W": [
"weretiger",
"weretiger",
"weretiger",
"water",
"water",
"body in water",
"magic/shamans",
"ritual",
"tamil tigers",
"tiger",
],
"X": [
"becoming-animal",
"first contact",
"foreigner",
"intercourse",
"xenophilia/xenophopia",
],
"Y": [
"first contact",
"foreigner",
"magic/shamans",
"obedience",
"youth",
"yielding"
],
"Z": [
"animal",
"archipelago",
"evasion",
"forest",
"jellyfish",
"modern nepotism",
"mountain",
"oppression",
"royalty",
"shape-shifter",
"water",
"weretiger",
"zomia",
"zoophilia",
"zombie"
]
}

View file

@ -1,8 +1,10 @@
#!/usr/bin/python3 #!/usr/bin/python3
import os import os
import sys
import json import json
import subprocess import subprocess
import string import string
from glob import glob
from pi import random from pi import random
from keywords import KEYWORDS from keywords import KEYWORDS
@ -44,9 +46,20 @@ def get_path(id):
'range': [0, 1] 'range': [0, 1]
})['data']['items'][0] })['data']['items'][0]
path = os.path.join('cache', '%s.%s' % (info['id'], info['extension'])) path = os.path.join('cache', '%s.%s' % (info['id'], info['extension']))
h = info['id']
source = '/srv/pandora/data/media/%s/%s/%s/%s/data.*' % (
h[:2], h[2:4], h[4:6], h[6:]
)
source = glob(source)[0]
if not os.path.exists(path): if not os.path.exists(path):
if not os.path.exists(source):
print('WTF', source)
sys.exit(1)
os.symlink(source, path)
'''
url = '%s/%s/download/source/' % (base_url, id) url = '%s/%s/download/source/' % (base_url, id)
print('get video', url) print('get video', url)
'''
PATHS[id] = path PATHS[id] = path
with open('PATHS.json', 'w') as fd: with open('PATHS.json', 'w') as fd:
json.dump(PATHS, fd, indent=4, sort_keys=True) json.dump(PATHS, fd, indent=4, sort_keys=True)
@ -77,18 +90,18 @@ def get_clips(tag):
def random_choice(seq, items): def random_choice(seq, items):
n = n_ = len(items) - 1 n = n_ = len(items) - 1
print('len', n) #print('len', n)
if n == 0: if n == 0:
return items[0] return items[0]
r = seq() r = seq()
base = 10 base = 10
while n > 10: while n > 10:
n /= 10 n /= 10
print(r) #print(r)
r += seq() r += seq()
base += 10 base += 10
r = int(n_ * r / base) r = int(n_ * r / base)
print('result', r, items) #print('result', r, items)
return items[r] return items[r]
def splitint(number, by): def splitint(number, by):
@ -114,14 +127,14 @@ def filter_clips(clips, duration, max_duration=0):
clip['tag'] = tag clip['tag'] = tag
clips_.append(clip) clips_.append(clip)
clips_.sort(key=lambda c: c['duration']) clips_.sort(key=lambda c: c['duration'])
print(clips_) #print(clips_)
size = splitint(len(clips_), 10) size = splitint(len(clips_), 10)
p = 0 p = 0
for i in range(10): for i in range(10):
buckets[i+1] = clips_[p:+p+size[i]] buckets[i+1] = clips_[p:+p+size[i]]
p += size[i] p += size[i]
clips_ = {} clips_ = {}
print(buckets[duration]) #print(buckets[duration])
for clip in buckets[duration]: for clip in buckets[duration]:
if clip['tag'] not in clips_: if clip['tag'] not in clips_:
clips_[clip['tag']] = [] clips_[clip['tag']] = []
@ -146,9 +159,13 @@ def sequence(seq, letter):
max_duration = MAX_DURATION - duration max_duration = MAX_DURATION - duration
clips_n = filter_clips(clips, n, max_duration) clips_n = filter_clips(clips, n, max_duration)
tags_n = list(sorted(clips_n.keys())) tags_n = []
for tag in tags:
if tag in clips_n:
tags_n.append(tag)
if not tags_n: if not tags_n:
print('NO tags for', letter, n) print('NO tags for', letter, n)
sys.exit(1)
tag = random_choice(seq, tags_n) tag = random_choice(seq, tags_n)
#if 'tiger' in tags_n: #if 'tiger' in tags_n:
# tag = 'tiger' # tag = 'tiger'
@ -159,6 +176,7 @@ def sequence(seq, letter):
if seq() == 0: if seq() == 0:
clip['black'] = True clip['black'] = True
position = last_text = 0 position = last_text = 0
tags_text = []
while position < duration: while position < duration:
n = seq() n = seq()
if n == 0: if n == 0:
@ -168,8 +186,12 @@ def sequence(seq, letter):
if n == 0: if n == 0:
n = 10 n = 10
n = min(n, duration-position) n = min(n, duration-position)
if not tags_text:
tags_text = list(sorted(set(tags)))
ttag = random_choice(seq, tags_text)
tags_text.remove(ttag)
text = { text = {
'text': random_choice(seq, tags_n), 'text': ttag,
'duration': n 'duration': n
} }
result['text'].append(text) result['text'].append(text)
@ -185,13 +207,23 @@ def sequence(seq, letter):
if __name__ == '__main__': if __name__ == '__main__':
for n in range(10): for n in range(10):
seq = random(n) seq = random(n * 1000)
#for letter in string.ascii_uppercase: #for letter in ('T', 'W'):
for letter in ('T', 'W'): for letter in string.ascii_uppercase:
r = sequence(seq, letter) r = sequence(seq, letter)
tjson = 'output/%s%d.json' % (letter, n) tjson = 'output/%02d/%s.json' % (n, letter)
with open(tjson, 'w') as fd: folder = os.path.dirname(tjson)
json.dump(r, fd, indent=4, sort_keys=True) if not os.path.exists(folder):
print(json.dumps(r, indent=4, sort_keys=True)) ox.makedirs(folder)
if os.path.exists(tjson):
with open(tjson, 'r') as fd:
old = fd.read()
else:
old = None
current = json.dumps(r, indent=4, sort_keys=True)
#print(current)
#print(sum([c['duration'] for c in r['clips']])) #print(sum([c['duration'] for c in r['clips']]))
if current != old:
with open(tjson, 'w') as fd:
fd.write(current)
subprocess.call(['./render_mlt.py', tjson]) subprocess.call(['./render_mlt.py', tjson])

View file

@ -67,7 +67,7 @@ for clip in data['clips']:
frames = int(clip['duration'] * fps) frames = int(clip['duration'] * fps)
add_color(video, 'black', frames) add_color(video, 'black', frames)
else: else:
print(clip['duration'], clip['path']) #print(clip['duration'], clip['path'])
if not os.path.exists(clip['path']): if not os.path.exists(clip['path']):
print(clip['path'], 'is missing') print(clip['path'], 'is missing')
sys.exit(1) sys.exit(1)
@ -75,6 +75,7 @@ for clip in data['clips']:
in_ = int(clip['in'] * fps) in_ = int(clip['in'] * fps)
frames = int(clip['duration'] * fps) frames = int(clip['duration'] * fps)
add_clip(video, clip['path'], in_, frames) add_clip(video, clip['path'], in_, frames)
for clip in data['text']: for clip in data['text']:
if clip.get('blank'): if clip.get('blank'):
frames = int(clip['duration'] * fps) frames = int(clip['duration'] * fps)
@ -86,7 +87,7 @@ for clip in data['text']:
multitrack.connect(video, 0) multitrack.connect(video, 0)
multitrack.connect(overlay, 1) multitrack.connect(overlay, 1)
composite = mlt.Transition(profile, "composite") composite = mlt.Transition(profile, "composite")
#composite.set('fill', 0) #composite.set('fill', 1)
tractor.plant_transition(composite) tractor.plant_transition(composite)

BIN
ttf/Roboto-Medium.ttf Normal file

Binary file not shown.