58 lines
1.4 KiB
Text
58 lines
1.4 KiB
Text
|
#!/usr/bin/env python3
|
||
|
|
||
|
import json
|
||
|
import os
|
||
|
import sys
|
||
|
import unicodedata
|
||
|
import re
|
||
|
|
||
|
import ox
|
||
|
import ox.api
|
||
|
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
if len(sys.argv) > 1:
|
||
|
target = sys.argv[1]
|
||
|
else:
|
||
|
target = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'Stills')
|
||
|
|
||
|
if not target.endswith('/'):
|
||
|
target += '/'
|
||
|
|
||
|
site = 'pandora.cinemusespace.com'
|
||
|
api = ox.api.signin('https://%s/api/' % site)
|
||
|
|
||
|
keep = []
|
||
|
r = api.findAnnotations({
|
||
|
'query': {
|
||
|
'conditions': [
|
||
|
{'key': 'layer', 'operator': '==', 'value': 'stills'}
|
||
|
]
|
||
|
},
|
||
|
'range': [0, 100000],
|
||
|
'keys': ['id', 'item', 'value', 'in', 'out', 'title']
|
||
|
})
|
||
|
for i in r['data']['items']:
|
||
|
img = re.compile('<img src="(.*)">').findall(i['value'])
|
||
|
if len(img) != 1:
|
||
|
print(img)
|
||
|
sys.exit(1)
|
||
|
lines = i['value'].strip().split('\n')
|
||
|
if len(lines) > 1:
|
||
|
tags = lines[1:]
|
||
|
else:
|
||
|
tags = []
|
||
|
|
||
|
name = i['title'].replace(' ', '_')
|
||
|
if tags:
|
||
|
name += '_' + ','.join(tags)
|
||
|
|
||
|
pos = float(re.compile('p(.*?).jpg').findall(img[0])[0])
|
||
|
name += '_%s.jpg' % ox.format_timecode(pos)
|
||
|
url = 'https://%s%s' % (site, img[0])
|
||
|
path = os.path.join(target, name)
|
||
|
if not os.path.exists(path):
|
||
|
print(url, name)
|
||
|
api.save_url(url, path)
|
||
|
|