"""Run in CT100191 after staging decoder-channel-playback.js in /tmp. No restart needed.""" import datetime import json import pathlib import shutil web = pathlib.Path('/usr/share/jellyfin/web') backup = pathlib.Path('/var/lib/jellyfin/decoder-plugin-backups') / ('web-playback-' + datetime.datetime.now(datetime.timezone.utc).strftime('%Y%m%dT%H%M%SZ')) backup.mkdir(mode=0o700) for name in ['index.html', 'config.json']: shutil.copy2(web / name, backup / name) script = web / 'decoder-channel-playback.js' if script.exists(): shutil.copy2(script, backup / script.name) shutil.copy2('/tmp/decoder-channel-playback.js', script) html = (web / 'index.html').read_text() tag = '' if tag not in html: html = html.replace('', '' + tag, 1) assert tag in html (web / 'index.html').write_text(html) config = json.loads((web / 'config.json').read_text()) plugins = config.setdefault('plugins', []) if 'DecoderChannelPlayback' not in plugins: plugins.append('DecoderChannelPlayback') (web / 'config.json').write_text(json.dumps(config, indent=2) + '\n') print(json.dumps({'web_playback_installed': True, 'backup': str(backup)}))