Skip to content

Commit

Permalink
Add Kodi library support
Browse files Browse the repository at this point in the history
This adds support for adding VRT NU as a Kodi library source.

To use this, add the following Video sources to your Kodi:

- VRT NU - Movies
  - location: plugin://plugin.video.vrt.nu/library/movies
  - type: Movies
  - provider: Local Information only
- VRT NU - TV shows
  - location: plugin://plugin.video.vrt.nu/library/tvshows
  - type: TV shows
  - provider: Local Information only

Then update your library to get VRT NU Movies and TV shows to show up in
the standard Kodi library.
  • Loading branch information
dagwieers committed Sep 28, 2020
1 parent bee5bd9 commit c718c39
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 2 deletions.
2 changes: 2 additions & 0 deletions addon.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
</requires>
<extension point="xbmc.python.pluginsource" library="resources/lib/addon_entry.py">
<provides>video</provides>
<medialibraryscanpath content="movies">library/movies</medialibraryscanpath>
<medialibraryscanpath content="tvshows">library/tvshows</medialibraryscanpath>
</extension>
<extension point="xbmc.service" library="resources/lib/service_entry.py"/>
<extension point="xbmc.addon.metadata">
Expand Down
18 changes: 18 additions & 0 deletions resources/lib/addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,24 @@ def iptv_epg():
IPTVManager(port).send_epg()


@plugin.route('/library/movies')
def library_movies():
"""Show movie listitems to be used as a Kodi source"""
from vrtplayer import VRTPlayer
VRTPlayer().show_library_movies()


@plugin.route('/library/tvshows')
@plugin.route('/library/tvshows/<program>')
def library_tvshows(program=None):
"""Show tvshow listitems to be used as a Kodi source"""
from vrtplayer import VRTPlayer
if program:
VRTPlayer().show_episodes_menu(program=program, season='allseasons')
else:
VRTPlayer().show_library_tvshows()


@plugin.route('/update/repos')
def update_repos():
"""Force an update of the repositories"""
Expand Down
10 changes: 9 additions & 1 deletion resources/lib/apihelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,23 @@ def list_tvshows(self, category=None, channel=None, feature=None, use_favorites=

def tvshow_to_listitem(self, tvshow, program, cache_file):
"""Return a ListItem based on a Suggests API result"""
from addon import plugin

label = self._metadata.get_label(tvshow)

if program:
context_menu, favorite_marker, _ = self._metadata.get_context_menu(tvshow, program, cache_file)
label += favorite_marker

# Support Kodi library source scanning
if plugin.path.startswith('/library'):
path = url_for('library_tvshows', program=program)
else:
path = url_for('programs', program=program)

return TitleItem(
label=label,
path=url_for('programs', program=program),
path=path,
art_dict=self._metadata.get_art(tvshow),
info_dict=self._metadata.get_info_labels(tvshow),
context_menu=context_menu,
Expand Down
8 changes: 8 additions & 0 deletions resources/lib/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,13 @@ def get_properties(self, api_data):
if year:
properties['year'] = year

# Poor man's implementation, use thumbnail and episode_count to detect change
from hashlib import md5
message = md5()
message.update(api_data.get('thumbnail', '').encode('ascii'))
message.update(api_data.get(str('episode_count', 0)))
properties['hash'] = message.hexdigest().upper()

return properties

@staticmethod
Expand Down Expand Up @@ -652,6 +659,7 @@ def get_info_labels(self, api_data, season=False, date=None, channel=None):
# VRT NU Suggest API
if api_data.get('type') == 'program':
info_labels = dict(
title=self.get_tvshowtitle(api_data),
tvshowtitle=self.get_tvshowtitle(api_data),
plot=self.get_plot(api_data),
mediatype=self.get_mediatype(api_data, season=season),
Expand Down
18 changes: 18 additions & 0 deletions resources/lib/vrtplayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,24 @@ def show_favorites_music_menu(self):
episode_items, sort, ascending, content = self._apihelper.list_episodes(category='muziek', season='allseasons', programtype='oneoff')
show_listing(episode_items, category=30046, sort=sort, ascending=ascending, content=content, cache=False)

def show_library_movies(self):
"""Show movie listitems to be used as a Kodi source"""
docu_items = []
music_items = []
if get_setting_bool('library_include_docu', default=True):
docu_items, _, _, _ = self._apihelper.list_episodes(category='docu', season='allseasons', programtype='oneoff')
if get_setting_bool('library_include_music', default=True):
music_items, _, _, _ = self._apihelper.list_episodes(category='muziek', season='allseasons', programtype='oneoff')
movie_items, sort, _, _ = self._apihelper.list_episodes(category='films', season='allseasons', programtype='oneoff')
show_listing(movie_items + docu_items + music_items, sort=sort, content='movies')

def show_library_tvshows(self):
"""Show tvshow listitems to be used as a Kodi source"""
self._favorites.refresh(ttl=ttl('direct'))
self._resumepoints.refresh(ttl=ttl('direct'))
tvshow_items = self._apihelper.list_tvshows(use_favorites=get_setting_bool('library_use_favorites', default=True))
show_listing(tvshow_items, sort='label', content='tvshows')

def show_tvshow_menu(self, use_favorites=False):
"""The VRT NU add-on 'All programs' listing menu"""
# My favorites menus may need more up-to-date favorites
Expand Down
12 changes: 12 additions & 0 deletions tests/test_routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,18 @@ def test_play_whatson_id(self):
addon.run(['plugin://plugin.video.vrt.nu/play/whatson/490431755527', '0', ''])
self.assertEqual(plugin.url_for(addon.play_whatson_id, whatson_id='490431755527'), 'plugin://plugin.video.vrt.nu/play/whatson/490431755527')

def test_library_movies(self):
"""Library Movies scan: /library/movies"""
addon.run(['plugin://plugin.video.vrt.nu/library/movies', '0', ''])
self.assertEqual(plugin.url_for(addon.library_movies), 'plugin://plugin.video.vrt.nu/library/movies')

def test_library_tvshows(self):
"""Library Movies scan: /library/tvshows"""
addon.run(['plugin://plugin.video.vrt.nu/library/tvshows', '0', ''])
self.assertEqual(plugin.url_for(addon.library_tvshows), 'plugin://plugin.video.vrt.nu/library/tvshows')
addon.run(['plugin://plugin.video.vrt.nu/library/tvshows/het-journaal', '0', ''])
self.assertEqual(plugin.url_for(addon.library_tvshows, program='het-journaal'), 'plugin://plugin.video.vrt.nu/library/tvshows/het-journaal')

def test_update_repos(self):
"""Update repositories: /update/repos"""
addon.run(['plugin://plugin.video.vrt.nu/update/repos', '0', ''])
Expand Down
5 changes: 4 additions & 1 deletion tests/userdata/addon_settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@
"een": "true",
"httpcachettldirect": "1",
"httpcachettlindirect": "5",
"itemsperpage": "20",
"ketnet": "false",
"ketnet-jr": "false",
"klara": "true",
"itemsperpage": "20",
"library_include_docu": "true",
"library_include_music": "true",
"library_use_favorites": "true",
"max_bandwidth": "10000000",
"max_log_level": "3",
"mnm": "true",
Expand Down

0 comments on commit c718c39

Please sign in to comment.