Skip to content

Commit

Permalink
Edit menu caching and allow clearing
Browse files Browse the repository at this point in the history
  • Loading branch information
mediaminister committed Sep 18, 2024
1 parent 8fa89bb commit 31abeef
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 3 deletions.
13 changes: 13 additions & 0 deletions resources/language/resource.language.en_gb/strings.po
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
msgid ""
msgstr ""
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: en\n"
Expand Down Expand Up @@ -96,6 +97,10 @@ msgctxt "#30702"
msgid "An error occurred while authenticating: {error}."
msgstr ""

msgctxt "#30707"
msgid "The cache has been cleared."
msgstr ""

msgctxt "#30710"
msgid "This video is geo-blocked and can't be played from your location: {error}."
msgstr ""
Expand Down Expand Up @@ -153,3 +158,11 @@ msgstr ""
msgctxt "#30884"
msgid "Open Kodi Logfile Uploader…"
msgstr ""

msgctxt "#30885"
msgid "Cache"
msgstr ""

msgctxt "#30886"
msgid "Clear cache"
msgstr ""
12 changes: 12 additions & 0 deletions resources/language/resource.language.nl_nl/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ msgctxt "#30702"
msgid "An error occurred while authenticating: {error}."
msgstr "Er is een fout opgetreden tijdens het aanmelden: {error}."

msgctxt "#30707"
msgid "The cache has been cleared."
msgstr "De cache is gewist."

msgctxt "#30710"
msgid "This video is geo-blocked and can't be played from your location: {error}."
msgstr "Deze video is geografisch geblokkeerd en kan niet worden afgespeeld vanaf je locatie: {error}."
Expand Down Expand Up @@ -154,3 +158,11 @@ msgstr "Installeer Kodi Logfile Uploader…"
msgctxt "#30884"
msgid "Open Kodi Logfile Uploader…"
msgstr "Open Kodi Logfile Uploader…"

msgctxt "#30885"
msgid "Cache"
msgstr "Cache"

msgctxt "#30886"
msgid "Clear cache"
msgstr "Wis cache"
7 changes: 7 additions & 0 deletions resources/lib/addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,13 @@ def play_catalog(uuid=None, content_type=None):
Player().play(uuid, content_type)


@routing.route('/cache/clear')
def clear_cache():
""" Clear the cache """
from resources.lib.modules.catalog import Catalog
Catalog().clear_cache()


def run(params):
""" Run the routing plugin """
kodilogging.config()
Expand Down
1 change: 1 addition & 0 deletions resources/lib/goplay/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,7 @@ def _parse_program_data(data):
uuid=data.get('programUuid'),
path=data.get('programUuid'),
channel=data.get('brand'),
category_name=data.get('category') or 'No category',
title=data.get('title'),
description=html_to_kodi(data.get('description')),
aired=datetime.fromtimestamp(data.get('dates', {}).get('publishDate', 0.0) or 0.0),
Expand Down
17 changes: 17 additions & 0 deletions resources/lib/kodiutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,23 @@ def get_cache_path():
return getattr(get_cache_path, 'cached')


def invalidate_cache(ttl=None):
""" Clear the cache """
fullpath = get_cache_path() + '/'

if not xbmcvfs.exists(fullpath):
return

_, files = xbmcvfs.listdir(fullpath)
import time
now = time.mktime(time.localtime())
for filename in files:
filepath = os.path.join(fullpath, to_unicode(filename))
if ttl and now - xbmcvfs.Stat(filepath).st_mtime() < ttl:
continue
xbmcvfs.delete(filepath)


def get_addon_info(key):
"""Return addon information"""
return to_unicode(ADDON.getAddonInfo(key))
Expand Down
8 changes: 7 additions & 1 deletion resources/lib/modules/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def show_season(self, season_uuid):
:type season_uuid: str
"""
try:
episodes = self._api.get_episodes(season_uuid)
episodes = self._api.get_episodes(season_uuid, cache=CACHE_PREVENT) # Use CACHE_PREVENT since we want fresh data
except UnavailableException:
kodiutils.ok_dialog(message=kodiutils.localize(30717)) # This program is not available in the catalogue.
kodiutils.end_of_directory()
Expand Down Expand Up @@ -218,3 +218,9 @@ def continue_watching(self, index=0):
# Sort items by title
# Used for A-Z listing or when movies and episodes are mixed.
kodiutils.show_listing(listing, 30011, content='tvshows', sort='title')

@staticmethod
def clear_cache():
""" Clear the cache """
kodiutils.invalidate_cache()
kodiutils.notification(message=kodiutils.localize(30707))
16 changes: 14 additions & 2 deletions resources/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
</group>
</category>
<category id="expert" label="30880" help=""> <!-- Expert -->
<group id="2" label="30881">
<group id="2" label="30881"> <!-- Logging -->
<setting id="debug_logging" type="boolean" label="30882" help="">
<level>0</level>
<default>false</default>
Expand All @@ -64,7 +64,19 @@
<dependency type="visible" on="property" name="infobool">System.HasAddon(script.kodi.loguploader) | System.AddonIsEnabled(script.kodi.loguploader)</dependency>
</dependencies>
</setting>
</group>
</group>
<group id="3" label="30885"> <!-- Cache -->
<setting id="clear_cache" type="action" label="30886" help=""> <!-- Clear cache -->
<level>0</level>
<default/>
<constraints>
<allowempty>true</allowempty>
</constraints>
<control type="button" format="action">
<data>RunPlugin(plugin://plugin.video.goplay/cache/clear)</data>
</control>
</setting>
</group>
</category>
</section>
</settings>

0 comments on commit 31abeef

Please sign in to comment.