diff --git a/addon.xml b/addon.xml index 45628266..6d17424a 100644 --- a/addon.xml +++ b/addon.xml @@ -10,6 +10,8 @@ video + library/movies + library/tvshows diff --git a/resources/language/resource.language.en_gb/strings.po b/resources/language/resource.language.en_gb/strings.po index 637e096e..38ef1c3e 100644 --- a/resources/language/resource.language.en_gb/strings.po +++ b/resources/language/resource.language.en_gb/strings.po @@ -745,6 +745,42 @@ msgctxt "#30835" msgid "De Warmste Week" msgstr "" +msgctxt "#30840" +msgid "Kodi Library" +msgstr "" + +msgctxt "#30841" +msgid "Indexing" +msgstr "" + +msgctxt "#30843" +msgid "Add video locations to the Kodi Library… [COLOR gray](See README.md)[/COLOR]" +msgstr "" + +msgctxt "#30845" +msgid "Index documentaries also" +msgstr "" + +msgctxt "#30847" +msgid "Index music videos also" +msgstr "" + +msgctxt "#30849" +msgid "Index only TV shows you follow" +msgstr "" + +msgctxt "#30851" +msgid "Maintenance" +msgstr "" + +msgctxt "#30853" +msgid "Refresh Library…" +msgstr "" + +msgctxt "#30855" +msgid "Clean Library…" +msgstr "" + msgctxt "#30860" msgid "Integration" msgstr "" diff --git a/resources/language/resource.language.nl_nl/strings.po b/resources/language/resource.language.nl_nl/strings.po index 632e37fa..4421c69d 100644 --- a/resources/language/resource.language.nl_nl/strings.po +++ b/resources/language/resource.language.nl_nl/strings.po @@ -745,6 +745,42 @@ msgctxt "#30835" msgid "De Warmste Week" msgstr "De Warmste Week" +msgctxt "#30840" +msgid "Kodi Library" +msgstr "Kodi-bibliotheek" + +msgctxt "#30841" +msgid "Indexing" +msgstr "Indexeren" + +msgctxt "#30843" +msgid "Add video locations to the Kodi Library… [COLOR gray](See README.md)[/COLOR]" +msgstr "Videolocaties toevoegen aan de Kodi-bibliotheek… [COLOR gray](Zie README.md)[/COLOR]" + +msgctxt "#30845" +msgid "Index documentaries also" +msgstr "Index ook documentaires" + +msgctxt "#30847" +msgid "Index music videos also" +msgstr "Indexeer ook muziek video's" + +msgctxt "#30849" +msgid "Index only TV shows you follow" +msgstr "Indexeer enkel tv-programma's die je volgt" + +msgctxt "#30851" +msgid "Maintenance" +msgstr "Onderhoud" + +msgctxt "#30853" +msgid "Refresh Library…" +msgstr "Verniew bibliotheek…" + +msgctxt "#30855" +msgid "Clean Library…" +msgstr "Bibliotheek opkuisen…" + msgctxt "#30860" msgid "Integration" msgstr "Integratie" diff --git a/resources/lib/addon.py b/resources/lib/addon.py index dade1256..4cfa9322 100644 --- a/resources/lib/addon.py +++ b/resources/lib/addon.py @@ -10,7 +10,7 @@ except ImportError: # Python 2 from urllib import unquote_plus -from kodiutils import end_of_directory, execute_builtin, get_global_setting, localize, log_access, notification, ok_dialog, refresh_caches +from kodiutils import end_of_directory, execute_builtin, get_global_setting, jsonrpc, localize, log_access, notification, ok_dialog, refresh_caches from utils import from_unicode, to_unicode plugin = Plugin() # pylint: disable=invalid-name @@ -337,6 +337,44 @@ 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/') +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('/library/configure') +def library_configure(): + """Configure the library integration""" + # There seems to be no way to add sources automatically + # → https://forum.kodi.tv/showthread.php?tid=228840 + execute_builtin('ActivateWindow(Videos,sources://video/)') + + +@plugin.route('/library/update') +def library_update(): + """Refresh the library""" + jsonrpc(method='VideoLibrary.Scan') + + +@plugin.route('/library/clean') +def library_clean(): + """Clean the library""" + jsonrpc(method='VideoLibrary.Clean') + + @plugin.route('/update/repos') def update_repos(): """Force an update of the repositories""" diff --git a/resources/lib/apihelper.py b/resources/lib/apihelper.py index 6412f123..d480158b 100644 --- a/resources/lib/apihelper.py +++ b/resources/lib/apihelper.py @@ -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, diff --git a/resources/lib/metadata.py b/resources/lib/metadata.py index deb879a1..af8ab884 100644 --- a/resources/lib/metadata.py +++ b/resources/lib/metadata.py @@ -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(str(api_data.get('episode_count', 0)).encode('ascii')) + properties['hash'] = message.hexdigest().upper() + return properties @staticmethod @@ -661,6 +668,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), diff --git a/resources/lib/vrtplayer.py b/resources/lib/vrtplayer.py index b08dd6f7..e6c12bf4 100644 --- a/resources/lib/vrtplayer.py +++ b/resources/lib/vrtplayer.py @@ -197,6 +197,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 diff --git a/resources/settings.xml b/resources/settings.xml index ebb94220..d9af0f36 100644 --- a/resources/settings.xml +++ b/resources/settings.xml @@ -51,6 +51,16 @@ + + + + + + + + + + diff --git a/tests/test_routing.py b/tests/test_routing.py index 8410a5c4..bfbc706a 100644 --- a/tests/test_routing.py +++ b/tests/test_routing.py @@ -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 TV shows 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', '']) diff --git a/tests/userdata/addon_settings.json b/tests/userdata/addon_settings.json index 4e0b4b20..769b46ff 100644 --- a/tests/userdata/addon_settings.json +++ b/tests/userdata/addon_settings.json @@ -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",