"""Run in CT100191 after staging DLL at /tmp/Jellyfin.Plugin.Enigma2.dll.""" import datetime,json,pathlib,shutil,sqlite3,subprocess,urllib.request db=sqlite3.connect('file:/var/lib/jellyfin/data/jellyfin.db?mode=ro',uri=True) token=db.execute('SELECT AccessToken FROM ApiKeys ORDER BY Id LIMIT 1').fetchone()[0];db.close() headers={'Authorization':'MediaBrowser Token="'+token+'", Client="DecoderIntegration", Device="Maintenance", DeviceId="decoder-maintenance", Version="7"'} def get(path): return json.load(urllib.request.urlopen(urllib.request.Request('http://127.0.0.1:8096'+path,headers=headers),timeout=30)) if get('/System/Info/Public')['Version']!='12.2.0':raise SystemExit('This build requires Jellyfin 12.2.0') if any(s.get('NowPlayingItem') for s in get('/Sessions')):raise SystemExit('Active playback: restart deferred') plugins=pathlib.Path('/var/lib/jellyfin/plugins') backup=pathlib.Path('/var/lib/jellyfin/decoder-plugin-backups')/datetime.datetime.now(datetime.timezone.utc).strftime('%Y%m%dT%H%M%SZ') backup.mkdir(parents=True,mode=0o700) config=plugins/'configurations/Jellyfin.Plugin.Enigma2.xml' if config.exists():shutil.copy2(config,backup/config.name) web_config=pathlib.Path('/usr/share/jellyfin/web/config.json') shutil.copy2(web_config,backup/'web-config.json') old=[p for p in plugins.glob('Enigma2_*') if p.is_dir()] new=plugins/'Enigma2_7.0.0.0' subprocess.run(['systemctl','stop','jellyfin'],check=True) try: for folder in old:shutil.move(str(folder),str(backup/folder.name)) new.mkdir();shutil.copy2('/tmp/Jellyfin.Plugin.Enigma2.dll',new/'Jellyfin.Plugin.Enigma2.dll') metadata={'category':'Live TV','description':'Enigma2 with internet EPG artwork and per-user channel preferences','guid':'193f29f9-ea6c-4595-a6f6-55e79d7c590a','name':'Enigma2','overview':'Enigma2 decoder integration','owner':'local','status':'Active','targetAbi':'12.2.0.0','version':'7.0.0.0'} (new/'meta.json').write_text(json.dumps(metadata)) subprocess.run(['chown','-R','jellyfin:jellyfin',str(new)],check=True) settings=json.loads(web_config.read_text());links=settings.setdefault('menuLinks',[]) if not any(x.get('name')=='Telewizja dekodera' for x in links):links.append({'name':'Telewizja dekodera','icon':'tv','url':'../DecoderIntegration/Channels'}) web_config.write_text(json.dumps(settings,indent=2)+'\n') except Exception: shutil.copy2(backup/'web-config.json',web_config) if new.exists():shutil.rmtree(new) for folder in old: if (backup/folder.name).exists():shutil.move(str(backup/folder.name),str(folder)) raise finally:subprocess.run(['systemctl','start','jellyfin'],check=True) print(json.dumps({'installed':'7.0.0.0','backup':str(backup)}))