pandora_cms/backup/backup_stills.command
2020-05-29 13:10:34 +02:00

61 lines
1.6 KiB
Bash
Executable file

#!/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', 'director', 'year']
})
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']
if i.get('year'):
name += '_(%s)' % i['year']
if i.get('director'):
name += '_' + ','.join(i['director'])
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)