Remove background metadata downloading (#74)
* Don't download metadata in the background anymore * Remove warning logging
This commit is contained in:
parent
a80100247e
commit
1a541552d7
@ -152,18 +152,6 @@ msgctxt "#30713"
|
|||||||
msgid "The requested video was not found in the guide."
|
msgid "The requested video was not found in the guide."
|
||||||
msgstr ""
|
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"
|
msgctxt "#30717"
|
||||||
msgid "This program is not available in the catalogue."
|
msgid "This program is not available in the catalogue."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
@ -180,10 +168,6 @@ msgctxt "#30720"
|
|||||||
msgid "This video is not available abroad."
|
msgid "This video is not available abroad."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
msgctxt "#30721"
|
|
||||||
msgid "Clearing local metadata failed."
|
|
||||||
msgstr ""
|
|
||||||
|
|
||||||
|
|
||||||
### SETTINGS
|
### SETTINGS
|
||||||
msgctxt "#30800"
|
msgctxt "#30800"
|
||||||
@ -202,26 +186,6 @@ msgctxt "#30803"
|
|||||||
msgid "Password"
|
msgid "Password"
|
||||||
msgstr ""
|
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"
|
msgctxt "#30840"
|
||||||
msgid "Integration"
|
msgid "Integration"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
@ -153,18 +153,6 @@ msgctxt "#30713"
|
|||||||
msgid "The requested video was not found in the guide."
|
msgid "The requested video was not found in the guide."
|
||||||
msgstr "De gevraagde video werd niet gevonden in de tv-gids."
|
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"
|
msgctxt "#30717"
|
||||||
msgid "This program is not available in the catalogue."
|
msgid "This program is not available in the catalogue."
|
||||||
msgstr "Dit programma is niet beschikbaar in de catalogus."
|
msgstr "Dit programma is niet beschikbaar in de catalogus."
|
||||||
@ -181,10 +169,6 @@ msgctxt "#30720"
|
|||||||
msgid "This video is not available abroad."
|
msgid "This video is not available abroad."
|
||||||
msgstr "Deze video is niet beschikbaar in het buitenland."
|
msgstr "Deze video is niet beschikbaar in het buitenland."
|
||||||
|
|
||||||
msgctxt "#30721"
|
|
||||||
msgid "Clearing local metadata failed."
|
|
||||||
msgstr "Wissen van lokale metadata is mislukt."
|
|
||||||
|
|
||||||
|
|
||||||
### SETTINGS
|
### SETTINGS
|
||||||
msgctxt "#30800"
|
msgctxt "#30800"
|
||||||
@ -203,26 +187,6 @@ msgctxt "#30803"
|
|||||||
msgid "Password"
|
msgid "Password"
|
||||||
msgstr "Wachtwoord"
|
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"
|
msgctxt "#30840"
|
||||||
msgid "Integration"
|
msgid "Integration"
|
||||||
msgstr "Integratie"
|
msgstr "Integratie"
|
||||||
|
@ -159,20 +159,6 @@ def play_from_page(page):
|
|||||||
Player().play_from_page(unquote(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')
|
@routing.route('/iptv/channels')
|
||||||
def iptv_channels():
|
def iptv_channels():
|
||||||
""" Generate channel data for the Kodi PVR integration """
|
""" Generate channel data for the Kodi PVR integration """
|
||||||
|
@ -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
|
|
@ -5,8 +5,6 @@ from __future__ import absolute_import, division, unicode_literals
|
|||||||
|
|
||||||
import hashlib
|
import hashlib
|
||||||
import logging
|
import logging
|
||||||
import os
|
|
||||||
from time import time
|
|
||||||
|
|
||||||
from xbmc import Monitor, Player, getInfoLabel
|
from xbmc import Monitor, Player, getInfoLabel
|
||||||
|
|
||||||
@ -31,10 +29,6 @@ class BackgroundService(Monitor):
|
|||||||
_LOGGER.debug('Service started')
|
_LOGGER.debug('Service started')
|
||||||
|
|
||||||
while not self.abortRequested():
|
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
|
# Stop when abort requested
|
||||||
if self.waitForAbort(10):
|
if self.waitForAbort(10):
|
||||||
break
|
break
|
||||||
@ -62,38 +56,6 @@ class BackgroundService(Monitor):
|
|||||||
return True
|
return True
|
||||||
return False
|
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):
|
class KodiPlayer(Player):
|
||||||
"""Communication with Kodi Player"""
|
"""Communication with Kodi Player"""
|
||||||
|
@ -89,8 +89,6 @@ class CognitoSync:
|
|||||||
signed_headers + '\n' +
|
signed_headers + '\n' +
|
||||||
payload_hash)
|
payload_hash)
|
||||||
|
|
||||||
_LOGGER.warning(canonical_request)
|
|
||||||
|
|
||||||
# Step 2. Create a string to sign
|
# Step 2. Create a string to sign
|
||||||
algorithm = 'AWS4-HMAC-SHA256'
|
algorithm = 'AWS4-HMAC-SHA256'
|
||||||
credential_scope = '%s/%s/%s/%s' % (datestamp, self.region, service, 'aws4_request')
|
credential_scope = '%s/%s/%s/%s' % (datestamp, self.region, service, 'aws4_request')
|
||||||
|
@ -208,7 +208,7 @@ class ContentApi:
|
|||||||
return data
|
return data
|
||||||
|
|
||||||
# Fetch listing from cache or update if needed
|
# 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:
|
if not data:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
@ -1,17 +1,10 @@
|
|||||||
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
|
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
|
||||||
<settings>
|
<settings>
|
||||||
<setting id="metadata_last_updated" visible="false"/>
|
|
||||||
<category label="30800"> <!-- Credentials -->
|
<category label="30800"> <!-- Credentials -->
|
||||||
<setting label="30801" type="lsep"/> <!-- Credentials -->
|
<setting label="30801" type="lsep"/> <!-- Credentials -->
|
||||||
<setting label="30802" type="text" id="username"/>
|
<setting label="30802" type="text" id="username"/>
|
||||||
<setting label="30803" type="text" id="password" option="hidden"/>
|
<setting label="30803" type="text" id="password" option="hidden"/>
|
||||||
</category>
|
</category>
|
||||||
<category label="30820"> <!-- Interface -->
|
|
||||||
<setting label="30821" type="lsep"/> <!-- Metadata -->
|
|
||||||
<setting label="30822" type="bool" id="metadata_update" default="true" subsetting="true"/>
|
|
||||||
<setting label="30823" type="action" action="RunPlugin(plugin://plugin.video.viervijfzes/metadata/update)"/>
|
|
||||||
<setting label="30824" type="action" action="RunPlugin(plugin://plugin.video.viervijfzes/metadata/clean)"/>
|
|
||||||
</category>
|
|
||||||
<category label="30840"> <!-- Integrations -->
|
<category label="30840"> <!-- Integrations -->
|
||||||
<setting label="30841" type="lsep"/> <!-- IPTV Manager -->
|
<setting label="30841" type="lsep"/> <!-- IPTV Manager -->
|
||||||
<setting label="30842" type="action" action="InstallAddon(service.iptv.manager)" option="close" visible="!System.HasAddon(service.iptv.manager)"/> <!-- Install IPTV Manager add-on -->
|
<setting label="30842" type="action" action="InstallAddon(service.iptv.manager)" option="close" visible="!System.HasAddon(service.iptv.manager)"/> <!-- Install IPTV Manager add-on -->
|
||||||
|
@ -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, channel='Play4'), '0', ''])
|
||||||
routing.run([routing.url_for(addon.show_channel_tvguide_detail, channel='Play4', date='today'), '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__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Loading…
Reference in New Issue
Block a user