From a26708d7f7d655b8af141382a09fbeb6f02c0c28 Mon Sep 17 00:00:00 2001 From: edit4ever Date: Mon, 4 Mar 2019 09:23:47 -0700 Subject: [PATCH] add option to refresh cache download days --- addon.xml | 3 ++- changelog.txt | 3 +++ .../resource.language.en_gb/strings.po | 6 ++++- resources/settings.xml | 1 + zap2epg.py | 25 ++++++++++++++----- 5 files changed, 30 insertions(+), 8 deletions(-) diff --git a/addon.xml b/addon.xml index 57a2d6c..550b3a5 100644 --- a/addon.xml +++ b/addon.xml @@ -1,5 +1,5 @@ - + @@ -29,6 +29,7 @@ Setup: + v1.2.0 - add option to refresh download cache days (2019-03-04) v1.1.0 - added ability to refresh TBA episodes (2018-11-20) v1.0.0 - official stable release (2018-07-12) diff --git a/changelog.txt b/changelog.txt index 974f596..53a7858 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,6 @@ +v1.2.0 (2019-03-04) + - add option to refresh download cache days + v1.1.0 (2018-11-20) - added ability to refresh TBA episode information diff --git a/resources/language/resource.language.en_gb/strings.po b/resources/language/resource.language.en_gb/strings.po index 8220e7f..03f6e91 100644 --- a/resources/language/resource.language.en_gb/strings.po +++ b/resources/language/resource.language.en_gb/strings.po @@ -48,7 +48,11 @@ msgctxt "#32014" msgid "Append Extra Details to Description" msgstr "" -# 32015-32019 blank +msgctxt "#32015" +msgid "Number of Days to Delete Cache (re-download)" +msgstr "" + +# 32016-32019 blank msgctxt "#32020" msgid "Include Episode Thumbnail" diff --git a/resources/settings.xml b/resources/settings.xml index e4e4869..a1c21b6 100644 --- a/resources/settings.xml +++ b/resources/settings.xml @@ -2,6 +2,7 @@ + diff --git a/zap2epg.py b/zap2epg.py index 99d0108..c813328 100644 --- a/zap2epg.py +++ b/zap2epg.py @@ -63,6 +63,8 @@ def mainRun(userdata): device = settingsDict[setting] if setting == 'days': days = settingsDict[setting] + if setting == 'redays': + redays = settingsDict[setting] if setting == 'xdetails': xdetails = settingsDict[setting] if setting == 'xdesc': @@ -125,7 +127,7 @@ def tvhMatchGet(): logging.exception('Exception: tvhMatch - %s', e.strerror) pass - def deleteOldCache(gridtimeStart, showList): + def deleteOldCache(gridtimeStart): logging.info('Checking for old cache files...') try: if os.path.exists(cacheDir): @@ -134,22 +136,32 @@ def deleteOldCache(gridtimeStart, showList): oldfile = entry.split('.')[0] if oldfile.isdigit(): fn = os.path.join(cacheDir, entry) - if (int(oldfile) + 10800) < gridtimeStart: + if (int(oldfile)) < (gridtimeStart + (int(redays) * 86400)): try: os.remove(fn) logging.info('Deleting old cache: %s', entry) except OSError, e: logging.warn('Error Deleting: %s - %s.' % (e.filename, e.strerror)) - elif not oldfile.isdigit(): + except Exception as e: + logging.exception('Exception: deleteOldCache - %s', e.strerror) + + def deleteOldShowCache(showList): + logging.info('Checking for old show cache files...') + try: + if os.path.exists(cacheDir): + entries = os.listdir(cacheDir) + for entry in entries: + oldfile = entry.split('.')[0] + if not oldfile.isdigit(): fn = os.path.join(cacheDir, entry) if oldfile not in showList: try: os.remove(fn) - logging.info('Deleting old cache: %s', entry) + logging.info('Deleting old show cache: %s', entry) except OSError, e: logging.warn('Error Deleting: %s - %s.' % (e.filename, e.strerror)) except Exception as e: - logging.exception('Exception: deleteOldCache - %s', e.strerror) + logging.exception('Exception: deleteOldshowCache - %s', e.strerror) def convTime(t): return time.strftime("%Y%m%d%H%M%S",time.localtime(int(t))) @@ -739,6 +751,7 @@ def makeDescsortList(optList): logging.info('No channel list found - adding all stations!') if tvhoff == 'true' and tvhmatch == 'true': tvhMatchGet() + deleteOldCache(gridtimeStart) while count < dayHours: filename = str(gridtime) + '.json.gz' fileDir = os.path.join(cacheDir, filename) @@ -776,7 +789,7 @@ def makeDescsortList(optList): else: showList = [] xmltv() - deleteOldCache(gridtimeStart, showList) + deleteOldShowCache(showList) timeRun = round((time.time() - pythonStartTime),2) logging.info('zap2epg completed in %s seconds. ', timeRun) logging.info('%s Stations and %s Episodes written to xmltv.xml file.', str(stationCount), str(episodeCount))