#!/usr/bin/python3 from datetime import datetime, timedelta from urllib.parse import quote import hashlib import json import os import subprocess import sys import unicodedata import ox import ox.api sort_edits = {} def normalize(id): name = id.split(":")[0] id = id.replace(':', '_').replace('/', '_') prefix = hashlib.sha1(('firends' + name).encode()).hexdigest()[:8] return '%s_%s' % (prefix, id) if __name__ == '__main__': site = sys.argv[1] users = sys.argv[2:] api = ox.api.signin('https://%s/api/' % site) public_names = [] r = api.findEdits({ 'query': { 'conditions': [{'key': 'status', 'operator': '!==', 'value': 'private'}] }, 'range': [0, 1000], 'keys': ['id', 'status', 'modified', 'type'] }) for edit in r['data']['items']: id = edit['id'] if users and id.split(':')[0] not in users: continue for sort in sort_edits.get(id, ['index']): if edit['type'] == 'smart' and sort == 'index': sort = 'year' edit_name = 'edits/%s_%s.json' % (normalize(id), sort) modified = int(datetime.strptime(edit['modified'], '%Y-%m-%dT%H:%M:%SZ').timestamp()) if not os.path.exists(edit_name) or os.path.getmtime(edit_name) < modified: print('update', id, sort) url = 'https://%s/edits/%s/list/%s' % (site, quote(id.replace('_', '\t')), sort) print(url) cmd = ['../edit.py', url, '-r', '720', '-s', 'local', '-o', edit_name] subprocess.call(cmd) cmd = ['../ffmpeg.py', '-r', '720', edit_name] subprocess.call(cmd) srt = edit_name.replace('.json', '.srt') vtt = edit_name.replace('.json', '.vtt') cmd = [ 'ffmpeg', '-hide_banner', '-nostats', '-loglevel', 'error', '-y', '-i', srt, vtt ] subprocess.call(cmd) public_names.append(edit_name.replace('.json', '')) #print('\n'.join(public_names)) #print('--') for f in os.listdir('edits'): if f.endswith('.html'): continue f = 'edits/' + f if '.' in f: name, ext = f.rsplit('.', 1) if ext not in ('json', 'mp4', 'srt', 'vtt'): print('skip', ext, f) continue if name not in public_names: print('remove', f, name, ext) os.unlink(f) mp4s = [f for f in os.listdir('edits') if f.endswith('.mp4')] html = {} for mp4 in sorted(mp4s): prefix = mp4.split('_')[0] if prefix not in html: html[prefix] = [ '''