backup annotations too

This commit is contained in:
j 2018-05-10 14:58:00 +01:00
parent 9f56cff77b
commit b3d7768839
2 changed files with 44 additions and 1 deletions

40
backup_annotations.py Executable file
View file

@ -0,0 +1,40 @@
#!/usr/bin/env python3
import json
import os
import sys
import unicodedata
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__)), 'Films')
if not target.endswith('/'):
target += '/'
site = 'pandora.cinemusespace.com'
api = ox.api.signin('https://%s/api/' % site)
keep = []
r = api.find({'range': [0, 1000], 'keys': ['id']})
for i in r['data']['items']:
item = api.get(id=i['id'], keys=[])['data']
layers = api.get(id=i['id'], keys=['layers'])['data']
item['layers'] = layers['layers']
director = item.get('director', ['Unknown Director'])
path = os.path.join('; '.join(director), '%s' % (item['title']))
if 'year' in item:
path += ' (%s)' % item['year']
path = ox.decode_html(path)
path = os.path.join(target, path)
ox.makedirs(path)
path = os.path.join(path, 'annotations.json')
with open(path, 'w') as fd:
json.dump(item, fd, ensure_ascii=False, indent=4, sort_keys=True)

View file

@ -37,6 +37,9 @@ if __name__ == '__main__':
path += ' (%s)' % item['year']
path = ox.decode_html(path)
prefix = ox.decode_html(item['title'])
keep.append(unicodedata.normalize('NFD', os.path.join(target, path, 'annotations.json')))
parts = []
if len(item['streams']) == 1:
id = item['streams'][0]
@ -60,7 +63,7 @@ if __name__ == '__main__':
os.unlink(abspath)
if not os.path.exists(abspath):
url = 'https://%s/%s/download/source/%s' % (site, id, part)
print('downloading', abspath[len(target) + 1:])
print('downloading', abspath[len(target):])
api.save_url(url, abspath)
keep.append(unicodedata.normalize('NFD', abspath))