1.0.0+kodimov.8: guide refresh doesn't fail at random; retry after 30 min

datetime.strptime sometimes fails in Kodi's embedded Python ('NoneType'
object is not callable), which aborted the whole guide export. Build the
XMLTV times without it.

The service now checks every 30 minutes and refreshes when the files are
over 6 hours old, so a failed refresh is retried soon. write_if_changed
touches an unchanged file so its time means "last refreshed".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
XoséandClaude Opus 5.5 committed 2026-11-10 08:36:21 +01:00
1 parent 9faaa482fc
commit 5df60a1fb8
4 files changed
+27 -31

No files matched your search

+18 -26
View File
@@ -12,26 +12,12 @@ from resources.lib.addon import *
from resources.lib.log import LOG
from resources.lib import kodimov
def export_epg():
from datetime import datetime, timedelta
def needs_update(filename):
if os.path.exists(filename):
file_modification_time = datetime.fromtimestamp(os.path.getmtime(filename))
return datetime.now() - file_modification_time > timedelta(hours=6)
return True
channels_filename = os.path.join(profile_dir, 'channels.m3u8')
epg_filename = os.path.join(profile_dir, 'epg.xml')
LOG('channels filename: {}'.format(channels_filename))
LOG('epg filename: {}'.format(epg_filename))
channels_needs_update = needs_update(channels_filename)
epg_needs_update = needs_update(epg_filename)
LOG('channels_needs_update: {} epg_needs_update: {}'.format(channels_needs_update, epg_needs_update))
if channels_needs_update or epg_needs_update:
xbmc.executebuiltin('RunPlugin(plugin://plugin.video.kodimovplus/?action=export_epg_now)')
def file_age(filename):
"""Seconds since the file was last written (or found unchanged)."""
try:
return time.time() - os.path.getmtime(filename)
except OSError:
return float('inf')
if __name__ == '__main__':
LOG('Service started')
@@ -40,8 +26,11 @@ if __name__ == '__main__':
LOG('proxy_address: {}'.format(proxy.proxy_address))
# Refreshes the TV guide channel list (new channels, new numbers) and the
# programme guide a minute after Kodi starts and then every 6 hours. Opening the add-on also renews the 10-day Movistar login.
next_export = time.time() + 60
# programme guide a minute after Kodi starts and then every 6 hours; a
# refresh that failed is tried again half an hour later. Opening the add-on
# also renews the 10-day Movistar login.
next_check = time.time() + 60
max_age = 0 # always refresh once after Kodi starts
try:
pvr_dir = translatePath(xbmcaddon.Addon('pvr.iptvsimple').getAddonInfo('profile'))
restart_iptv = kodimov.use_hourly_iptv_refresh(pvr_dir, 'kodimovplus')
@@ -55,11 +44,14 @@ if __name__ == '__main__':
if restart_iptv and not player.isPlaying(): # restarting stops live TV
restart_iptv = False
kodimov.restart_iptv_simple()
if time.time() >= next_export:
next_export = time.time() + 6 * 3600
if time.time() >= next_check:
next_check = time.time() + 30 * 60
age_limit, max_age = max_age, 6 * 3600 - 120
if addon.getSettingBool('auto_export_epg'): # channels + programme guide
xbmc.executebuiltin('RunPlugin(plugin://plugin.video.kodimovplus/?action=export_epg_now&quiet=1)')
if file_age(os.path.join(profile_dir, 'epg.xml')) > age_limit:
xbmc.executebuiltin('RunPlugin(plugin://plugin.video.kodimovplus/?action=export_epg_now&quiet=1)')
elif addon.getSettingBool('export_channels'):
xbmc.executebuiltin('RunPlugin(plugin://plugin.video.kodimovplus/?action=export_channels_now)')
if file_age(os.path.join(profile_dir, 'channels.m3u8')) > age_limit:
xbmc.executebuiltin('RunPlugin(plugin://plugin.video.kodimovplus/?action=export_channels_now)')
proxy.stop()