From 1a541552d7831765c5fba3a880643be97fd2c5d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Arnauts?= Date: Mon, 15 Feb 2021 13:42:10 +0100 Subject: [PATCH] Remove background metadata downloading (#74) * Don't download metadata in the background anymore * Remove warning logging --- .../resource.language.en_gb/strings.po | 36 ---------- .../resource.language.nl_nl/strings.po | 36 ---------- resources/lib/addon.py | 14 ---- resources/lib/modules/metadata.py | 69 ------------------- resources/lib/service.py | 38 ---------- resources/lib/viervijfzes/aws/cognito_sync.py | 2 - resources/lib/viervijfzes/content.py | 2 +- resources/settings.xml | 7 -- tests/test_routing.py | 3 - 9 files changed, 1 insertion(+), 206 deletions(-) delete mode 100644 resources/lib/modules/metadata.py diff --git a/resources/language/resource.language.en_gb/strings.po b/resources/language/resource.language.en_gb/strings.po index 1a4b288..064ff55 100644 --- a/resources/language/resource.language.en_gb/strings.po +++ b/resources/language/resource.language.en_gb/strings.po @@ -152,18 +152,6 @@ msgctxt "#30713" msgid "The requested video was not found in the guide." msgstr "" -msgctxt "#30714" -msgid "Local metadata is cleared." -msgstr "" - -msgctxt "#30715" -msgid "Updating metadata..." -msgstr "" - -msgctxt "#30716" -msgid "Updating metadata ({index}/{total})..." -msgstr "" - msgctxt "#30717" msgid "This program is not available in the catalogue." msgstr "" @@ -180,10 +168,6 @@ msgctxt "#30720" msgid "This video is not available abroad." msgstr "" -msgctxt "#30721" -msgid "Clearing local metadata failed." -msgstr "" - ### SETTINGS msgctxt "#30800" @@ -202,26 +186,6 @@ msgctxt "#30803" msgid "Password" msgstr "" -msgctxt "#30820" -msgid "Interface" -msgstr "" - -msgctxt "#30821" -msgid "Metadata" -msgstr "" - -msgctxt "#30822" -msgid "Periodically refresh metadata in the background" -msgstr "" - -msgctxt "#30823" -msgid "Update local metadata now…" -msgstr "De lokale metadata nu vernieuwen…" - -msgctxt "#30824" -msgid "Clear local metadata…" -msgstr "De lokale metadata verwijderen…" - msgctxt "#30840" msgid "Integration" msgstr "" diff --git a/resources/language/resource.language.nl_nl/strings.po b/resources/language/resource.language.nl_nl/strings.po index 5613e72..8610ed3 100644 --- a/resources/language/resource.language.nl_nl/strings.po +++ b/resources/language/resource.language.nl_nl/strings.po @@ -153,18 +153,6 @@ msgctxt "#30713" msgid "The requested video was not found in the guide." msgstr "De gevraagde video werd niet gevonden in de tv-gids." -msgctxt "#30714" -msgid "Local metadata is cleared." -msgstr "De lokale metadata is verwijderd." - -msgctxt "#30715" -msgid "Updating metadata..." -msgstr "Vernieuwen metadata..." - -msgctxt "#30716" -msgid "Updating metadata ({index}/{total})..." -msgstr "Vernieuwen metadata ({index}/{total})..." - msgctxt "#30717" msgid "This program is not available in the catalogue." msgstr "Dit programma is niet beschikbaar in de catalogus." @@ -181,10 +169,6 @@ msgctxt "#30720" msgid "This video is not available abroad." msgstr "Deze video is niet beschikbaar in het buitenland." -msgctxt "#30721" -msgid "Clearing local metadata failed." -msgstr "Wissen van lokale metadata is mislukt." - ### SETTINGS msgctxt "#30800" @@ -203,26 +187,6 @@ msgctxt "#30803" msgid "Password" msgstr "Wachtwoord" -msgctxt "#30820" -msgid "Interface" -msgstr "Interface" - -msgctxt "#30821" -msgid "Metadata" -msgstr "Metadata" - -msgctxt "#30822" -msgid "Periodically refresh metadata in the background" -msgstr "Vernieuw de lokale metdata automatisch in de achtergrond" - -msgctxt "#30823" -msgid "Update local metadata now…" -msgstr "De lokale metadata nu vernieuwen…" - -msgctxt "#30824" -msgid "Clear local metadata…" -msgstr "De lokale metadata verwijderen…" - msgctxt "#30840" msgid "Integration" msgstr "Integratie" diff --git a/resources/lib/addon.py b/resources/lib/addon.py index e0d6afd..fbd3e80 100644 --- a/resources/lib/addon.py +++ b/resources/lib/addon.py @@ -159,20 +159,6 @@ def play_from_page(page): Player().play_from_page(unquote(page)) -@routing.route('/metadata/update') -def metadata_update(): - """ Update the metadata for the listings (called from settings) """ - from resources.lib.modules.metadata import Metadata - Metadata().update() - - -@routing.route('/metadata/clean') -def metadata_clean(): - """ Clear the metadata for the listings (called from settings) """ - from resources.lib.modules.metadata import Metadata - Metadata().clean() - - @routing.route('/iptv/channels') def iptv_channels(): """ Generate channel data for the Kodi PVR integration """ diff --git a/resources/lib/modules/metadata.py b/resources/lib/modules/metadata.py deleted file mode 100644 index 5708fc3..0000000 --- a/resources/lib/modules/metadata.py +++ /dev/null @@ -1,69 +0,0 @@ -# -*- coding: utf-8 -*- -""" Metadata module """ - -from __future__ import absolute_import, division, unicode_literals - -import os - -from resources.lib import kodiutils -from resources.lib.viervijfzes import CHANNELS -from resources.lib.viervijfzes.content import CACHE_AUTO, CACHE_PREVENT, ContentApi, Program - - -class Metadata: - """ Code responsible for the management of the local cached metadata """ - - def __init__(self): - """ Initialise object """ - self._api = ContentApi(cache_path=kodiutils.get_cache_path()) - - def update(self): - """ Update the metadata with a foreground progress indicator """ - # Create progress indicator - progress = kodiutils.progress(message=kodiutils.localize(30715)) # Updating metadata... - - def update_status(i, total): - """ Update the progress indicator """ - progress.update(int(((i + 1) / total) * 100), - kodiutils.localize(30716, index=i + 1, total=total)) # Updating metadata ({index}/{total})... - return progress.iscanceled() - - self.fetch_metadata(callback=update_status, refresh=True) - - # Close progress indicator - progress.close() - - def fetch_metadata(self, callback=None, refresh=False): - """ Fetch the metadata for all the items in the catalog - :type callback: callable - :type refresh: bool - """ - # Fetch all items from the catalog - items = [] - for channel in list(CHANNELS): - items.extend(self._api.get_programs(channel, CACHE_PREVENT)) - count = len(items) - - # Loop over all of them and download the metadata - for index, item in enumerate(items): - if isinstance(item, Program): - self._api.get_program(item.channel, item.path, CACHE_PREVENT if refresh else CACHE_AUTO) - - # Run callback after every item - if callback and callback(index, count): - # Stop when callback returns True - return False - - return True - - @staticmethod - def clean(): - """ Clear metadata (called from settings) """ - cache_path = kodiutils.get_cache_path() - _, files = kodiutils.listdir(cache_path) - for filename in files: - if not kodiutils.delete(os.path.join(cache_path, filename)): - return kodiutils.ok_dialog(message=kodiutils.localize(30721)) # Clearing local metadata failed - - kodiutils.set_setting('metadata_last_updated', '0') - return kodiutils.ok_dialog(message=kodiutils.localize(30714)) # Local metadata is cleared diff --git a/resources/lib/service.py b/resources/lib/service.py index 67f063f..ae8cc5f 100644 --- a/resources/lib/service.py +++ b/resources/lib/service.py @@ -5,8 +5,6 @@ from __future__ import absolute_import, division, unicode_literals import hashlib import logging -import os -from time import time from xbmc import Monitor, Player, getInfoLabel @@ -31,10 +29,6 @@ class BackgroundService(Monitor): _LOGGER.debug('Service started') while not self.abortRequested(): - # Update every `update_interval` after the last update - if kodiutils.get_setting_bool('metadata_update') and int(kodiutils.get_setting('metadata_last_updated', 0)) + self.update_interval < time(): - self._update_metadata() - # Stop when abort requested if self.waitForAbort(10): break @@ -62,38 +56,6 @@ class BackgroundService(Monitor): return True return False - def _update_metadata(self): - """ Update the metadata for the listings """ - from resources.lib.modules.metadata import Metadata - - def update_status(_i, _total): - """ Allow to cancel the background job """ - return self.abortRequested() or not kodiutils.get_setting_bool('metadata_update') - - # Clear metadata that has expired for 30 days - self._remove_expired_metadata(30 * 24 * 60 * 60) - - # Fetch new metadata - success = Metadata().fetch_metadata(callback=update_status) - - # Update metadata_last_updated - if success: - kodiutils.set_setting('metadata_last_updated', str(int(time()))) - - @staticmethod - def _remove_expired_metadata(keep_expired=None): - """ Clear the cache """ - path = kodiutils.get_cache_path() - if not os.path.exists(path): - return - - now = time() - for filename in os.listdir(path): - fullpath = os.path.join(path, filename) - if keep_expired and os.stat(fullpath).st_mtime + keep_expired > now: - continue - os.unlink(fullpath) - class KodiPlayer(Player): """Communication with Kodi Player""" diff --git a/resources/lib/viervijfzes/aws/cognito_sync.py b/resources/lib/viervijfzes/aws/cognito_sync.py index 1d2ed6f..b39d20f 100644 --- a/resources/lib/viervijfzes/aws/cognito_sync.py +++ b/resources/lib/viervijfzes/aws/cognito_sync.py @@ -89,8 +89,6 @@ class CognitoSync: signed_headers + '\n' + payload_hash) - _LOGGER.warning(canonical_request) - # Step 2. Create a string to sign algorithm = 'AWS4-HMAC-SHA256' credential_scope = '%s/%s/%s/%s' % (datestamp, self.region, service, 'aws4_request') diff --git a/resources/lib/viervijfzes/content.py b/resources/lib/viervijfzes/content.py index 9d0c3c5..338b57e 100644 --- a/resources/lib/viervijfzes/content.py +++ b/resources/lib/viervijfzes/content.py @@ -208,7 +208,7 @@ class ContentApi: return data # Fetch listing from cache or update if needed - data = self._handle_cache(key=['programs'], cache_mode=cache, update=update, ttl=30 * 5) + data = self._handle_cache(key=['programs'], cache_mode=cache, update=update, ttl=5 * 60) if not data: return [] diff --git a/resources/settings.xml b/resources/settings.xml index 35309d1..0043bb6 100644 --- a/resources/settings.xml +++ b/resources/settings.xml @@ -1,17 +1,10 @@ - - - - - - - diff --git a/tests/test_routing.py b/tests/test_routing.py index 8171bf7..97c0898 100644 --- a/tests/test_routing.py +++ b/tests/test_routing.py @@ -51,9 +51,6 @@ class TestRouting(unittest.TestCase): routing.run([routing.url_for(addon.show_channel_tvguide, channel='Play4'), '0', '']) routing.run([routing.url_for(addon.show_channel_tvguide_detail, channel='Play4', date='today'), '0', '']) - # def test_metadata_update(self): - # routing.run([routing.url_for(addon.metadata_update), '0', '']) - if __name__ == '__main__': unittest.main()