Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Jellyfin Manual Plugin Install
#!/usr/bin/env python
import shutil
from argparse import ArgumentParser
from io import BytesIO
from pathlib import Path
from urllib.parse import urlparse
from zipfile import ZipFile
import requests
parser = ArgumentParser()
parser.add_argument(
"-d",
"--data-directory-path",
help="Path to jellyfin data directory",
required=True,
type=Path,
)
parser.add_argument(
"-p", "--plugin-name", help="Name of plugin to install", required=True, type=str
)
parser.add_argument(
"-r",
"--repository",
default="https://repo.jellyfin.org/releases/plugin/manifest-stable.json",
help="Jellyfin plugin repository url",
type=urlparse,
)
args = parser.parse_args()
repository = {}
for plugin in requests.get(args.repository.geturl()).json():
repository[plugin["name"]] = plugin["versions"].pop(0)["sourceUrl"]
if args.plugin_name not in repository:
raise ValueError(
f"Plugin name '{args.plugin_name}' does not exist in repository {args.repository.geturl()}"
)
else:
print(
f"Plugin name '{args.plugin_name}' exists in repository {args.repository.geturl()}"
)
new_plugin_directory = args.data_directory_path.joinpath(f"plugins/{args.plugin_name}")
print(f"Deleting '{new_plugin_directory}' directory")
shutil.rmtree(new_plugin_directory, ignore_errors=True)
print(f"Creating new '{new_plugin_directory}' directory")
new_plugin_directory.mkdir(parents=True)
print(f"Downloading latest '{args.plugin_name}' plugin zip")
resp = requests.get(repository[args.plugin_name])
zipfile = ZipFile(BytesIO(resp.content))
print(f"Extracting contents of '{Path(repository[args.plugin_name]).name}' to {new_plugin_directory}")
zipfile.extractall(path=new_plugin_directory)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment