pandora_cms/backup/backup_stills.command

62 lines
1.6 KiB
Text
Raw Permalink Normal View History

2020-05-29 11:05:02 +00:00
#!/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],
2020-05-29 11:10:34 +00:00
'keys': ['id', 'item', 'value', 'in', 'out', 'title', 'director', 'year']
2020-05-29 11:05:02 +00:00
})
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 = []
2020-05-29 11:10:34 +00:00
name = i['title']
if i.get('year'):
name += '_(%s)' % i['year']
if i.get('director'):
name += '_' + ','.join(i['director'])
2020-05-29 11:05:02 +00:00
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)