initial commit
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
/dist
|
||||||
37
Makefile
Normal file
37
Makefile
Normal file
@@ -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)"
|
||||||
112
addon.py
Normal file
112
addon.py
Normal file
@@ -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()
|
||||||
22
addon.xml
Normal file
22
addon.xml
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<addon id="script.utils"
|
||||||
|
name="Utility"
|
||||||
|
version="1.0.0"
|
||||||
|
provider-name="custom">
|
||||||
|
|
||||||
|
<requires>
|
||||||
|
<import addon="xbmc.python" version="3.0.0"/>
|
||||||
|
</requires>
|
||||||
|
|
||||||
|
<extension point="xbmc.python.pluginsource" library="addon.py">
|
||||||
|
<provides>executable</provides>
|
||||||
|
</extension>
|
||||||
|
|
||||||
|
<extension point="xbmc.addon.metadata">
|
||||||
|
<summary lang="en_GB">Custom scripts</summary>
|
||||||
|
<description lang="en_GB">Open plugin and add scripts to favourites via context menu</description>
|
||||||
|
<platform>all</platform>
|
||||||
|
<license>MIT</license>
|
||||||
|
</extension>
|
||||||
|
|
||||||
|
</addon>
|
||||||
7
resources/settings.xml
Normal file
7
resources/settings.xml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<settings>
|
||||||
|
<category label="NAS">
|
||||||
|
<setting id="nas_host" type="string" label="Host" default="" />
|
||||||
|
<setting id="nas_key" type="string" label="API Key" default="" />
|
||||||
|
</category>
|
||||||
|
</settings>
|
||||||
Reference in New Issue
Block a user