Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Commit

Permalink
Trim down main class and call the correct followup implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
razzeee committed Jan 23, 2017
1 parent 7a7035f commit d05a98f
Show file tree
Hide file tree
Showing 10 changed files with 259 additions and 97 deletions.
61 changes: 50 additions & 11 deletions generators/app/index.js
Expand Up @@ -168,30 +168,39 @@ module.exports = yeoman.extend({
this.destinationPath('README.md')
);

if (this.props.type != 'Module' && this.props.type != 'Resource') {
this.fs.copyTpl(
this.templatePath('main.py'),
this.destinationPath('main.py'), {
props: this.props
}
);
}

if (this.props.type == 'Contextmenu') {
this.fs.copy(
this.templatePath('context.py'),
this.destinationPath('context.py')
this.templatePath('resources/lib/context.py'),
this.destinationPath('resources/lib/context.py')
);
} else if (this.props.type == 'Plugin') {
this.fs.copy(
this.templatePath('plugin.py'),
this.destinationPath('plugin.py')
this.templatePath('resources/lib/plugin.py'),
this.destinationPath('resources/lib/plugin.py')
);
} else if (this.props.type == 'Script') {
this.fs.copy(
this.templatePath('script.py'),
this.destinationPath('script.py')
this.templatePath('resources/lib/script.py'),
this.destinationPath('resources/lib/script.py')
);
} else if (this.props.type == 'Service') {
this.fs.copy(
this.templatePath('service.py'),
this.destinationPath('service.py')
this.templatePath('resources/lib/service.py'),
this.destinationPath('resources/lib/service.py')
);
} else if (this.props.type == 'Subtitle') {
this.fs.copy(
this.templatePath('subtitle.py'),
this.destinationPath('subtitle.py')
this.templatePath('resources/lib/subtitle.py'),
this.destinationPath('resources/lib/subtitle.py')
);
}

Expand All @@ -210,10 +219,40 @@ module.exports = yeoman.extend({
);
} else {
this.fs.copyTpl(
this.templatePath('resources/**'),
this.templatePath('resources/*'),
this.destinationPath('resources/'), {
props: this.props
}
);
this.fs.copyTpl(
this.templatePath('resources/language/**'),
this.destinationPath('resources/language/'), {
props: this.props
}
);
this.fs.copyTpl(
this.templatePath('resources/lib/__init__.py'),
this.destinationPath('resources/lib/__init__.py'), {
props: this.props
}
);
this.fs.copyTpl(
this.templatePath('resources/lib/utilities.py'),
this.destinationPath('resources/lib/utilities.py'), {
props: this.props
}
);
this.fs.copyTpl(
this.templatePath('resources/lib/kodiLogging.py'),
this.destinationPath('resources/lib/kodiLogging.py'), {
props: this.props
}
);
this.fs.copyTpl(
this.templatePath('resources/lib/README.md'),
this.destinationPath('resources/lib/README.md'), {
props: this.props
}
);
}
}
Expand Down
8 changes: 4 additions & 4 deletions generators/app/templates/addon.xml
Expand Up @@ -5,17 +5,17 @@
<%_ if (props.type == 'Plugin') { -%> <import addon="script.module.routing" version="0.2.0"/><% } %>
<%_ if (props.kodiVersion == '2.24.0' && (props.type == 'Plugin' || props.type == 'Script' || props.type == 'Service')) { -%> <import addon="script.module.simplejson" version="3.3.0"/><% } %>
</requires>
<% if (props.type == 'Contextmenu') { -%><extension point="kodi.context.item" library="context.py">
<% if (props.type == 'Contextmenu') { -%><extension point="kodi.context.item" library="main.py">
<item>
<!-- This label can be changed in your strings.po -->
<label>32000</label>
<visible>True</visible>
</item>
</extension><% } -%><% if (props.type == 'Module') {%><extension point="xbmc.python.module" library="lib"/><% } %><% if (props.type == 'Plugin') {%><extension point="xbmc.python.pluginsource" library="plugin.py">
</extension><% } -%><% if (props.type == 'Module') {%><extension point="xbmc.python.module" library="lib"/><% } %><% if (props.type == 'Plugin') {%><extension point="xbmc.python.pluginsource" library="main.py">
<provides><%= provides %></provides>
</extension><% } %><% if (props.type == 'Resource') {%><extension point="kodi.resource.images" compile="false" type="skinbackgrounds"/><% } %><% if (props.type == 'Script') {%><extension point="xbmc.python.script" library="script.py">
</extension><% } %><% if (props.type == 'Resource') {%><extension point="kodi.resource.images" compile="false" type="skinbackgrounds"/><% } %><% if (props.type == 'Script') {%><extension point="xbmc.python.script" library="main.py">
<provides><%= provides %></provides>
</extension><% } %><% if (props.type == 'Service') {%><extension point="xbmc.service" library="service.py" start="<%= props.start %>"/><% } %><% if (props.type == 'Subtitle') {%><extension point="xbmc.subtitle.module" library="subtitle.py" /><% } %>
</extension><% } %><% if (props.type == 'Service') {%><extension point="xbmc.service" library="main.py" start="<%= props.start %>"/><% } %><% if (props.type == 'Subtitle') {%><extension point="xbmc.subtitle.module" library="main.py" /><% } %>
<extension point="xbmc.addon.metadata">
<summary lang="en_GB"><%= props.summary %></summary>
<description lang="en_GB"></description>
Expand Down
34 changes: 34 additions & 0 deletions generators/app/templates/main.py
@@ -0,0 +1,34 @@
# -*- coding: utf-8 -*-

from resources.lib import kodiLogging
<%_ if (props.type == 'Contextmenu') { -%>
from resources.lib import context
<%_ } else if (props.type == 'Plugin') { -%>
from resources.lib import plugin
<%_ } else if (props.type == 'Script') { -%>
from resources.lib import script
<%_ } else if (props.type == 'Service') { -%>
from resources.lib import service
<%_ } else if (props.type == 'Subtitle') { -%>
from resources.lib import subtitle
<% } %>
import logging
import xbmcaddon

# Keep this file to a minimum, as Kodi
# doesn't keep a compiled copy of this
ADDON = xbmcaddon.Addon()
kodiLogging.config()

<%_ if (props.type == 'Contextmenu') { -%>
context.run()
<%_ } else if (props.type == 'Plugin') { -%>
plugin.run()
<%_ } else if (props.type == 'Script') { -%>
script.show_dialog()
<%_ } else if (props.type == 'Service') { -%>
service.run()
<%_ } else if (props.type == 'Subtitle') { -%>
subtitle.run()
<% } %>

Expand Up @@ -3,18 +3,16 @@
import xbmcaddon
import xbmcgui

def main():

def run():
# Implement what your contextmenu aims to do here
# For example you could call executebuiltin to call another addon
# xbmc.executebuiltin("RunScript(script.example,action=show)")
# You might want to check your addon.xml for the visible condition of your contextmenu
# Read more here http://kodi.wiki/view/Context_Item_Add-ons
addon = xbmcaddon.Addon()
addonname = addon.getAddonInfo('name')
addon_name = addon.getAddonInfo('name')

line1 = "Hello World!"

xbmcgui.Dialog().ok(addonname, line1)

if __name__ == '__main__':
main()
xbmcgui.Dialog().ok(addon_name, line1)
Expand Up @@ -2,6 +2,7 @@

import routing
import logging
import xbmcaddon
from resources.lib import utilities
from resources.lib import kodiLogging
from xbmcgui import ListItem
Expand All @@ -13,16 +14,21 @@
kodiLogging.config()
plugin = routing.Plugin()


@plugin.route('/')
def index():
addDirectoryItem(plugin.handle, plugin.url_for(show_category, "one"), ListItem("Category One"), True)
addDirectoryItem(plugin.handle, plugin.url_for(show_category, "two"), ListItem("Category Two"), True)
addDirectoryItem(plugin.handle, plugin.url_for(
show_category, "one"), ListItem("Category One"), True)
addDirectoryItem(plugin.handle, plugin.url_for(
show_category, "two"), ListItem("Category Two"), True)
endOfDirectory(plugin.handle)


@plugin.route('/category/<category_id>')
def show_category(category_id):
addDirectoryItem(plugin.handle, "", ListItem("Hello category %s!" % category_id))
addDirectoryItem(
plugin.handle, "", ListItem("Hello category %s!" % category_id))
endOfDirectory(plugin.handle)

if __name__ == '__main__':
plugin.run()
def run():
plugin.run()
Expand Up @@ -9,12 +9,13 @@

ADDON = xbmcaddon.Addon()
logger = logging.getLogger(ADDON.getAddonInfo('id'))
kodiLogging.config()


# Put your code here, this is just an example showing
# a textbox as soon as this addon gets called
addonname = ADDON.getAddonInfo('name')
def show_dialog():
addon_name = ADDON.getAddonInfo('name')

line1 = "Hello World!"
line1 = "Hello World!"

xbmcgui.Dialog().ok(addonname, line1)
xbmcgui.Dialog().ok(addon_name, line1)
Expand Up @@ -5,18 +5,19 @@
import logging
import time
import xbmc
import xbmcaddon


ADDON = xbmcaddon.Addon()
logger = logging.getLogger(ADDON.getAddonInfo('id'))
kodiLogging.config()

if __name__ == '__main__':

def run():
monitor = xbmc.Monitor()

while not monitor.abortRequested():
# Sleep/wait for abort for 10 seconds
if monitor.waitForAbort(10):
# Abort was requested while waiting. We should exit
break
logger.debug("hello addon! %s" % time.time())
logger.debug("hello addon! %s" % time.time())
Expand Up @@ -33,7 +33,7 @@ def normalize_string(str):
'NFKD', unicode(unicode(str, 'utf-8'))
).encode('ascii', 'ignore')

# Gather all the information available from the playing item,
# Gather all the information available from the playing item,
# helps to determine what subtitle to list
def get_info():
item = {}
Expand Down Expand Up @@ -142,18 +142,19 @@ def download(params):
xbmcplugin.addDirectoryItem(
handle=HANDLE, url=file, listitem=xbmcgui.ListItem(label=file), isFolder=False)

# Gather the request info
params = get_params()

if 'action' in params:
if params['action'] == "search":
# If the action is 'search' use item information kodi provides to search for subtitles
search(get_info(), get_languages(params))
elif params['action'] == "manualsearch":
# If the action is 'manualsearch' use user manually inserted string to search for subtitles
manual_search(params['searchstring'], get_languages(params))
elif params['action'] == "download":
# If the action is 'download' use the info provided to download the subtitle and give the file path to kodi
download(params)

xbmcplugin.endOfDirectory(HANDLE)
def run():
# Gather the request info
params = get_params()

if 'action' in params:
if params['action'] == "search":
# If the action is 'search' use item information kodi provides to search for subtitles
search(get_info(), get_languages(params))
elif params['action'] == "manualsearch":
# If the action is 'manualsearch' use user manually inserted string to search for subtitles
manual_search(params['searchstring'], get_languages(params))
elif params['action'] == "download":
# If the action is 'download' use the info provided to download the subtitle and give the file path to kodi
download(params)

xbmcplugin.endOfDirectory(HANDLE)
35 changes: 22 additions & 13 deletions generators/app/templates/resources/lib/utilities.py
Expand Up @@ -5,7 +5,6 @@
import re
import sys
import logging

<%_ if (props.kodiVersion == '2.24.0') { -%>
if sys.version_info >= (2, 7):
import json as json
Expand All @@ -20,37 +19,46 @@

logger = logging.getLogger(__name__)


def notification(header, message, time=5000, icon=ADDON.getAddonInfo('icon'), sound=True):
xbmcgui.Dialog().notification(header, message, icon, time, sound)

def showSettings():

def show_settings():
ADDON.openSettings()

def getSetting(setting):

def get_setting(setting):
return ADDON.getSetting(setting).strip().decode('utf-8')

def setSetting(setting, value):

def set_setting(setting, value):
ADDON.setSetting(setting, str(value))

def getSettingAsBool(setting):
return getSetting(setting).lower() == "true"

def getSettingAsFloat(setting):
def get_setting_as_bool(setting):
return get_setting(setting).lower() == "true"


def get_setting_as_float(setting):
try:
return float(getSetting(setting))
return float(get_setting(setting))
except ValueError:
return 0

def getSettingAsInt(setting):

def get_setting_as_int(setting):
try:
return int(getSettingAsFloat(setting))
return int(get_setting_as_float(setting))
except ValueError:
return 0

def getString(string_id):

def get_string(string_id):
return ADDON.getLocalizedString(string_id).encode('utf-8', 'ignore')

def kodiJsonRequest(params):

def kodi_json_request(params):
data = json.dumps(params)
request = xbmc.executeJSONRPC(data)

Expand All @@ -64,5 +72,6 @@ def kodiJsonRequest(params):
return response['result']
return None
except KeyError:
logger.warn("[%s] %s" % (params['method'], response['error']['message']))
logger.warn("[%s] %s" %
(params['method'], response['error']['message']))
return None

0 comments on commit d05a98f

Please sign in to comment.