| 1 | from enigma import * #, quitMainloop
|
|---|
| 2 | from Components.ServiceEventTracker import ServiceEventTracker
|
|---|
| 3 | from Tools.Directories import fileExists
|
|---|
| 4 | from crossepglib import *
|
|---|
| 5 | from crossepg_downloader import CrossEPG_Downloader
|
|---|
| 6 | from crossepg_converter import CrossEPG_Converter
|
|---|
| 7 | from crossepg_loader import CrossEPG_Loader
|
|---|
| 8 | from crossepg_importer import CrossEPG_Importer
|
|---|
| 9 | from crossepg_locale import _
|
|---|
| 10 | from Screens.Screen import Screen
|
|---|
| 11 |
|
|---|
| 12 | from time import *
|
|---|
| 13 |
|
|---|
| 14 | import os
|
|---|
| 15 |
|
|---|
| 16 | class CrossEPG_Auto(Screen):
|
|---|
| 17 | POLL_TIMER = 1800000 # poll every 30 minutes
|
|---|
| 18 | #POLL_TIMER = 18000
|
|---|
| 19 | POLL_TIMER_FAST = 10000 # poll every 10 seconds
|
|---|
| 20 | POLL_TIMER_BOOT = 60000 # poll every 1 minute
|
|---|
| 21 |
|
|---|
| 22 | def __init__(self):
|
|---|
| 23 | self.session = None
|
|---|
| 24 |
|
|---|
| 25 | self.timer = eTimer()
|
|---|
| 26 | self.standbyTimer = eTimer()
|
|---|
| 27 | self.delayedInitTimer = eTimer()
|
|---|
| 28 |
|
|---|
| 29 | self.timer.callback.append(self.poll)
|
|---|
| 30 | self.standbyTimer.callback.append(self.backToStandby)
|
|---|
| 31 | self.delayedInitTimer.callback.append(self.init)
|
|---|
| 32 |
|
|---|
| 33 | self.config = CrossEPG_Config()
|
|---|
| 34 | self.patchtype = getEPGPatchType()
|
|---|
| 35 |
|
|---|
| 36 | self.pdownloader = None
|
|---|
| 37 | self.pimporter = None
|
|---|
| 38 | self.pconverter = None
|
|---|
| 39 | self.ploader = None
|
|---|
| 40 |
|
|---|
| 41 | self.osd = False
|
|---|
| 42 | self.ontune = False
|
|---|
| 43 | self.lock = False
|
|---|
| 44 |
|
|---|
| 45 | if fileExists("/tmp/crossepg.standby"):
|
|---|
| 46 | os.system("rm -f /tmp/crossepg.standby")
|
|---|
| 47 | print "[CrossEPG_Auto] coming back in standby in 30 seconds"
|
|---|
| 48 | self.standbyTimer.start(30000, 1)
|
|---|
| 49 |
|
|---|
| 50 | self.config.load()
|
|---|
| 51 |
|
|---|
| 52 | if self.config.force_load_on_boot:
|
|---|
| 53 | self.loader()
|
|---|
| 54 |
|
|---|
| 55 | def init(self, session = None):
|
|---|
| 56 | if session != None:
|
|---|
| 57 | self.session = session
|
|---|
| 58 |
|
|---|
| 59 | if time() < 1262325600: # if before 2010 probably the clock isn't yet updated
|
|---|
| 60 | self.delayedInitTimer.start(60000, 1) #initialization delayed of 1 minute
|
|---|
| 61 | return
|
|---|
| 62 |
|
|---|
| 63 | self.resetDailyDownloadDateCache()
|
|---|
| 64 | self.timer.start(self.POLL_TIMER_BOOT, 1)
|
|---|
| 65 |
|
|---|
| 66 | def forcePoll(self):
|
|---|
| 67 | self.timer.stop()
|
|---|
| 68 | self.resetDailyDownloadDateCache()
|
|---|
| 69 | self.timer.start(self.POLL_TIMER_FAST, 1)
|
|---|
| 70 |
|
|---|
| 71 | def resetDailyDownloadDateCache(self):
|
|---|
| 72 | self.config.load()
|
|---|
| 73 | now = time()
|
|---|
| 74 | ttime = localtime(now)
|
|---|
| 75 | ltime = (ttime[0], ttime[1], ttime[2], self.config.download_daily_hours, self.config.download_daily_minutes, 0, ttime[6], ttime[7], ttime[8])
|
|---|
| 76 | stime = mktime(ltime)
|
|---|
| 77 | if stime < now:
|
|---|
| 78 | ttime = localtime(stime+86400) # 24 hours in future
|
|---|
| 79 |
|
|---|
| 80 | # to avoid problems with internal clock (big changes on date/time)
|
|---|
| 81 | # we step forward of 24 hours until the new time is greater than now
|
|---|
| 82 | while ttime < now:
|
|---|
| 83 | ttime = ttime+86400 # 24 hours in future
|
|---|
| 84 |
|
|---|
| 85 | self.cacheYear = ttime[0]
|
|---|
| 86 | self.cacheMonth = ttime[1]
|
|---|
| 87 | self.cacheDay = ttime[2]
|
|---|
| 88 |
|
|---|
| 89 | def poll(self):
|
|---|
| 90 | from Screens.Standby import inStandby
|
|---|
| 91 | self.config.load()
|
|---|
| 92 |
|
|---|
| 93 | if self.lock:
|
|---|
| 94 | print "[CrossEPG_Auto] poll"
|
|---|
| 95 | self.timer.start(self.POLL_TIMER_FAST, 1)
|
|---|
| 96 | elif self.session.nav.RecordTimer.isRecording() or abs(self.session.nav.RecordTimer.getNextRecordingTime() - time()) <= 900 or abs(self.session.nav.RecordTimer.getNextZapTime() - time()) <= 900:
|
|---|
| 97 | print "[CrossEPG_Auto] poll"
|
|---|
| 98 | self.timer.start(self.POLL_TIMER, 1)
|
|---|
| 99 | elif self.config.download_standby_enabled and inStandby:
|
|---|
| 100 | self.providers = []
|
|---|
| 101 | now = time()
|
|---|
| 102 |
|
|---|
| 103 | if self.config.last_full_download_timestamp <= now - (24*60*60):
|
|---|
| 104 | self.config.last_full_download_timestamp = now
|
|---|
| 105 | self.config.last_partial_download_timestamp = now
|
|---|
| 106 | self.config.save()
|
|---|
| 107 | self.providers = self.config.providers
|
|---|
| 108 | elif self.config.last_partial_download_timestamp <= now - (60*60): # skip xmltv... we download it only one time a day
|
|---|
| 109 | self.config.last_partial_download_timestamp = now
|
|---|
| 110 | self.config.save()
|
|---|
| 111 | providers = self.config.getAllProviders()
|
|---|
| 112 | i = 0
|
|---|
| 113 | for provider in providers[0]:
|
|---|
| 114 | if self.config.providers.count(provider) > 0:
|
|---|
| 115 | if providers[2][i] == "opentv":
|
|---|
| 116 | self.providers.append(provider)
|
|---|
| 117 | else:
|
|---|
| 118 | print "[CrossEPG_Auto] is not OpenTV : skip provider %s (we download it only one time a day)" % provider
|
|---|
| 119 | i += 1
|
|---|
| 120 |
|
|---|
| 121 | if len(self.providers) == 0:
|
|---|
| 122 | print "[CrossEPG_Auto] poll"
|
|---|
| 123 | self.timer.start(self.POLL_TIMER, 1)
|
|---|
| 124 | else:
|
|---|
| 125 | print "[CrossEPG_Auto] automatic download in standby"
|
|---|
| 126 | self.osd = False
|
|---|
| 127 | self.ontune = False
|
|---|
| 128 | self.config.deleteLog()
|
|---|
| 129 | self.download(self.providers)
|
|---|
| 130 | elif self.config.download_daily_enabled:
|
|---|
| 131 | now = time()
|
|---|
| 132 | ttime = localtime(now)
|
|---|
| 133 | ltime = (self.cacheYear, self.cacheMonth, self.cacheDay, self.config.download_daily_hours, self.config.download_daily_minutes, 0, ttime[6], ttime[7], ttime[8])
|
|---|
| 134 | stime = mktime(ltime)
|
|---|
| 135 | if stime < now and self.config.last_full_download_timestamp != stime:
|
|---|
| 136 | from Screens.Standby import inStandby
|
|---|
| 137 | self.osd = (inStandby == None)
|
|---|
| 138 | self.ontune = False
|
|---|
| 139 | self.config.last_full_download_timestamp = stime
|
|---|
| 140 | self.config.last_partial_download_timestamp = stime
|
|---|
| 141 | self.config.save()
|
|---|
| 142 | ttime = localtime(stime+86400) # 24 hours in future
|
|---|
| 143 | # to avoid problems with internal clock (big changes on date/time)
|
|---|
| 144 | # we step forward of 24 hours until the new time is greater than now
|
|---|
| 145 | while ttime < now:
|
|---|
| 146 | ttime = ttime+86400 # 24 hours in future
|
|---|
| 147 | self.cacheYear = ttime[0]
|
|---|
| 148 | self.cacheMonth = ttime[1]
|
|---|
| 149 | self.cacheDay = ttime[2]
|
|---|
| 150 | self.config.deleteLog()
|
|---|
| 151 | self.download(self.config.providers)
|
|---|
| 152 | elif stime < now + (self.POLL_TIMER / 1000) and self.config.last_full_download_timestamp != stime:
|
|---|
| 153 | print "[CrossEPG_Auto] poll"
|
|---|
| 154 | delta = int(stime - now);
|
|---|
| 155 | self.timer.start((delta + 5)*1000, 1) # 5 seconds offset
|
|---|
| 156 | else:
|
|---|
| 157 | print "[CrossEPG_Auto] poll"
|
|---|
| 158 | self.timer.start(self.POLL_TIMER, 1)
|
|---|
| 159 | elif self.config.download_tune_enabled:
|
|---|
| 160 | now = time()
|
|---|
| 161 | if self.config.last_partial_download_timestamp <= now - (60*60):
|
|---|
| 162 | providerok = None
|
|---|
| 163 | sservice = self.session.nav.getCurrentlyPlayingServiceReference()
|
|---|
| 164 | if sservice:
|
|---|
| 165 | service = sservice.toString()
|
|---|
| 166 |
|
|---|
| 167 | providers = self.config.getAllProviders()
|
|---|
| 168 | i = 0
|
|---|
| 169 | for provider in providers[0]:
|
|---|
| 170 | if providers[2][i] == "opentv":
|
|---|
| 171 | if self.config.getChannelID(provider) == service:
|
|---|
| 172 | providerok = provider
|
|---|
| 173 | break;
|
|---|
| 174 | i += 1
|
|---|
| 175 |
|
|---|
| 176 | if providerok:
|
|---|
| 177 | print "[CrossEPG_Auto] automatic download on tune"
|
|---|
| 178 | self.osd = False
|
|---|
| 179 | self.ontune = True
|
|---|
| 180 | self.config.last_partial_download_timestamp = now
|
|---|
| 181 | self.config.save()
|
|---|
| 182 | self.config.deleteLog()
|
|---|
| 183 | self.download([provider,])
|
|---|
| 184 | else:
|
|---|
| 185 | print "[CrossEPG_Auto] poll"
|
|---|
| 186 | self.timer.start(self.POLL_TIMER, 1)
|
|---|
| 187 | else:
|
|---|
| 188 | print "[CrossEPG_Auto] poll"
|
|---|
| 189 | self.timer.start(self.POLL_TIMER, 1)
|
|---|
| 190 | else:
|
|---|
| 191 | print "[CrossEPG_Auto] poll"
|
|---|
| 192 | self.timer.start(self.POLL_TIMER, 1)
|
|---|
| 193 |
|
|---|
| 194 | def download(self, providers):
|
|---|
| 195 | print "[CrossEPG_Auto] providers selected for download:"
|
|---|
| 196 | for provider in providers:
|
|---|
| 197 | print "[CrossEPG_Auto] %s" % provider
|
|---|
| 198 | if self.osd:
|
|---|
| 199 | self.session.openWithCallback(self.downloadCallback, CrossEPG_Downloader, providers)
|
|---|
| 200 | else:
|
|---|
| 201 | self.pdownloader = CrossEPG_Downloader(self.session, providers, self.downloadCallback, True)
|
|---|
| 202 |
|
|---|
| 203 | def downloadCallback(self, ret):
|
|---|
| 204 | self.pdownloader = None
|
|---|
| 205 |
|
|---|
| 206 | from Screens.Standby import inStandby
|
|---|
| 207 | if inStandby: # if in standby force service stop
|
|---|
| 208 | self.session.nav.stopService()
|
|---|
| 209 |
|
|---|
| 210 | if ret:
|
|---|
| 211 | if self.config.csv_import_enabled == 1 and not self.ontune:
|
|---|
| 212 | self.importer()
|
|---|
| 213 | else:
|
|---|
| 214 | if self.patchtype != 3:
|
|---|
| 215 | self.converter()
|
|---|
| 216 | else:
|
|---|
| 217 | self.loader()
|
|---|
| 218 | else:
|
|---|
| 219 | self.timer.start(self.POLL_TIMER, 1)
|
|---|
| 220 |
|
|---|
| 221 | def importer(self):
|
|---|
| 222 | print "[CrossEPG_Auto] start csv import"
|
|---|
| 223 | if self.osd:
|
|---|
| 224 | self.session.openWithCallback(self.importerCallback, CrossEPG_Importer)
|
|---|
| 225 | else:
|
|---|
| 226 | self.pimporter = CrossEPG_Importer(self.session, self.importerCallback, True)
|
|---|
| 227 |
|
|---|
| 228 | def importerCallback(self, ret):
|
|---|
| 229 | self.pimporter = None
|
|---|
| 230 |
|
|---|
| 231 | if ret:
|
|---|
| 232 | if self.patchtype != 3:
|
|---|
| 233 | self.converter()
|
|---|
| 234 | else:
|
|---|
| 235 | self.loader()
|
|---|
| 236 | else:
|
|---|
| 237 | self.timer.start(self.POLL_TIMER, 1)
|
|---|
| 238 |
|
|---|
| 239 | def converter(self):
|
|---|
| 240 | print "[CrossEPG_Auto] start epg.dat conversion"
|
|---|
| 241 | if self.osd:
|
|---|
| 242 | self.session.openWithCallback(self.converterCallback, CrossEPG_Converter)
|
|---|
| 243 | else:
|
|---|
| 244 | self.pconverter = CrossEPG_Converter(self.session, self.converterCallback, True)
|
|---|
| 245 |
|
|---|
| 246 | def converterCallback(self, ret):
|
|---|
| 247 | self.pconverter = None
|
|---|
| 248 |
|
|---|
| 249 | if ret:
|
|---|
| 250 | if self.patchtype != -1:
|
|---|
| 251 | self.loader()
|
|---|
| 252 | else:
|
|---|
| 253 | if self.config.download_daily_reboot:
|
|---|
| 254 | from Screens.Standby import inStandby
|
|---|
| 255 | if inStandby:
|
|---|
| 256 | os.system("touch /tmp/crossepg.standby")
|
|---|
| 257 | else:
|
|---|
| 258 | os.system("rm /tmp/crossepg.standby")
|
|---|
| 259 | print "[CrossEPG_Auto] rebooting"
|
|---|
| 260 | from Screens.Standby import TryQuitMainloop
|
|---|
| 261 | self.session.open(TryQuitMainloop, 3)
|
|---|
| 262 | else:
|
|---|
| 263 | self.timer.start(self.POLL_TIMER, 1)
|
|---|
| 264 | else:
|
|---|
| 265 | self.timer.start(self.POLL_TIMER, 1)
|
|---|
| 266 |
|
|---|
| 267 | def loader(self):
|
|---|
| 268 | if self.osd:
|
|---|
| 269 | self.session.openWithCallback(self.loaderCallback, CrossEPG_Loader)
|
|---|
| 270 | else:
|
|---|
| 271 | self.ploader = CrossEPG_Loader(self.session, self.loaderCallback, True)
|
|---|
| 272 |
|
|---|
| 273 | def loaderCallback(self, ret):
|
|---|
| 274 | self.ploader = None
|
|---|
| 275 | self.timer.start(self.POLL_TIMER, 1)
|
|---|
| 276 |
|
|---|
| 277 | def stop(self):
|
|---|
| 278 | if self.pdownloader:
|
|---|
| 279 | self.pdownloader.quit()
|
|---|
| 280 | self.pdownloader = None
|
|---|
| 281 | if self.pimporter:
|
|---|
| 282 | self.pimporter.quit()
|
|---|
| 283 | self.pimporter = None
|
|---|
| 284 | if self.pconverter:
|
|---|
| 285 | self.pconverter.quit()
|
|---|
| 286 | self.pconverter = None
|
|---|
| 287 | if self.ploader:
|
|---|
| 288 | self.ploader.quit()
|
|---|
| 289 | self.ploader = None
|
|---|
| 290 |
|
|---|
| 291 | def backToStandby(self):
|
|---|
| 292 | from Screens.Standby import inStandby
|
|---|
| 293 | if inStandby == None:
|
|---|
| 294 | print "[CrossEPG_Auto] coming back in standby"
|
|---|
| 295 | from Screens.Standby import Standby
|
|---|
| 296 | self.session.open(Standby)
|
|---|
| 297 |
|
|---|
| 298 | crossepg_auto = CrossEPG_Auto()
|
|---|