Skip to content

Commit 24217a6

Browse files
committed
Add Kodi library support
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.
1 parent 27fd834 commit 24217a6

File tree

7 files changed

+71
-2
lines changed

7 files changed

+71
-2
lines changed

addon.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
</requires>
1111
<extension point="xbmc.python.pluginsource" library="resources/lib/addon_entry.py">
1212
<provides>video</provides>
13+
<medialibraryscanpath content="movies">library/movies</medialibraryscanpath>
14+
<medialibraryscanpath content="tvshows">library/tvshows</medialibraryscanpath>
1315
</extension>
1416
<extension point="xbmc.service" library="resources/lib/service_entry.py"/>
1517
<extension point="xbmc.addon.metadata">

resources/lib/addon.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,24 @@ def iptv_epg():
337337
IPTVManager(port).send_epg()
338338

339339

340+
@plugin.route('/library/movies')
341+
def library_movies():
342+
"""Show movie listitems to be used as a Kodi source"""
343+
from vrtplayer import VRTPlayer
344+
VRTPlayer().show_library_movies()
345+
346+
347+
@plugin.route('/library/tvshows')
348+
@plugin.route('/library/tvshows/<program>')
349+
def library_tvshows(program=None):
350+
"""Show tvshow listitems to be used as a Kodi source"""
351+
from vrtplayer import VRTPlayer
352+
if program:
353+
VRTPlayer().show_episodes_menu(program=program, season='allseasons')
354+
else:
355+
VRTPlayer().show_library_tvshows()
356+
357+
340358
@plugin.route('/update/repos')
341359
def update_repos():
342360
"""Force an update of the repositories"""

resources/lib/apihelper.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,23 @@ def list_tvshows(self, category=None, channel=None, feature=None, use_favorites=
7878

7979
def tvshow_to_listitem(self, tvshow, program, cache_file):
8080
"""Return a ListItem based on a Suggests API result"""
81+
from addon import plugin
82+
8183
label = self._metadata.get_label(tvshow)
8284

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

89+
# Support Kodi library source scanning
90+
if plugin.path.startswith('/library'):
91+
path = url_for('library_tvshows', program=program)
92+
else:
93+
path = url_for('programs', program=program)
94+
8795
return TitleItem(
8896
label=label,
89-
path=url_for('programs', program=program),
97+
path=path,
9098
art_dict=self._metadata.get_art(tvshow),
9199
info_dict=self._metadata.get_info_labels(tvshow),
92100
context_menu=context_menu,

resources/lib/metadata.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,13 @@ def get_properties(self, api_data):
214214
if year:
215215
properties['year'] = year
216216

217+
# Poor man's implementation, use thumbnail and episode_count to detect change
218+
from hashlib import md5
219+
message = md5()
220+
message.update(api_data.get('thumbnail', '').encode('ascii'))
221+
message.update(str(api_data.get('episode_count', 0)).encode('ascii'))
222+
properties['hash'] = message.hexdigest().upper()
223+
217224
return properties
218225

219226
@staticmethod
@@ -661,6 +668,7 @@ def get_info_labels(self, api_data, season=False, date=None, channel=None):
661668
# VRT NU Suggest API
662669
if api_data.get('type') == 'program':
663670
info_labels = dict(
671+
title=self.get_tvshowtitle(api_data),
664672
tvshowtitle=self.get_tvshowtitle(api_data),
665673
plot=self.get_plot(api_data),
666674
mediatype=self.get_mediatype(api_data, season=season),

resources/lib/vrtplayer.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,24 @@ def show_favorites_music_menu(self):
192192
episode_items, sort, ascending, content = self._apihelper.list_episodes(category='muziek', season='allseasons', programtype='oneoff')
193193
show_listing(episode_items, category=30046, sort=sort, ascending=ascending, content=content, cache=False)
194194

195+
def show_library_movies(self):
196+
"""Show movie listitems to be used as a Kodi source"""
197+
docu_items = []
198+
music_items = []
199+
if get_setting_bool('library_include_docu', default=True):
200+
docu_items, _, _, _ = self._apihelper.list_episodes(category='docu', season='allseasons', programtype='oneoff')
201+
if get_setting_bool('library_include_music', default=True):
202+
music_items, _, _, _ = self._apihelper.list_episodes(category='muziek', season='allseasons', programtype='oneoff')
203+
movie_items, sort, _, _ = self._apihelper.list_episodes(category='films', season='allseasons', programtype='oneoff')
204+
show_listing(movie_items + docu_items + music_items, sort=sort, content='movies')
205+
206+
def show_library_tvshows(self):
207+
"""Show tvshow listitems to be used as a Kodi source"""
208+
self._favorites.refresh(ttl=ttl('direct'))
209+
self._resumepoints.refresh(ttl=ttl('direct'))
210+
tvshow_items = self._apihelper.list_tvshows(use_favorites=get_setting_bool('library_use_favorites', default=True))
211+
show_listing(tvshow_items, sort='label', content='tvshows')
212+
195213
def show_tvshow_menu(self, use_favorites=False):
196214
"""The VRT NU add-on 'All programs' listing menu"""
197215
# My favorites menus may need more up-to-date favorites

tests/test_routing.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,18 @@ def test_play_whatson_id(self):
271271
addon.run(['plugin://plugin.video.vrt.nu/play/whatson/490431755527', '0', ''])
272272
self.assertEqual(plugin.url_for(addon.play_whatson_id, whatson_id='490431755527'), 'plugin://plugin.video.vrt.nu/play/whatson/490431755527')
273273

274+
def test_library_movies(self):
275+
"""Library Movies scan: /library/movies"""
276+
addon.run(['plugin://plugin.video.vrt.nu/library/movies', '0', ''])
277+
self.assertEqual(plugin.url_for(addon.library_movies), 'plugin://plugin.video.vrt.nu/library/movies')
278+
279+
def test_library_tvshows(self):
280+
"""Library TV shows scan: /library/tvshows"""
281+
addon.run(['plugin://plugin.video.vrt.nu/library/tvshows', '0', ''])
282+
self.assertEqual(plugin.url_for(addon.library_tvshows), 'plugin://plugin.video.vrt.nu/library/tvshows')
283+
addon.run(['plugin://plugin.video.vrt.nu/library/tvshows/het-journaal', '0', ''])
284+
self.assertEqual(plugin.url_for(addon.library_tvshows, program='het-journaal'), 'plugin://plugin.video.vrt.nu/library/tvshows/het-journaal')
285+
274286
def test_update_repos(self):
275287
"""Update repositories: /update/repos"""
276288
addon.run(['plugin://plugin.video.vrt.nu/update/repos', '0', ''])

tests/userdata/addon_settings.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@
1616
"een": "true",
1717
"httpcachettldirect": "1",
1818
"httpcachettlindirect": "5",
19+
"itemsperpage": "20",
1920
"ketnet": "false",
2021
"ketnet-jr": "false",
2122
"klara": "true",
22-
"itemsperpage": "20",
23+
"library_include_docu": "true",
24+
"library_include_music": "true",
25+
"library_use_favorites": "true",
2326
"max_bandwidth": "10000000",
2427
"max_log_level": "3",
2528
"mnm": "true",

0 commit comments

Comments
 (0)