backup stills

This commit is contained in:
j 2020-05-29 13:05:02 +02:00
parent 2ed1bbaa6f
commit 4f581e8d62
1 changed files with 57 additions and 0 deletions

57
backup/backup_stills.command Executable file
View File

@ -0,0 +1,57 @@
#!/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)