Skip to content

Commit a26708d

Browse files
committed
add option to refresh cache download days
1 parent 0e06997 commit a26708d

File tree

5 files changed

+30
-8
lines changed

5 files changed

+30
-8
lines changed

addon.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2-
<addon id="script.module.zap2epg" name="zap2epg" version="1.1.0" provider-name="edit4ever">
2+
<addon id="script.module.zap2epg" name="zap2epg" version="1.2.0" provider-name="edit4ever">
33
<requires>
44
<import addon="xbmc.python" version="2.7.13"/>
55
<import addon="script.module.dateutil" version="2.4.2"/>
@@ -29,6 +29,7 @@ Setup:
2929
<email></email>
3030
<source></source>
3131
<news>
32+
v1.2.0 - add option to refresh download cache days (2019-03-04)
3233
v1.1.0 - added ability to refresh TBA episodes (2018-11-20)
3334
v1.0.0 - official stable release (2018-07-12)
3435
</news>

changelog.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
v1.2.0 (2019-03-04)
2+
- add option to refresh download cache days
3+
14
v1.1.0 (2018-11-20)
25
- added ability to refresh TBA episode information
36

resources/language/resource.language.en_gb/strings.po

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ msgctxt "#32014"
4848
msgid "Append Extra Details to Description"
4949
msgstr ""
5050

51-
# 32015-32019 blank
51+
msgctxt "#32015"
52+
msgid "Number of Days to Delete Cache (re-download)"
53+
msgstr ""
54+
55+
# 32016-32019 blank
5256

5357
msgctxt "#32020"
5458
msgid "Include Episode Thumbnail"

resources/settings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<settings>
33
<category label="32011">
44
<setting label="32012" type="slider" id="days" default="1" range="1,1,14" option="int"/>
5+
<setting label="32015" type="slider" id="redays" default="1" range="0,1,14" option="int"/>
56
<setting label="32013" type="bool" id="xdetails" default="false"/>
67
<setting label="32014" type="bool" id="xdesc" default="true"/>
78
<setting label="32020" type="enum" id="epicon" default="1" lvalues="32021|32022|32023"/>

zap2epg.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ def mainRun(userdata):
6363
device = settingsDict[setting]
6464
if setting == 'days':
6565
days = settingsDict[setting]
66+
if setting == 'redays':
67+
redays = settingsDict[setting]
6668
if setting == 'xdetails':
6769
xdetails = settingsDict[setting]
6870
if setting == 'xdesc':
@@ -125,7 +127,7 @@ def tvhMatchGet():
125127
logging.exception('Exception: tvhMatch - %s', e.strerror)
126128
pass
127129

128-
def deleteOldCache(gridtimeStart, showList):
130+
def deleteOldCache(gridtimeStart):
129131
logging.info('Checking for old cache files...')
130132
try:
131133
if os.path.exists(cacheDir):
@@ -134,22 +136,32 @@ def deleteOldCache(gridtimeStart, showList):
134136
oldfile = entry.split('.')[0]
135137
if oldfile.isdigit():
136138
fn = os.path.join(cacheDir, entry)
137-
if (int(oldfile) + 10800) < gridtimeStart:
139+
if (int(oldfile)) < (gridtimeStart + (int(redays) * 86400)):
138140
try:
139141
os.remove(fn)
140142
logging.info('Deleting old cache: %s', entry)
141143
except OSError, e:
142144
logging.warn('Error Deleting: %s - %s.' % (e.filename, e.strerror))
143-
elif not oldfile.isdigit():
145+
except Exception as e:
146+
logging.exception('Exception: deleteOldCache - %s', e.strerror)
147+
148+
def deleteOldShowCache(showList):
149+
logging.info('Checking for old show cache files...')
150+
try:
151+
if os.path.exists(cacheDir):
152+
entries = os.listdir(cacheDir)
153+
for entry in entries:
154+
oldfile = entry.split('.')[0]
155+
if not oldfile.isdigit():
144156
fn = os.path.join(cacheDir, entry)
145157
if oldfile not in showList:
146158
try:
147159
os.remove(fn)
148-
logging.info('Deleting old cache: %s', entry)
160+
logging.info('Deleting old show cache: %s', entry)
149161
except OSError, e:
150162
logging.warn('Error Deleting: %s - %s.' % (e.filename, e.strerror))
151163
except Exception as e:
152-
logging.exception('Exception: deleteOldCache - %s', e.strerror)
164+
logging.exception('Exception: deleteOldshowCache - %s', e.strerror)
153165

154166
def convTime(t):
155167
return time.strftime("%Y%m%d%H%M%S",time.localtime(int(t)))
@@ -739,6 +751,7 @@ def makeDescsortList(optList):
739751
logging.info('No channel list found - adding all stations!')
740752
if tvhoff == 'true' and tvhmatch == 'true':
741753
tvhMatchGet()
754+
deleteOldCache(gridtimeStart)
742755
while count < dayHours:
743756
filename = str(gridtime) + '.json.gz'
744757
fileDir = os.path.join(cacheDir, filename)
@@ -776,7 +789,7 @@ def makeDescsortList(optList):
776789
else:
777790
showList = []
778791
xmltv()
779-
deleteOldCache(gridtimeStart, showList)
792+
deleteOldShowCache(showList)
780793
timeRun = round((time.time() - pythonStartTime),2)
781794
logging.info('zap2epg completed in %s seconds. ', timeRun)
782795
logging.info('%s Stations and %s Episodes written to xmltv.xml file.', str(stationCount), str(episodeCount))

0 commit comments

Comments
 (0)