@@ -440,33 +440,85 @@ if [[ "$MEDIA_SERVER" == "jellyfin" ]]; then
440440 # Fetch plugin catalog
441441 PLUGIN_CATALOG=$( curl -fsS " http://localhost:8096/Packages" -H " X-Emby-Token: $JF_API_KEY " 2> /dev/null || true)
442442
443+ url_encode () {
444+ local raw=" $1 "
445+ if command -v python3 > /dev/null 2>&1 ; then
446+ python3 - " $raw " << 'PY '
447+ import sys, urllib.parse
448+ print(urllib.parse.quote(sys.argv[1], safe=""))
449+ PY
450+ else
451+ # Best-effort fallback for environments without python3
452+ printf ' %s\n' " ${raw// /% 20} "
453+ fi
454+ }
455+
456+ resolve_jf_plugin () {
457+ local requested=" $1 "
458+ if ! command -v python3 > /dev/null 2>&1 ; then
459+ return 1
460+ fi
461+
462+ printf ' %s' " $PLUGIN_CATALOG " | python3 - " $requested " << 'PY '
463+ import json, sys
464+
465+ wanted = sys.argv[1].strip().lower()
466+ try:
467+ payload = json.load(sys.stdin)
468+ except Exception:
469+ sys.exit(1)
470+
471+ items = payload.get("Items", payload) if isinstance(payload, dict) else payload
472+ if not isinstance(items, list):
473+ sys.exit(1)
474+
475+ for item in items:
476+ if not isinstance(item, dict):
477+ continue
478+ name = str(item.get("name", item.get("Name", ""))).strip()
479+ guid = str(item.get("guid", item.get("Guid", ""))).strip()
480+ if name.lower() == wanted:
481+ print(name)
482+ print(guid)
483+ sys.exit(0)
484+
485+ sys.exit(1)
486+ PY
487+ }
488+
443489 install_jf_plugin () {
444490 local plugin_name=" $1 "
445491 if [[ -z " $PLUGIN_CATALOG " ]]; then
446492 warn " $plugin_name : could not fetch plugin catalog"
447493 return 0
448494 fi
449495
450- # Extract the plugin GUID from catalog
451- local plugin_guid
452- plugin_guid=$( echo " $PLUGIN_CATALOG " | grep -o " \" name\" :\" $plugin_name \" [^}]*\" guid\" :\" [^\" ]*\" " | grep -o ' "guid":"[^"]*"' | cut -d' "' -f4 || true)
496+ local plugin_info plugin_guid resolved_name
497+ plugin_info=" $( resolve_jf_plugin " $plugin_name " || true) "
498+ resolved_name=" $( echo " $plugin_info " | sed -n ' 1p' ) "
499+ plugin_guid=" $( echo " $plugin_info " | sed -n ' 2p' ) "
453500
454- if [[ -z " $plugin_guid " ]]; then
501+ if [[ -z " $resolved_name " ]]; then
455502 warn " $plugin_name : not found in plugin catalog"
456503 warn " Install manually: Administration > Plugins > Catalog > $plugin_name "
457504 return 0
458505 fi
459506
460- # Get latest version
461- local install_result
507+ local install_result encoded_name install_url
508+ encoded_name=" $( url_encode " $resolved_name " ) "
509+ install_url=" http://localhost:8096/Packages/Installed/$encoded_name "
510+ if [[ -n " $plugin_guid " ]]; then
511+ install_url=" ${install_url} ?assemblyGuid=$plugin_guid "
512+ fi
513+
462514 install_result=$( curl -s -o /dev/null -w " %{http_code}" -X POST \
463- " http://localhost:8096/Packages/Installed/ $plugin_name " \
515+ " $install_url " \
464516 -H " X-Emby-Token: $JF_API_KEY " 2> /dev/null || echo " 000" )
465517
466518 if [[ " $install_result " =~ ^2 ]]; then
467- log " $plugin_name plugin installed"
519+ log " $resolved_name plugin installed"
468520 else
469- warn " $plugin_name : install returned HTTP $install_result "
521+ warn " $resolved_name : install returned HTTP $install_result "
470522 warn " Install manually: Administration > Plugins > Catalog > $plugin_name "
471523 fi
472524 }
0 commit comments