Skip to content

Commit

Permalink
Declare KodiWrapper locally when using reuselanguageinvoker
Browse files Browse the repository at this point in the history
  • Loading branch information
mediaminister committed Nov 14, 2019
1 parent 34240cd commit f0451c7
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 14 deletions.
46 changes: 42 additions & 4 deletions resources/lib/addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,38 @@

# pylint: disable=invalid-name
plugin = Plugin()
kodi = KodiWrapper(globals())
glob = globals()


@plugin.route('/')
def main_menu():
''' The VRT NU plugin main menu '''
from vrtplayer import VRTPlayer
kodi = KodiWrapper(glob)
VRTPlayer(kodi).show_main_menu()


@plugin.route('/cache/delete')
@plugin.route('/cache/delete/<cache_file>')
def delete_cache(cache_file='*.json'):
''' The API interface to delete caches '''
kodi = KodiWrapper(glob)
kodi.refresh_caches(cache_file=cache_file)


@plugin.route('/tokens/delete')
def delete_tokens():
''' The API interface to delete all VRT tokens '''
from tokenresolver import TokenResolver
kodi = KodiWrapper(glob)
TokenResolver(kodi).delete_tokens()


@plugin.route('/follow/<program>/<title>')
def follow(program, title):
''' The API interface to follow a program used by the context menu '''
from favorites import Favorites
kodi = KodiWrapper(glob)
Favorites(kodi).follow(program=program, title=to_unicode(unquote_plus(from_unicode(title))))


Expand All @@ -51,41 +55,47 @@ def unfollow(program, title):
''' The API interface to unfollow a program used by the context menu '''
move_down = bool(plugin.args.get('move_down'))
from favorites import Favorites
kodi = KodiWrapper(glob)
Favorites(kodi).unfollow(program=program, title=to_unicode(unquote_plus(from_unicode(title))), move_down=move_down)


@plugin.route('/watchlater/<path:url>/<uuid>/<title>')
def watchlater(uuid, title, url):
''' The API interface to watch an episode used by the context menu '''
from resumepoints import ResumePoints
kodi = KodiWrapper(glob)
ResumePoints(kodi).watchlater(uuid=uuid, title=to_unicode(unquote_plus(from_unicode(title))), url=url)


@plugin.route('/unwatchlater/<path:url>/<uuid>/<title>')
def unwatchlater(uuid, title, url):
''' The API interface to unwatch an episode used by the context menu '''
from resumepoints import ResumePoints
kodi = KodiWrapper(glob)
ResumePoints(kodi).unwatchlater(uuid=uuid, title=to_unicode(unquote_plus(from_unicode(title))), url=url)


@plugin.route('/favorites')
def favorites_menu():
''' The My favorites menu '''
from vrtplayer import VRTPlayer
kodi = KodiWrapper(glob)
VRTPlayer(kodi).show_favorites_menu()


@plugin.route('/favorites/programs')
def favorites_programs():
''' The favorites 'My programs' listing '''
from vrtplayer import VRTPlayer
kodi = KodiWrapper(glob)
VRTPlayer(kodi).show_tvshow_menu(use_favorites=True)


@plugin.route('/favorites/docu')
def favorites_docu():
''' The favorites docu listing '''
from vrtplayer import VRTPlayer
kodi = KodiWrapper(glob)
VRTPlayer(kodi).show_favorites_docu_menu()


Expand All @@ -94,6 +104,7 @@ def favorites_docu():
def favorites_recent(page=1):
''' The favorites recent listing '''
from vrtplayer import VRTPlayer
kodi = KodiWrapper(glob)
VRTPlayer(kodi).show_recent_menu(page=page, use_favorites=True)


Expand All @@ -102,13 +113,15 @@ def favorites_recent(page=1):
def favorites_offline(page=1):
''' The favorites offline listing '''
from vrtplayer import VRTPlayer
kodi = KodiWrapper(glob)
VRTPlayer(kodi).show_offline_menu(page=page, use_favorites=True)


@plugin.route('/favorites/refresh')
def favorites_refresh():
''' The API interface to refresh the favorites cache '''
from favorites import Favorites
kodi = KodiWrapper(glob)
Favorites(kodi).refresh(ttl=0)
kodi.show_notification(message=kodi.localize(30982))

Expand All @@ -117,20 +130,23 @@ def favorites_refresh():
def favorites_manage():
''' The API interface to manage your favorites '''
from favorites import Favorites
kodi = KodiWrapper(glob)
Favorites(kodi).manage()


@plugin.route('/resumepoints/continue')
def resumepoints_continue():
''' The resumepoints continue listing '''
from vrtplayer import VRTPlayer
kodi = KodiWrapper(glob)
VRTPlayer(kodi).show_continue_menu(page=1)


@plugin.route('/resumepoints/refresh')
def resumepoints_refresh():
''' The API interface to refresh the resumepoints cache '''
from resumepoints import ResumePoints
kodi = KodiWrapper(glob)
ResumePoints(kodi).refresh(ttl=0)
kodi.show_notification(message=kodi.localize(30983))

Expand All @@ -139,6 +155,7 @@ def resumepoints_refresh():
def resumepoints_watchlater():
''' The resumepoints watchlater listing '''
from vrtplayer import VRTPlayer
kodi = KodiWrapper(glob)
VRTPlayer(kodi).show_watchlater_menu(page=1)


Expand All @@ -148,6 +165,7 @@ def resumepoints_watchlater():
def programs(program=None, season=None):
''' The Programs / Seasons / Episodes listing '''
from vrtplayer import VRTPlayer
kodi = KodiWrapper(glob)
if program:
VRTPlayer(kodi).show_episodes_menu(program=program, season=season)
else:
Expand All @@ -159,6 +177,7 @@ def programs(program=None, season=None):
def categories(category=None):
''' The categories menu and listing '''
from vrtplayer import VRTPlayer
kodi = KodiWrapper(glob)
VRTPlayer(kodi).show_category_menu(category=category)


Expand All @@ -167,13 +186,15 @@ def categories(category=None):
def channels(channel=None):
''' The channels menu and listing '''
from vrtplayer import VRTPlayer
kodi = KodiWrapper(glob)
VRTPlayer(kodi).show_channels_menu(channel=channel)


@plugin.route('/livetv')
def livetv():
''' The livetv menu '''
from vrtplayer import VRTPlayer
kodi = KodiWrapper(glob)
VRTPlayer(kodi).show_livetv_menu()


Expand All @@ -182,6 +203,7 @@ def livetv():
def recent(page=1):
''' The most recent items listing '''
from vrtplayer import VRTPlayer
kodi = KodiWrapper(glob)
VRTPlayer(kodi).show_recent_menu(page=page)


Expand All @@ -190,6 +212,7 @@ def recent(page=1):
def offline(page=1):
''' The soon offline listing '''
from vrtplayer import VRTPlayer
kodi = KodiWrapper(glob)
VRTPlayer(kodi).show_offline_menu(page=page)


Expand All @@ -198,6 +221,7 @@ def offline(page=1):
def featured(feature=None):
''' The featured menu and listing '''
from vrtplayer import VRTPlayer
kodi = KodiWrapper(glob)
VRTPlayer(kodi).show_featured_menu(feature=feature)


Expand All @@ -208,6 +232,7 @@ def featured(feature=None):
def tvguide(date=None, channel=None):
''' The TV guide menu and listings by date '''
from tvguide import TVGuide
kodi = KodiWrapper(glob)
TVGuide(kodi).show_tvguide(date=date, channel=channel)


Expand All @@ -217,34 +242,39 @@ def tvguide(date=None, channel=None):
def tvguide_channel(channel=None, date=None):
''' The TV guide menu and listings by channel '''
from tvguide import TVGuide
kodi = KodiWrapper(glob)
TVGuide(kodi).show_tvguide(channel=channel, date=date)


@plugin.route('/search')
def search():
''' The Search menu and history '''
from search import Search
kodi = KodiWrapper(glob)
Search(kodi).search_menu()


@plugin.route('/search/clear')
def clear_search():
''' Clear the search history '''
from search import Search
kodi = KodiWrapper(glob)
Search(kodi).clear()


@plugin.route('/search/add/<keywords>')
def add_search(keywords):
''' Add to search history '''
from search import Search
kodi = KodiWrapper(glob)
Search(kodi).add(keywords)


@plugin.route('/search/remove/<keywords>')
def remove_search(keywords):
''' Remove from search history '''
from search import Search
kodi = KodiWrapper(glob)
Search(kodi).remove(keywords)


Expand All @@ -254,6 +284,7 @@ def remove_search(keywords):
def search_query(keywords=None, page=1):
''' The Search interface and query listing '''
from search import Search
kodi = KodiWrapper(glob)
Search(kodi).search(keywords=keywords, page=page)


Expand All @@ -262,27 +293,31 @@ def search_query(keywords=None, page=1):
def play_id(video_id, publication_id=None):
''' The API interface to play a video by video_id and/or publication_id '''
from vrtplayer import VRTPlayer
kodi = KodiWrapper(glob)
VRTPlayer(kodi).play(dict(video_id=video_id, publication_id=publication_id))


@plugin.route('/play/url/<path:video_url>')
def play_url(video_url):
''' The API interface to play a video by using a URL '''
from vrtplayer import VRTPlayer
kodi = KodiWrapper(glob)
VRTPlayer(kodi).play(dict(video_url=video_url))


@plugin.route('/play/latest/<program>')
def play_latest(program):
''' The API interface to play the latest episode of a program '''
from vrtplayer import VRTPlayer
kodi = KodiWrapper(glob)
VRTPlayer(kodi).play_latest_episode(program=program)


@plugin.route('/play/whatson/<whatson_id>')
def play_whatson(whatson_id):
''' The API interface to play a video by whatson_id '''
from vrtplayer import VRTPlayer
kodi = KodiWrapper(glob)
VRTPlayer(kodi).play_whatson(whatson_id=whatson_id)


Expand All @@ -291,10 +326,13 @@ def play_whatson(whatson_id):
def play_by_air_date(channel, start_date, end_date=None):
''' The API interface to play an episode of a program given the channel and the air date in iso format (2019-07-06T19:35:00) '''
from vrtplayer import VRTPlayer
kodi = KodiWrapper(glob)
VRTPlayer(kodi).play_episode_by_air_date(channel, start_date, end_date)


def run(argv):
def run():
''' Addon entry point from wrapper '''
kodi.log_access(argv[0])
plugin.run(argv)
import sys
kodi = KodiWrapper(glob)
kodi.log_access(sys.argv[0])
plugin.run(sys.argv)
3 changes: 1 addition & 2 deletions resources/lib/addon_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
''' This is the actual VRT NU video plugin entry point '''

from __future__ import absolute_import, division, unicode_literals
import sys
from addon import run
run(sys.argv)
run()
4 changes: 3 additions & 1 deletion test/test_apihelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@

from __future__ import absolute_import, division, print_function, unicode_literals
import unittest
from addon import kodi
from addon import glob
from apihelper import ApiHelper
from data import CHANNELS
from favorites import Favorites
from kodiwrapper import KodiWrapper
from resumepoints import ResumePoints
from xbmcextra import kodi_to_ansi

Expand All @@ -21,6 +22,7 @@

class ApiHelperTests(unittest.TestCase):

kodi = KodiWrapper(glob)
_favorites = Favorites(kodi)
_resumepoints = ResumePoints(kodi)
_apihelper = ApiHelper(kodi, _favorites, _resumepoints)
Expand Down
4 changes: 3 additions & 1 deletion test/test_favorites.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
from __future__ import absolute_import, division, print_function, unicode_literals
import unittest
from random import shuffle
from addon import kodi
from addon import glob
from apihelper import ApiHelper
from favorites import Favorites
from kodiwrapper import KodiWrapper
from resumepoints import ResumePoints

xbmc = __import__('xbmc')
Expand All @@ -24,6 +25,7 @@

class TestFavorites(unittest.TestCase):

kodi = KodiWrapper(glob)
_favorites = Favorites(kodi)
_resumepoints = ResumePoints(kodi)
_apihelper = ApiHelper(kodi, _favorites, _resumepoints)
Expand Down
4 changes: 3 additions & 1 deletion test/test_resumepoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@

from __future__ import absolute_import, division, print_function, unicode_literals
import unittest
from addon import kodi
from addon import glob
from apihelper import ApiHelper
from favorites import Favorites
from kodiwrapper import KodiWrapper
from resumepoints import ResumePoints

xbmc = __import__('xbmc')
Expand All @@ -23,6 +24,7 @@

class TestResumePoints(unittest.TestCase):

kodi = KodiWrapper(glob)
_favorites = Favorites(kodi)
_resumepoints = ResumePoints(kodi)
_apihelper = ApiHelper(kodi, _favorites, _resumepoints)
Expand Down
4 changes: 3 additions & 1 deletion test/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@

from __future__ import absolute_import, division, print_function, unicode_literals
import unittest
from addon import kodi
from addon import glob
from apihelper import ApiHelper
from favorites import Favorites
from kodiwrapper import KodiWrapper
from resumepoints import ResumePoints

xbmc = __import__('xbmc')
Expand All @@ -20,6 +21,7 @@

class TestSearch(unittest.TestCase):

kodi = KodiWrapper(glob)
_favorites = Favorites(kodi)
_resumepoints = ResumePoints(kodi)
_apihelper = ApiHelper(kodi, _favorites, _resumepoints)
Expand Down
Loading

0 comments on commit f0451c7

Please sign in to comment.