Skip to content

Commit

Permalink
rewrite addon to also be available as video addon
Browse files Browse the repository at this point in the history
  • Loading branch information
BigNoid committed Jan 17, 2017
1 parent fb7ed10 commit aac1cc6
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 71 deletions.
60 changes: 19 additions & 41 deletions default.py → plugin.py
Expand Up @@ -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'))
Expand All @@ -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')
Expand All @@ -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):
Expand Down
7 changes: 2 additions & 5 deletions resources/lib/data.py
Expand Up @@ -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')
Expand Down
16 changes: 5 additions & 11 deletions library.py → resources/lib/library.py
Expand Up @@ -19,29 +19,23 @@
# 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


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
Expand Down
57 changes: 57 additions & 0 deletions 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 <http://www.gnu.org/licenses/>.
#

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)
21 changes: 7 additions & 14 deletions service.py
Expand Up @@ -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)


Expand Down Expand Up @@ -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)

0 comments on commit aac1cc6

Please sign in to comment.