diff --git a/backup_annotations.py b/backup_annotations.py new file mode 100755 index 0000000..fd316e2 --- /dev/null +++ b/backup_annotations.py @@ -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) + diff --git a/backup_films.py b/backup_films.py index d030992..11420be 100755 --- a/backup_films.py +++ b/backup_films.py @@ -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))