case
This commit is contained in:
parent
a09fcaaa86
commit
19d4367ec7
2 changed files with 15 additions and 6 deletions
|
@ -30,7 +30,7 @@ if __name__ == '__main__':
|
|||
edit = api.getEdit(id=i['id'])['data']
|
||||
if edit['status'] == 'private':
|
||||
continue
|
||||
path = i['id'].replace(':', '_').replace('/', '_') + '.json'
|
||||
path = i['id'].replace(':', '\uf022').replace('/', '_').replace('|', '_') + '.json'
|
||||
path = ox.decode_html(path)
|
||||
path = os.path.join(target, path)
|
||||
ox.makedirs(os.path.dirname(path))
|
||||
|
|
|
@ -12,9 +12,12 @@ def get_extension(api, oshash):
|
|||
r = api.findMedia({'query': {
|
||||
'conditions': [{'key': 'oshash', 'value': oshash}]
|
||||
}, 'keys': ['extension']})['data']
|
||||
return r['items'][0]['extension']
|
||||
return r['items'][0]['extension'].lower()
|
||||
|
||||
|
||||
COLON = '\uf022'
|
||||
COLON = ':'
|
||||
|
||||
if __name__ == '__main__':
|
||||
if len(sys.argv) > 1:
|
||||
target = sys.argv[1]
|
||||
|
@ -28,7 +31,7 @@ if __name__ == '__main__':
|
|||
api = ox.api.signin('https://%s/api/' % site)
|
||||
|
||||
keep = []
|
||||
r = api.find({'range': [0, 1000], 'keys': ['id']})
|
||||
r = api.find({'range': [0, 10000], 'keys': ['id']})
|
||||
for i in r['data']['items']:
|
||||
item = api.get(id=i['id'], keys=['id', 'streams', 'title', 'director', 'year', 'instances'])['data']
|
||||
director = item.get('director', ['Unknown Director'])
|
||||
|
@ -38,7 +41,10 @@ if __name__ == '__main__':
|
|||
path = ox.decode_html(path)
|
||||
prefix = ox.decode_html(item['title'])
|
||||
|
||||
keep.append(unicodedata.normalize('NFD', os.path.join(target, path, 'annotations.json')))
|
||||
path = path.replace(':', COLON)
|
||||
prefix = prefix.replace(':', COLON)
|
||||
|
||||
keep.append(unicodedata.normalize('NFD', os.path.join(target, path, 'annotations.json')).lower())
|
||||
|
||||
parts = []
|
||||
if len(item['streams']) == 1:
|
||||
|
@ -46,6 +52,7 @@ if __name__ == '__main__':
|
|||
ext = get_extension(api, id)
|
||||
name = '%s.%s' % (item['title'], ext)
|
||||
name = ox.decode_html(name)
|
||||
name = name.replace(':', COLON)
|
||||
part = 1
|
||||
parts.append([os.path.join(path, name), item['id'], id, part])
|
||||
else:
|
||||
|
@ -54,12 +61,14 @@ if __name__ == '__main__':
|
|||
ext = get_extension(api, id)
|
||||
name = '%s.Part %d.%s' % (prefix, part, ext)
|
||||
name = ox.decode_html(name)
|
||||
name = name.replace(':', COLON)
|
||||
parts.append([os.path.join(path, name), item['id'], id, part])
|
||||
part += 1
|
||||
|
||||
for path, id, oshash, part in parts:
|
||||
abspath = os.path.join(target, path)
|
||||
if os.path.exists(abspath) and ox.oshash(abspath) != oshash:
|
||||
print('file changed', abspath[len(target):])
|
||||
os.unlink(abspath)
|
||||
if not os.path.exists(abspath):
|
||||
url = 'https://%s/%s/download/source/%s' % (site, id, part)
|
||||
|
@ -68,11 +77,11 @@ if __name__ == '__main__':
|
|||
api.save_url(url, abspath)
|
||||
except:
|
||||
print('failed to download', url)
|
||||
keep.append(unicodedata.normalize('NFD', abspath))
|
||||
keep.append(unicodedata.normalize('NFD', abspath).lower())
|
||||
|
||||
for root, folders, files in os.walk(target):
|
||||
for f in files:
|
||||
path = os.path.join(root, f)
|
||||
if unicodedata.normalize('NFD', path) not in keep:
|
||||
if unicodedata.normalize('NFD', path).lower() not in keep:
|
||||
print('deleting', path)
|
||||
os.unlink(path)
|
||||
|
|
Loading…
Reference in a new issue