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 1e04361 commit 9091cc2
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 39 deletions.
78 changes: 41 additions & 37 deletions addon.xml
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="plugin.video.vrt.nu" name="VRT NU" version="2.4.0" provider-name="Martijn Moreel, dagwieers">
<requires>
<import addon="resource.images.studios.white" version="0.0.22"/>
<import addon="script.module.beautifulsoup4" version="4.6.2"/>
<import addon="script.module.dateutil" version="2.8.0"/>
<import addon="script.module.inputstreamhelper" version="0.4.3"/>
<import addon="script.module.routing" version="0.2.3"/>
<import addon="xbmc.python" version="2.25.0"/>
</requires>
<extension point="xbmc.python.pluginsource" library="resources/lib/addon_entry.py">
<provides>video</provides>
</extension>
<extension point="xbmc.service" library="resources/lib/service_entry.py"/>
<extension point="xbmc.addon.metadata">
<summary lang="en_GB">Watch videos from VRT NU</summary>
<description lang="en_GB">VRT NU is the video-on-demand platform of the Flemish public broadcaster (VRT).
<requires>
<import addon="resource.images.studios.white" version="0.0.22"/>
<import addon="script.module.beautifulsoup4" version="4.6.2"/>
<import addon="script.module.dateutil" version="2.8.0"/>
<import addon="script.module.inputstreamhelper" version="0.4.3"/>
<import addon="script.module.routing" version="0.2.3"/>
<import addon="xbmc.python" version="2.25.0"/>
</requires>
<extension point="xbmc.python.pluginsource" library="resources/lib/addon_entry.py">
<provides>video</provides>
<medialibraryscanpath content="movies">library/docu</medialibraryscanpath>
<medialibraryscanpath content="movies">library/movies</medialibraryscanpath>
<medialibraryscanpath content="movies">library/music</medialibraryscanpath>
<medialibraryscanpath content="tvshows">library/tvshows</medialibraryscanpath>
</extension>
<extension point="xbmc.service" library="resources/lib/service_entry.py"/>
<extension point="xbmc.addon.metadata">
<summary lang="en_GB">Watch videos from VRT NU</summary>
<description lang="en_GB">VRT NU is the video-on-demand platform of the Flemish public broadcaster (VRT).

- Track the programs you like
- List all videos alphabetically by program, category, channel or feature
Expand All @@ -23,9 +27,9 @@
- Browse the online TV guides or search VRT NU

[I]The VRT NU add-on is not endorsed by VRT, and is provided 'as is' without any warranty of any kind.[/I]</description>
<disclaimer lang="en_GB">The VRT NU add-on is not endorsed by VRT, and is provided 'as is' without any warranty of any kind.</disclaimer>
<summary lang="nl_NL">VRT NU videos bekijken.</summary>
<description lang="nl_NL">VRT NU is het video-on-demand platform van de Vlaamse publieke omroep (VRT).
<disclaimer lang="en_GB">The VRT NU add-on is not endorsed by VRT, and is provided 'as is' without any warranty of any kind.</disclaimer>
<summary lang="nl_NL">VRT NU videos bekijken.</summary>
<description lang="nl_NL">VRT NU is het video-on-demand platform van de Vlaamse publieke omroep (VRT).

- Volg je favoriete tv-programma's
- Raadpleeg video's op basis van programma, categorie, kanaal of feature
Expand All @@ -34,14 +38,14 @@
- Doorblader de online tv-gids of doorzoek VRT NU

[I]Deze VRT NU add-on wordt niet ondersteund door de VRT, en wordt aangeboden 'as is', zonder enige garantie.[/I]</description>
<disclaimer lang="nl_NL">Deze VRT NU add-on wordt niet ondersteund door de VRT, en wordt aangeboden 'as is', zonder enige garantie.</disclaimer>
<language>en nl</language>
<platform>all</platform>
<license>GPL-3.0-only</license>
<forum>https://www.facebook.com/kodivrtnu/</forum>
<website>https://github.com/add-ons/plugin.video.vrt.nu/wiki</website>
<source>https://github.com/add-ons/plugin.video.vrt.nu</source>
<news>
<disclaimer lang="nl_NL">Deze VRT NU add-on wordt niet ondersteund door de VRT, en wordt aangeboden 'as is', zonder enige garantie.</disclaimer>
<language>en nl</language>
<platform>all</platform>
<license>GPL-3.0-only</license>
<forum>https://www.facebook.com/kodivrtnu/</forum>
<website>https://github.com/add-ons/plugin.video.vrt.nu/wiki</website>
<source>https://github.com/add-ons/plugin.video.vrt.nu</source>
<news>
v2.4.0 (2020-07-18)
- Show error messages when connections fail
- Improve user authentication cache
Expand Down Expand Up @@ -80,15 +84,15 @@ v2.3.1 (2020-01-14)
- Small fix for livestreams
- Improvements to metadata handling specific to Kodi rendering
- Support multiple YouTube links per channel
</news>
<assets>
<icon>resources/media/icon.png</icon>
<fanart>resources/media/fanart.png</fanart>
<screenshot>resources/media/screenshot01.jpg</screenshot>
<screenshot>resources/media/screenshot02.jpg</screenshot>
<screenshot>resources/media/screenshot03.jpg</screenshot>
<screenshot>resources/media/screenshot04.jpg</screenshot>
</assets>
<reuselanguageinvoker>true</reuselanguageinvoker>
</extension>
</news>
<assets>
<icon>resources/media/icon.png</icon>
<fanart>resources/media/fanart.png</fanart>
<screenshot>resources/media/screenshot01.jpg</screenshot>
<screenshot>resources/media/screenshot02.jpg</screenshot>
<screenshot>resources/media/screenshot03.jpg</screenshot>
<screenshot>resources/media/screenshot04.jpg</screenshot>
</assets>
<reuselanguageinvoker>true</reuselanguageinvoker>
</extension>
</addon>
32 changes: 32 additions & 0 deletions resources/lib/addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,38 @@ def iptv_epg():
IPTVManager(port).send_epg()


@plugin.route('/library/docu')
def library_docu():
"""Show docu listitems to be used as a Kodi source"""
from vrtplayer import VRTPlayer
VRTPlayer().show_favorites_docu_menu()


@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/music')
def library_music():
"""Show music listitems to be used as a Kodi source"""
from vrtplayer import VRTPlayer
VRTPlayer().show_favorites_music_menu()


@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
9 changes: 8 additions & 1 deletion resources/lib/apihelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +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
9 changes: 8 additions & 1 deletion resources/lib/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,15 @@ def get_properties(self, api_data):
"""Get properties from single item json api data"""
properties = {}

url = reformat_url(api_data.get('url', ''), 'medium')

# Only fill in properties when using VRT NU resumepoints because setting resumetime/totaltime breaks standard Kodi watched status
if self._resumepoints.is_activated():
asset_id = self.get_asset_id(api_data)
if asset_id:
# We need to ensure forward slashes are quoted
program_title = to_unicode(quote_plus(from_unicode(api_data.get('program'))))

url = reformat_url(api_data.get('url', ''), 'medium')
properties.update(asset_id=asset_id, url=url, title=program_title)

position = self._resumepoints.get_position(asset_id)
Expand All @@ -214,6 +215,11 @@ def get_properties(self, api_data):
if year:
properties['year'] = year

from hashlib import md5
message = md5()
message.update(url.encode('ascii'))
properties['hash'] = message.hexdigest().upper()

return properties

@staticmethod
Expand Down Expand Up @@ -652,6 +658,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

0 comments on commit 9091cc2

Please sign in to comment.