Skip to content

Commit

Permalink
add option to refresh cache download days
Browse files Browse the repository at this point in the history
  • Loading branch information
edit4ever committed Mar 4, 2019
1 parent 0e06997 commit a26708d
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 8 deletions.
3 changes: 2 additions & 1 deletion addon.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="script.module.zap2epg" name="zap2epg" version="1.1.0" provider-name="edit4ever">
<addon id="script.module.zap2epg" name="zap2epg" version="1.2.0" provider-name="edit4ever">
<requires>
<import addon="xbmc.python" version="2.7.13"/>
<import addon="script.module.dateutil" version="2.4.2"/>
Expand Down Expand Up @@ -29,6 +29,7 @@ Setup:
<email></email>
<source></source>
<news>
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)
</news>
Expand Down
3 changes: 3 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -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

Expand Down
6 changes: 5 additions & 1 deletion resources/language/resource.language.en_gb/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions resources/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<settings>
<category label="32011">
<setting label="32012" type="slider" id="days" default="1" range="1,1,14" option="int"/>
<setting label="32015" type="slider" id="redays" default="1" range="0,1,14" option="int"/>
<setting label="32013" type="bool" id="xdetails" default="false"/>
<setting label="32014" type="bool" id="xdesc" default="true"/>
<setting label="32020" type="enum" id="epicon" default="1" lvalues="32021|32022|32023"/>
Expand Down
25 changes: 19 additions & 6 deletions zap2epg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down Expand Up @@ -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):
Expand All @@ -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)))
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit a26708d

Please sign in to comment.