From aac1cc6dd4ddf498c484d05780519c9e05bf571c Mon Sep 17 00:00:00 2001 From: BigNoid Date: Tue, 17 Jan 2017 22:11:11 +0100 Subject: [PATCH] rewrite addon to also be available as video addon --- default.py => plugin.py | 60 ++++++++------------------ resources/lib/data.py | 7 +-- library.py => resources/lib/library.py | 16 +++---- resources/lib/router.py | 57 ++++++++++++++++++++++++ service.py | 21 +++------ 5 files changed, 90 insertions(+), 71 deletions(-) rename default.py => plugin.py (79%) rename library.py => resources/lib/library.py (97%) create mode 100644 resources/lib/router.py diff --git a/default.py b/plugin.py similarity index 79% rename from default.py rename to plugin.py index cd3de46..dc307b3 100644 --- a/default.py +++ b/plugin.py @@ -25,14 +25,13 @@ import xbmcplugin import xbmcaddon from resources.lib import data +from resources.lib import router ADDON = xbmcaddon.Addon() ADDON_VERSION = ADDON.getAddonInfo('version') ADDON_NAME = ADDON.getAddonInfo('name') ADDON_LANGUAGE = ADDON.getLocalizedString -PLOT_ENABLE = True - def log(txt): message = '%s: %s' % (ADDON_NAME, txt.encode('ascii', 'ignore')) @@ -44,68 +43,70 @@ class Main: def __init__(self): self._init_vars() self._parse_argv() + if not self.TYPE: + router.run() for content_type in self.TYPE.split("+"): full_liz = list() if content_type == "randommovies": xbmcplugin.setContent(int(sys.argv[1]), 'movies') - data.parse_movies('randommovies', 32004, full_liz, self.USECACHE, PLOT_ENABLE, self.LIMIT) + data.parse_movies('randommovies', 32004, full_liz, self.USECACHE, self.PLOT_ENABLE, self.LIMIT) xbmcplugin.addDirectoryItems(int(sys.argv[1]), full_liz) elif content_type == "recentmovies": xbmcplugin.setContent(int(sys.argv[1]), 'movies') - data.parse_movies('recentmovies', 32005, full_liz, self.USECACHE, PLOT_ENABLE, self.LIMIT) + data.parse_movies('recentmovies', 32005, full_liz, self.USECACHE, self.PLOT_ENABLE, self.LIMIT) xbmcplugin.addDirectoryItems(int(sys.argv[1]), full_liz) elif content_type == "recommendedmovies": xbmcplugin.setContent(int(sys.argv[1]), 'movies') - data.parse_movies('recommendedmovies', 32006, full_liz, self.USECACHE, PLOT_ENABLE, self.LIMIT) + data.parse_movies('recommendedmovies', 32006, full_liz, self.USECACHE, self.PLOT_ENABLE, self.LIMIT) xbmcplugin.addDirectoryItems(int(sys.argv[1]), full_liz) elif content_type == "recommendedepisodes": xbmcplugin.setContent(int(sys.argv[1]), 'episodes') - data.parse_tvshows_recommended('recommendedepisodes', 32010, full_liz, self.USECACHE, PLOT_ENABLE, self.LIMIT) + data.parse_tvshows_recommended('recommendedepisodes', 32010, full_liz, self.USECACHE, self.PLOT_ENABLE, self.LIMIT) xbmcplugin.addDirectoryItems(int(sys.argv[1]), full_liz) elif content_type == "favouriteepisodes": xbmcplugin.setContent(int(sys.argv[1]), 'episodes') - data.parse_tvshows_favourite('favouriteepisodes', 32020, full_liz, self.USECACHE, PLOT_ENABLE, self.LIMIT) + data.parse_tvshows_favourite('favouriteepisodes', 32020, full_liz, self.USECACHE, self.PLOT_ENABLE, self.LIMIT) xbmcplugin.addDirectoryItems(int(sys.argv[1]), full_liz) elif content_type == "recentepisodes": xbmcplugin.setContent(int(sys.argv[1]), 'episodes') - data.parse_tvshows('recentepisodes', 32008, full_liz, self.USECACHE, PLOT_ENABLE, self.LIMIT) + data.parse_tvshows('recentepisodes', 32008, full_liz, self.USECACHE, self.PLOT_ENABLE, self.LIMIT) xbmcplugin.addDirectoryItems(int(sys.argv[1]), full_liz) elif content_type == "randomepisodes": xbmcplugin.setContent(int(sys.argv[1]), 'episodes') - data.parse_tvshows('randomepisodes', 32007, full_liz, self.USECACHE, PLOT_ENABLE, self.LIMIT) + data.parse_tvshows('randomepisodes', 32007, full_liz, self.USECACHE, self.PLOT_ENABLE, self.LIMIT) xbmcplugin.addDirectoryItems(int(sys.argv[1]), full_liz) elif content_type == "recentvideos": listA = [] listB = [] dateListA = [] dateListB = [] - data.parse_movies('recentmovies', 32005, listA, dateListA, "dateadded", self.USECACHE, PLOT_ENABLE, self.LIMIT) - data.parse_tvshows('recentepisodes', 32008, listB, dateListB, "dateadded", self.USECACHE, PLOT_ENABLE, self.LIMIT) + data.parse_movies('recentmovies', 32005, listA, dateListA, "dateadded", self.USECACHE, self.PLOT_ENABLE, self.LIMIT) + data.parse_tvshows('recentepisodes', 32008, listB, dateListB, "dateadded", self.USECACHE, self.PLOT_ENABLE, self.LIMIT) full_liz = data._combine_by_date(listA, dateListA, listB, dateListB, self.LIMIT, self.SETTINGLIMIT) xbmcplugin.addDirectoryItems(int(sys.argv[1]), full_liz) elif content_type == "randomalbums": xbmcplugin.setContent(int(sys.argv[1]), 'albums') - data.parse_albums('randomalbums', 32016, full_liz, self.USECACHE, PLOT_ENABLE, self.LIMIT) + data.parse_albums('randomalbums', 32016, full_liz, self.USECACHE, self.PLOT_ENABLE, self.LIMIT) xbmcplugin.addDirectoryItems(int(sys.argv[1]), full_liz) elif content_type == "recentalbums": xbmcplugin.setContent(int(sys.argv[1]), 'albums') - data.parse_albums('recentalbums', 32017, full_liz, self.USECACHE, PLOT_ENABLE, self.LIMIT) + data.parse_albums('recentalbums', 32017, full_liz, self.USECACHE, self.PLOT_ENABLE, self.LIMIT) xbmcplugin.addDirectoryItems(int(sys.argv[1]), full_liz) elif content_type == "recommendedalbums": xbmcplugin.setContent(int(sys.argv[1]), 'albums') - data.parse_albums('recommendedalbums', 32018, full_liz, self.USECACHE, PLOT_ENABLE, self.LIMIT) + data.parse_albums('recommendedalbums', 32018, full_liz, self.USECACHE, self.PLOT_ENABLE, self.LIMIT) xbmcplugin.addDirectoryItems(int(sys.argv[1]), full_liz) elif content_type == "randomsongs": xbmcplugin.setContent(int(sys.argv[1]), 'songs') - data.parse_song('randomsongs', 32015, full_liz, self.USECACHE, PLOT_ENABLE, self.LIMIT) + data.parse_song('randomsongs', 32015, full_liz, self.USECACHE, self.PLOT_ENABLE, self.LIMIT) xbmcplugin.addDirectoryItems(int(sys.argv[1]), full_liz) elif content_type == "randommusicvideos": xbmcplugin.setContent(int(sys.argv[1]), 'musicvideos') - data.parse_musicvideos('randommusicvideos', 32022, full_liz, self.USECACHE, PLOT_ENABLE, self.LIMIT) + data.parse_musicvideos('randommusicvideos', 32022, full_liz, self.USECACHE, self.PLOT_ENABLE, self.LIMIT) xbmcplugin.addDirectoryItems(int(sys.argv[1]), full_liz) elif content_type == "recentmusicvideos": xbmcplugin.setContent(int(sys.argv[1]), 'musicvideos') - data.parse_musicvideos('recentmusicvideos', 32023, full_liz, self.USECACHE, PLOT_ENABLE, self.LIMIT) + data.parse_musicvideos('recentmusicvideos', 32023, full_liz, self.USECACHE, self.PLOT_ENABLE, self.LIMIT) xbmcplugin.addDirectoryItems(int(sys.argv[1]), full_liz) elif content_type == "movie": xbmcplugin.setContent(int(sys.argv[1]), 'movies') @@ -130,35 +131,12 @@ def __init__(self): elif content_type == "play_album": data.play_album(self.ALBUM) return - - if not self.TYPE: - # Show a root menu - full_liz = list() - items = [[32004, "randommovies"], - [32005, "recentmovies"], - [32006, "recommendedmovies"], - [32007, "randomepisodes"], - [32008, "recentepisodes"], - [32010, "recommendedepisodes"], - [32020, "favouriteepisodes"], - [32019, "recentvideos"], - [32016, "randomalbums"], - [32017, "recentalbums"], - [32018, "recommendedalbums"], - [32015, "randomsongs"], - [32022, "randommusicvideos"], - [32023, "recentmusicvideos"]] - for item in items: - liz = xbmcgui.ListItem(ADDON_LANGUAGE(item[0]), iconImage='DefaultFolder.png') - full_liz.append(("plugin://service.library.data.provider?type=" + item[1], liz, True)) - xbmcplugin.addDirectoryItems(int(sys.argv[1]), full_liz) xbmcplugin.endOfDirectory(handle=int(sys.argv[1])) def _init_vars(self): self.WINDOW = xbmcgui.Window(10000) self.SETTINGSLIMIT = int(ADDON.getSetting("limit")) - global PLOT_ENABLE - PLOT_ENABLE = ADDON.getSetting("plot_enable") == 'true' + self.PLOT_ENABLE = ADDON.getSetting("plot_enable") == 'true' self.RANDOMITEMS_UNPLAYED = ADDON.getSetting("randomitems_unplayed") == 'true' def _parse_argv(self): diff --git a/resources/lib/data.py b/resources/lib/data.py index def4b01..fd9a4c3 100644 --- a/resources/lib/data.py +++ b/resources/lib/data.py @@ -24,12 +24,9 @@ import xbmcgui import xbmcaddon import xbmcplugin -import library +import json as simplejson +from resources.lib import library -if sys.version_info < (2, 7): - import simplejson -else: - import json as simplejson ADDON = xbmcaddon.Addon() ADDON_VERSION = ADDON.getAddonInfo('version') diff --git a/library.py b/resources/lib/library.py similarity index 97% rename from library.py rename to resources/lib/library.py index 5337fb7..e9756c6 100755 --- a/library.py +++ b/resources/lib/library.py @@ -19,18 +19,12 @@ # This script is based on service.skin.widgets # Thanks to the original authors -import sys import xbmc import xbmcgui import xbmcaddon +import json from time import gmtime, strftime -if sys.version_info < (2, 7): - import simplejson as json -else: - import json - -__addon__ = xbmcaddon.Addon() PLOT_ENABLE = True @@ -38,10 +32,10 @@ class LibraryFunctions(): def __init__(self): self.WINDOW = xbmcgui.Window(10000) - self.LIMIT = int(__addon__.getSetting("limit")) - self.RECENTITEMS_UNPLAYED = __addon__.getSetting("recentitems_unplayed") == 'true' - self.RANDOMITEMS_UNPLAYED = __addon__.getSetting("randomitems_unplayed") == 'true' - self.INCLUDE_SPECIALS = __addon__.getSetting("include_specials") == 'true' + self.LIMIT = int(xbmcaddon.Addon().getSetting("limit")) + self.RECENTITEMS_UNPLAYED = xbmcaddon.Addon().getSetting("recentitems_unplayed") == 'true' + self.RANDOMITEMS_UNPLAYED = xbmcaddon.Addon().getSetting("randomitems_unplayed") == 'true' + self.INCLUDE_SPECIALS = xbmcaddon.Addon().getSetting("include_specials") == 'true' def _get_data(self, query_type, useCache): # Check if data is being refreshed elsewhere diff --git a/resources/lib/router.py b/resources/lib/router.py new file mode 100644 index 0000000..b602efb --- /dev/null +++ b/resources/lib/router.py @@ -0,0 +1,57 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# +# Copyright (C) 2017 BigNoid +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +import xbmcplugin +import xbmcgui +import xbmcaddon +import routing + +ADDON_LANGUAGE = xbmcaddon.Addon().getLocalizedString + + +plugin = routing.Plugin() + + +def run(): + plugin.run() + + +@plugin.route('/') +def root(): + xbmcplugin.setPluginCategory(plugin.handle, "Media") + items = [("randommovies", ADDON_LANGUAGE(32004), "DefaultMovies.png"), + ("recentmovies", ADDON_LANGUAGE(32005), "DefaultRecentlyAddedMovies.png"), + ("recommendedmovies", ADDON_LANGUAGE(32006), "DefaultMovieTitle.png"), + ("randomepisodes", ADDON_LANGUAGE(32007), "DefaultTVShows.png"), + ("recentepisodes", ADDON_LANGUAGE(32008), "DefaultRecentlyAddedEpisodes.png"), + ("recommendedepisodes", ADDON_LANGUAGE(32010), "DefaultTVShowTitle.png"), + ("favouriteepisodes", ADDON_LANGUAGE(32020), "DefaultTVShows.png"), + ("recentvideos", ADDON_LANGUAGE(32019), "DefaultVideo.png"), + ("randommusicvideos", ADDON_LANGUAGE(32022), "DefaultMusicVideos.png"), + ("recentmusicvideos", ADDON_LANGUAGE(32023), "DefaultRecentlyAddedMusicVideos.png")] + for call, title, thumb in items: + liz = xbmcgui.ListItem(label=title, + thumbnailImage=thumb) + url = 'plugin://service.library.data.provider?type=%s' % call + xbmcplugin.addDirectoryItem(handle=plugin.handle, + url=url, + listitem=liz, + isFolder=True) + xbmcplugin.addSortMethod(plugin.handle, xbmcplugin.SORT_METHOD_NONE) + xbmcplugin.endOfDirectory(plugin.handle) diff --git a/service.py b/service.py index 5fa5384..8c5828d 100644 --- a/service.py +++ b/service.py @@ -19,28 +19,21 @@ # This script is based on service.skin.widgets # Thanks to the original authors -import sys import xbmc import xbmcgui import xbmcaddon import datetime -import library +from resources.lib import library LIBRARY = library.LibraryFunctions() -if sys.version_info < (2, 7): - import simplejson -else: - import json as simplejson -__addon__ = xbmcaddon.Addon() -__addonversion__ = __addon__.getAddonInfo('version') -__addonid__ = __addon__.getAddonInfo('id') -__addonname__ = __addon__.getAddonInfo('name') -__localize__ = __addon__.getLocalizedString +ADDON = xbmcaddon.Addon() +ADDON_VERSION = ADDON.getAddonInfo('version') +ADDON_NAME = ADDON.getAddonInfo('name') def log(txt): - message = '%s: %s' % (__addonname__, txt.encode('ascii', 'ignore')) + message = '%s: %s' % (ADDON_NAME, txt.encode('ascii', 'ignore')) xbmc.log(msg=message, level=xbmc.LOGDEBUG) @@ -184,6 +177,6 @@ def onPlayBackStopped(self): self.type = "" -log('service version %s started' % __addonversion__) +log('service version %s started' % ADDON_VERSION) Main() -log('service version %s stopped' % __addonversion__) +log('service version %s stopped' % ADDON_VERSION)