From 6ed3b1097bf7d52a9e35b711f1518653d037709e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Arnauts?= Date: Fri, 19 Jun 2020 15:20:20 +0200 Subject: [PATCH] Add Clean Metadata setting (#34) --- .../resource.language.en_gb/strings.po | 24 +++++++++++------ .../resource.language.nl_nl/strings.po | 26 ++++++++++++------- resources/lib/addon.py | 7 +++++ resources/lib/kodiutils.py | 18 +++++++++++-- resources/lib/modules/metadata.py | 18 ++++++++++--- resources/lib/viervijfzes/content.py | 3 ++- resources/settings.xml | 11 ++++---- 7 files changed, 79 insertions(+), 28 deletions(-) diff --git a/resources/language/resource.language.en_gb/strings.po b/resources/language/resource.language.en_gb/strings.po index 06d2225..4b72ac8 100644 --- a/resources/language/resource.language.en_gb/strings.po +++ b/resources/language/resource.language.en_gb/strings.po @@ -136,8 +136,12 @@ 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" +msgid "Updating metadata..." msgstr "" msgctxt "#30716" @@ -162,11 +166,11 @@ msgctxt "#30801" msgid "Credentials" msgstr "" -msgctxt "#30803" +msgctxt "#30802" msgid "Email address" msgstr "" -msgctxt "#30805" +msgctxt "#30803" msgid "Password" msgstr "" @@ -174,17 +178,21 @@ msgctxt "#30820" msgid "Interface" msgstr "" -msgctxt "#30827" +msgctxt "#30821" msgid "Metadata" msgstr "" -msgctxt "#30829" +msgctxt "#30822" msgid "Periodically refresh metadata in the background" msgstr "" -msgctxt "#30831" -msgid "Update local metadata now" -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 "#30880" msgid "Expert" diff --git a/resources/language/resource.language.nl_nl/strings.po b/resources/language/resource.language.nl_nl/strings.po index 1dbc5bd..a2d1929 100644 --- a/resources/language/resource.language.nl_nl/strings.po +++ b/resources/language/resource.language.nl_nl/strings.po @@ -137,9 +137,13 @@ 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" +msgid "Updating metadata..." +msgstr "Vernieuwen metadata..." msgctxt "#30716" msgid "Updating metadata ({index}/{total})..." @@ -164,11 +168,11 @@ msgctxt "#30801" msgid "Credentials" msgstr "Inloggegevens" -msgctxt "#30803" +msgctxt "#30802" msgid "Email address" msgstr "E-mailadres" -msgctxt "#30805" +msgctxt "#30803" msgid "Password" msgstr "Wachtwoord" @@ -176,17 +180,21 @@ msgctxt "#30820" msgid "Interface" msgstr "Interface" -msgctxt "#30827" +msgctxt "#30821" msgid "Metadata" msgstr "Metadata" -msgctxt "#30829" +msgctxt "#30822" msgid "Periodically refresh metadata in the background" msgstr "Vernieuw de lokale metdata automatisch in de achtergrond" -msgctxt "#30831" -msgid "Update local metadata now" -msgstr "De lokale metadata nu vernieuwen" +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 "#30880" msgid "Expert" diff --git a/resources/lib/addon.py b/resources/lib/addon.py index ac1b853..9b11b96 100644 --- a/resources/lib/addon.py +++ b/resources/lib/addon.py @@ -146,6 +146,13 @@ def metadata_update(): 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/kodiutils.py b/resources/lib/kodiutils.py index b694a8d..156b8a2 100644 --- a/resources/lib/kodiutils.py +++ b/resources/lib/kodiutils.py @@ -30,7 +30,8 @@ _LOGGER = logging.getLogger('kodiutils') class TitleItem: """ This helper object holds all information to be used with Kodi xbmc's ListItem object """ - def __init__(self, title, path=None, art_dict=None, info_dict=None, prop_dict=None, stream_dict=None, context_menu=None, subtitles_path=None, + def __init__(self, title, path=None, art_dict=None, info_dict=None, prop_dict=None, stream_dict=None, + context_menu=None, subtitles_path=None, is_playable=False): """ The constructor for the TitleItem class :type title: str @@ -256,7 +257,8 @@ def multiselect(heading='', options=None, autoclose=0, preselect=None, use_detai from xbmcgui import Dialog if not heading: heading = addon_name() - return Dialog().multiselect(heading=heading, options=options, autoclose=autoclose, preselect=preselect, useDetails=use_details) + return Dialog().multiselect(heading=heading, options=options, autoclose=autoclose, preselect=preselect, + useDetails=use_details) class progress(xbmcgui.DialogProgress, object): # pylint: disable=invalid-name,useless-object-inheritance @@ -503,3 +505,15 @@ def jsonrpc(*args, **kwargs): if kwargs.get('jsonrpc') is None: kwargs.update(jsonrpc='2.0') return loads(xbmc.executeJSONRPC(dumps(kwargs))) + + +def listdir(path): + """Return all files in a directory (using xbmcvfs)""" + from xbmcvfs import listdir as vfslistdir + return vfslistdir(path) + + +def delete(path): + """Remove a file (using xbmcvfs)""" + from xbmcvfs import delete as vfsdelete + return vfsdelete(path) diff --git a/resources/lib/modules/metadata.py b/resources/lib/modules/metadata.py index 866c359..d7e2f1a 100644 --- a/resources/lib/modules/metadata.py +++ b/resources/lib/modules/metadata.py @@ -18,11 +18,12 @@ class Metadata: def update(self): """ Update the metadata with a foreground progress indicator """ # Create progress indicator - progress = kodiutils.progress(message=kodiutils.localize(30715)) # Updating metadata + 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}) + 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) @@ -48,7 +49,18 @@ class Metadata: # Run callback after every item if callback and callback(index, count): - # Stop when callback returns False + # 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: + kodiutils.delete(cache_path + filename) + + kodiutils.set_setting('metadata_last_updated', '0') + kodiutils.ok_dialog(message=kodiutils.localize(30714)) # Local metadata is cleared diff --git a/resources/lib/viervijfzes/content.py b/resources/lib/viervijfzes/content.py index 7a135ed..fd97279 100644 --- a/resources/lib/viervijfzes/content.py +++ b/resources/lib/viervijfzes/content.py @@ -213,7 +213,7 @@ class ContentApi: programs = [] for path in data: title = data[path] - program = self.get_program(channel, path, CACHE_ONLY) # Get program details, but from cache only + program = self.get_program(channel, path, cache=CACHE_ONLY) # Get program details, but from cache only if program: # Use program with metadata from cache programs.append(program) @@ -228,6 +228,7 @@ class ContentApi: """ Get a Program object from the specified page. :type channel: str :type path: str + :type extract_clips: bool :type cache: int :rtype Program """ diff --git a/resources/settings.xml b/resources/settings.xml index 1a7b5c0..50229ec 100644 --- a/resources/settings.xml +++ b/resources/settings.xml @@ -6,13 +6,14 @@ - - + + - - - + + + +