Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the router implementation using routing #318

Merged
merged 1 commit into from
Jun 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ script:
- python test/apihelpertests.py
- python test/tvguidetests.py
- python test/searchtests.py
- python test/routertests.py
- python test/routingtests.py
#- python test/favoritestests.py
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ unit:
PYTHONPATH=$(CURDIR) python test/apihelpertests.py
PYTHONPATH=$(CURDIR) python test/tvguidetests.py
PYTHONPATH=$(CURDIR) python test/searchtests.py
PYTHONPATH=$(CURDIR) python test/routertests.py
PYTHONPATH=$(CURDIR) python test/routingtests.py
PYTHONPATH=$(CURDIR) python test/favoritestests.py
@echo -e "$(white)=$(blue) Unit tests finished successfully.$(reset)"

Expand Down
192 changes: 190 additions & 2 deletions addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,198 @@

''' This is the actual VRT NU video plugin entry point '''

# pylint: disable=missing-docstring

from __future__ import absolute_import, division, unicode_literals
import sys
import routing
from resources.lib import kodiwrapper

plugin = routing.Plugin()
_kodi = kodiwrapper.KodiWrapper(plugin)


@plugin.route('/')
def main_menu():
from resources.lib import vrtplayer
_vrtplayer = vrtplayer.VRTPlayer(_kodi)
_vrtplayer.show_main_menu_items()


@plugin.route('/cache/delete')
@plugin.route('/cache/delete/<cache_file>')
def delete_cache(cache_file=None):
if cache_file:
_kodi.refresh_caches(cache_file)
return
_kodi.invalidate_caches()


@plugin.route('/widevine/install')
def install_widevine():
_kodi.install_widevine()


@plugin.route('/tokens/delete')
def delete_tokens():
from resources.lib import tokenresolver
_tokenresolver = tokenresolver.TokenResolver(_kodi)
_tokenresolver.delete_tokens()


@plugin.route('/follow/<title>/<program>')
def follow(title, program):
from resources.lib import favorites
_favorites = favorites.Favorites(_kodi)
_favorites.follow(title=title, program=program)


@plugin.route('/unfollow/<title>/<program>')
def unfollow(title, program):
from resources.lib import favorites
_favorites = favorites.Favorites(_kodi)
_favorites.unfollow(title=title, program=program)


@plugin.route('/play/id/<video_id>')
@plugin.route('/play/id/<publication_id>/<video_id>')
def play_id(video_id, publication_id=None):
from resources.lib import vrtplayer
_vrtplayer = vrtplayer.VRTPlayer(_kodi)

if video_id and publication_id:
_vrtplayer.play(dict(publication_id=publication_id, video_id=video_id))
elif video_id:
_vrtplayer.play(dict(video_id=video_id))


@plugin.route('/play/url/<path:video_url>')
def play_url(video_url):
from resources.lib import vrtplayer
_vrtplayer = vrtplayer.VRTPlayer(_kodi)
_vrtplayer.play(dict(video_url=video_url))


@plugin.route('/play/lastepisode/<program>')
def play_last(program):
from resources.lib import vrtplayer
_vrtplayer = vrtplayer.VRTPlayer(_kodi)
_vrtplayer.play_latest_episode(program)


@plugin.route('/favorites')
def favorites_menu():
from resources.lib import vrtplayer
_vrtplayer = vrtplayer.VRTPlayer(_kodi)
_vrtplayer.show_favorites_menu_items()


@plugin.route('/favorites/programs')
def favorites_programs():
from resources.lib import vrtplayer
_vrtplayer = vrtplayer.VRTPlayer(_kodi)
_vrtplayer.show_tvshow_menu_items(use_favorites=True)


@plugin.route('/favorites/recent')
@plugin.route('/favorites/recent/<page>')
def favorites_recent(page=1):
from resources.lib import vrtplayer
_vrtplayer = vrtplayer.VRTPlayer(_kodi)
_vrtplayer.show_recent(page=page, use_favorites=True)


@plugin.route('/favorites/offline')
@plugin.route('/favorites/offline/<page>')
def favorites_offline(page=1):
from resources.lib import vrtplayer
_vrtplayer = vrtplayer.VRTPlayer(_kodi)
_vrtplayer.show_offline(page=page, use_favorites=True)


@plugin.route('/favorites/refresh')
def favorites_refresh():
from resources.lib import favorites
_favorites = favorites.Favorites(_kodi)
_favorites.get_favorites(ttl=0)


@plugin.route('/programs')
@plugin.route('/programs/<program>')
@plugin.route('/programs/<program>/<season>')
def programs(program=None, season=None):
from resources.lib import vrtplayer
_vrtplayer = vrtplayer.VRTPlayer(_kodi)
if program:
_vrtplayer.show_episodes(program, season)
return
_vrtplayer.show_tvshow_menu_items()


@plugin.route('/categories')
@plugin.route('/categories/<category>')
def categories(category=None):
from resources.lib import vrtplayer
_vrtplayer = vrtplayer.VRTPlayer(_kodi)
if category:
_vrtplayer.show_tvshow_menu_items(category=category)
return
_vrtplayer.show_category_menu_items()


@plugin.route('/channels')
@plugin.route('/channels/<channel>')
def channels(channel=None):
from resources.lib import vrtplayer
_vrtplayer = vrtplayer.VRTPlayer(_kodi)
_vrtplayer.show_channels_menu_items(channel=channel)


@plugin.route('/livetv')
def livetv():
from resources.lib import vrtplayer
_vrtplayer = vrtplayer.VRTPlayer(_kodi)
_vrtplayer.show_livestream_items()


@plugin.route('/recent')
@plugin.route('/recent/<page>')
def recent(page=1):
from resources.lib import vrtplayer
_vrtplayer = vrtplayer.VRTPlayer(_kodi)
_vrtplayer.show_recent(page=page)


@plugin.route('/offline')
@plugin.route('/offline/<page>')
def offline(page=1):
from resources.lib import vrtplayer
_vrtplayer = vrtplayer.VRTPlayer(_kodi)
_vrtplayer.show_offline(page=page)


@plugin.route('/tvguide')
@plugin.route('/tvguide/<date>')
@plugin.route('/tvguide/<date>/<channel>')
def tv_guide(date=None, channel=None):
from resources.lib import tvguide
_tvguide = tvguide.TVGuide(_kodi)
_tvguide.show_tvguide(date=date, channel=channel)


@plugin.route('/search')
@plugin.route('/search/<search_string>')
@plugin.route('/search/<search_string>/<page>')
def search(search_string=None, page=1):
from resources.lib import vrtplayer
_vrtplayer = vrtplayer.VRTPlayer(_kodi)
_vrtplayer.search(search_string=search_string, page=page)


def test(path):
plugin.run(path)

from resources.lib import router

if __name__ == '__main__':
router.router(sys.argv)
_kodi.log_access(sys.argv[0])
plugin.run(sys.argv)
5 changes: 3 additions & 2 deletions addon.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="plugin.video.vrt.nu" name="VRT NU" version="1.10.1" provider-name="Martijn Moreel, dagwieers">
<addon id="plugin.video.vrt.nu" name="VRT NU" version="2.0.0" provider-name="Martijn Moreel, dagwieers">
<requires>
<import addon="resource.images.studios.white" version="0.0.21"/>
<import addon="script.module.beautifulsoup4" version="4.5.3"/>
<import addon="script.module.dateutil" version="2.6.0"/>
<import addon="script.module.inputstreamhelper" version="0.3.3"/>
<!-- import addon="inputstream.adaptive" version="2.0.20" optional="true"/ -->
<import addon="script.module.inputstreamhelper" version="0.3.3"/>
<import addon="script.module.pysocks" version="1.6.8" optional="true"/>
<import addon="script.module.routing" version="0.2.0"/>
<import addon="xbmc.python" version="2.25.0"/>
</requires>

Expand Down
1 change: 1 addition & 0 deletions pylintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[MESSAGES CONTROL]
disable=
bad-option-value,
broad-except,
duplicate-code,
fixme,
Expand Down
4 changes: 4 additions & 0 deletions resources/language/resource.language.en_gb/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ msgctxt "#30412"
msgid "Unfollow"
msgstr ""

msgctxt "#30413"
msgid "Refresh"
msgstr ""

msgctxt "#30415"
msgid "No followed programs found"
msgstr ""
Expand Down
4 changes: 4 additions & 0 deletions resources/language/resource.language.nl_nl/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@ msgctxt "#30412"
msgid "Unfollow"
msgstr "Vergeet"

msgctxt "#30413"
msgid "Refresh"
msgstr "Vernieuw"

msgctxt "#30415"
msgid "No followed programs found"
msgstr "Geen programma's worden gevolgd"
Expand Down
16 changes: 8 additions & 8 deletions resources/lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@
studio='Sporza',
live_stream_id='vualto_sporza_geo',
),
dict(
id='13',
name='vrtnws',
label='VRT NWS',
studio='VRT NWS',
live_stream_id='vualto_nieuws',
# live_stream_id='vualto_journaal',
),
dict(
id='11',
name='radio1',
Expand Down Expand Up @@ -106,14 +114,6 @@
label='VRT NXT',
studio='VRT NXT',
),
dict(
id='13',
name='vrtnws',
label='VRT NWS',
studio='VRT NWS',
live_stream_id='vualto_nieuws',
# live_stream_id='vualto_journaal',
),
]


Expand Down
8 changes: 4 additions & 4 deletions resources/lib/favorites.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
''' Implementation of Favorites class '''

from __future__ import absolute_import, division, unicode_literals
from resources.lib import statichelper
from resources.lib import statichelper, tokenresolver

try: # Python 3
from urllib.parse import unquote
Expand All @@ -18,10 +18,10 @@
class Favorites:
''' Track, cache and manage VRT favorites '''

def __init__(self, _kodi, _tokenresolver):
def __init__(self, _kodi):
''' Initialize favorites, relies on XBMC vfs and a special VRT token '''
self._kodi = _kodi
self._tokenresolver = _tokenresolver
self._tokenresolver = tokenresolver.TokenResolver(_kodi)
self._proxies = _kodi.get_proxies()
install_opener(build_opener(ProxyHandler(self._proxies)))
# This is our internal representation
Expand Down Expand Up @@ -67,7 +67,7 @@ def set_favorite(self, title, program, value=True):

xvrttoken = self._tokenresolver.get_xvrttoken(token_variant='user')
if xvrttoken is None:
self._kodi.show_notification(message='Failed to get favorites roken from VRT NU')
self._kodi.show_notification(message='Failed to get favorites token from VRT NU')
self._kodi.log_error('Failed to get favorites token from VRT NU')
return False

Expand Down
7 changes: 4 additions & 3 deletions resources/lib/kodiwrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,11 @@ def has_socks():
class KodiWrapper:
''' A wrapper around all Kodi functionality '''

def __init__(self, handle, url):
def __init__(self, plugin):
''' Initialize the Kodi wrapper '''
self._handle = handle
self._url = url
self._plugin = plugin
self._handle = plugin.handle if plugin else -1
self._url = plugin.base_url if plugin else 'plugin://plugin.video.vrt.nu'
self._addon = xbmcaddon.Addon()
self._addon_id = self._addon.getAddonInfo('id')
self._max_log_level = log_levels.get(self.get_setting('max_log_level', 'Debug'), 3)
Expand Down
Loading