-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlookup_title.py
executable file
·54 lines (47 loc) · 1.44 KB
/
lookup_title.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
#!/usr/bin/env python
from database import Database
from formatting import Formatting
import sys
import re
from math import ceil
if len(sys.argv) < 2:
print "Usage: %s movie"
sys.exit()
else:
title = ' '.join(sys.argv[1:])
params = (title,)
query = "select * from videometadata where title = %s"
fmt = Formatting()
db = Database()
results = db.rows_to_dicts(query, params)
if len(results) != 1:
print "Couldn't find movie!"
sys.exit()
else:
metadata = results[0]
for key in ['genre', 'cast']:
query = ("select video" + key + "." + key + " from video" + key +
" inner join videometadata" + key +
" on video" + key + ".intid = videometadata" + key + ".id" + key +
" where videometadata" + key + ".idvideo = %s")
params = (metadata['intid'],)
metadata[key] = ', '.join([i[0].decode('latin-1', 'replace') for i in db.run_query(query, params)])
keys = metadata.keys()
for key in ['collectionref',
'homepage',
'showlevel',
'hash',
'childid',
'browse',
'watched',
'processed',
'playcommand',
'category',
'trailer',
'host',
'screenshot',
'banner']:
keys.remove(key)
for key in keys:
tabs = '\t' * (3 - int(ceil(len(key) / 6.0)))
print "%s%s%s:%s%s%s%s" % (fmt.header, key, fmt.reset, tabs, fmt.text, metadata[key], fmt.reset)