commit ebc288b54d34f273ec4a1f573edf6f32f28dc24e Author: Niklas Kapelle Date: Tue Jun 9 00:04:11 2026 +0200 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9b1c8b1 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/dist diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..979ba67 --- /dev/null +++ b/Makefile @@ -0,0 +1,37 @@ +# Targets: +# make - build the installable ZIP +# make clean - remove build artefacts +# make version - print current version read from addon.xml + +ADDON_ID := $(shell grep -oP '(?<=id=")[^"]+' addon.xml | head -1) +ADDON_VERSION := $(shell grep -oP '(?<=version=")[^"]+' addon.xml | head -1).0 + +ZIP_NAME := $(ADDON_ID)-$(ADDON_VERSION).zip +DIST_DIR := dist +STAGE_DIR := $(DIST_DIR)/$(ADDON_ID)-$(ADDON_VERSION) + +SRC_FILES := addon.py addon.xml resources + +.PHONY: all zip clean version + +all: zip + +zip: $(DIST_DIR)/$(ZIP_NAME) + +stage: + rm -rf $(STAGE_DIR) + mkdir -p $(STAGE_DIR) + cp -r $(SRC_FILES) $(STAGE_DIR)/ + +$(DIST_DIR)/$(ZIP_NAME): stage + cd $(DIST_DIR) && \ + zip -r $(ZIP_NAME) $(ADDON_ID)-$(ADDON_VERSION) \ + --exclude "*.pyc" \ + --exclude "*/__pycache__/*" \ + --exclude "*.DS_Store" + +clean: + rm -rf $(DIST_DIR) + +version: + @echo "$(ADDON_ID) v$(ADDON_VERSION)" diff --git a/addon.py b/addon.py new file mode 100644 index 0000000..f264539 --- /dev/null +++ b/addon.py @@ -0,0 +1,112 @@ +import sys +import urllib.parse +import urllib.request +import xbmc +import xbmcaddon +import xbmcgui +import xbmcplugin + +ADDON = xbmcaddon.Addon() +ADDON_ID = ADDON.getAddonInfo("id") +ADDON_NAME = ADDON.getAddonInfo("name") +HANDLE = int(sys.argv[1]) if len(sys.argv) > 1 else -1 +PARAMS_STR = sys.argv[2] if len(sys.argv) > 2 else "" + +def run_trigger(n): + if n == 0: + return notify("Yay","One",success=True) + elif n == 1: + return notify("Yay","Two",success=True) + else: + return notify("Oh no","You fucked up",success=False) + + +def get_trigger_config(n): + if n == 0: + return "One" + elif n == 1: + return "Two" + else: + return None + + +def show_menu(): + """ + Build a virtual directory listing with one item per configured trigger. + Each item can be added to Favourites individually. + """ + xbmcplugin.setPluginCategory(HANDLE, ADDON_NAME) + xbmcplugin.setContent(HANDLE, "files") + + n = 0 + while True: + cfg = get_trigger_config(n) + + if cfg == None: + break + + run_url = f"plugin://{ADDON_ID}/?trigger={n}" + label = cfg + sublabel = "[not configured]" + + li = xbmcgui.ListItem(label=label, label2=sublabel) + li.setArt({"icon": "DefaultAddonProgram.png"}) + li.setInfo("video", {"title": label, "plot": sublabel}) + li.setProperty("IsPlayable", "false") + + li.addContextMenuItems([ + ( + f"Add '{label}' to Favourites", + f"RunScript(special://home/addons/{ADDON_ID}/addon.py,trigger={n})" + ) + ]) + + xbmcplugin.addDirectoryItem( + handle=HANDLE, + url=run_url, + listitem=li, + isFolder=False, + ) + + n += 1 + + xbmcplugin.endOfDirectory(HANDLE) + +def notify(title, message, success=True): + """Show a Kodi notification toast.""" + icon = xbmcgui.NOTIFICATION_INFO if success else xbmcgui.NOTIFICATION_ERROR + xbmcgui.Dialog().notification(title, message, icon=icon, time=4000) + +def get_params(): + """Parse the query-string arguments Kodi passes as sys.argv[2].""" + if PARAMS_STR.startswith("?"): + return dict(urllib.parse.parse_qsl(PARAMS_STR[1:])) + return {} + +def main(): + params = get_params() + + # Called with ?trigger=N (from the favorites menu) + if "trigger" in params: + try: + n = int(params["trigger"]) + except ValueError: + notify(ADDON_NAME, "Invalid trigger parameter", success=False) + return + if get_trigger_config(n) == None: + notify(ADDON_NAME, f"Trigger {n} out of range", success=False) + return + run_trigger(n) + return + + # Called with ?action=settings + if params.get("action") == "settings": + ADDON.openSettings() + return + + # No param + show_menu() + + +if __name__ == "__main__": + main() diff --git a/addon.xml b/addon.xml new file mode 100644 index 0000000..184160d --- /dev/null +++ b/addon.xml @@ -0,0 +1,22 @@ + + + + + + + + + executable + + + + Custom scripts + Open plugin and add scripts to favourites via context menu + all + MIT + + + diff --git a/resources/settings.xml b/resources/settings.xml new file mode 100644 index 0000000..dfaf7fe --- /dev/null +++ b/resources/settings.xml @@ -0,0 +1,7 @@ + + + + + + +