def _grabAll(self): self._logger.debug("EpgProvider._grabAll") self._logger.warning("Grabbing EPG for all channels.") self._syncEpgIds() db = DBConnection() allChannels = Channel.getAllFromDb(db) if len(allChannels) == 0: self._logger.critical("No channels in the database. Script error?") return # Get epgids from database (contains channels per epg_id and strategy) epgIds = EpgId.getAllFromDb(db) now = time.localtime() nowDay = datetime.datetime(now[0], now[1], now[2]) # Remove program older than this day self._logger.warning("Removing EPG from before %s" % (getTimestamp(nowDay))) EpgProgram.deleteByTimeFromDB(db, getTimestamp(nowDay)) for epgId in epgIds: if not self._running: break self._grabEpgForChannel(epgId=epgId) if self._running: self._logger.warning("Grabbing EPG data complete.") else: self._logger.warning("Grabbing EPG interrupted.")
def _grabAll( self ): self._logger.debug( "EpgProvider._grabAll" ) self._logger.warning( "Grabbing EPG for all channels." ) self._syncEpgIds() db = DBConnection() allChannels = Channel.getAllFromDb( db ) if len( allChannels ) == 0: self._logger.critical( "No channels in the database. Script error?" ) return # Get epgids from database (contains channels per epg_id and strategy) epgIds = EpgId.getAllFromDb( db ) now = time.localtime() nowDay = datetime.datetime( now[0], now[1], now[2] ) # Remove program older than this day self._logger.warning( "Removing EPG from before %s" % ( getTimestamp( nowDay ) ) ) EpgProgram.deleteByTimeFromDB( db, getTimestamp( nowDay ) ) for epgId in epgIds: if not self._running: break self._grabEpgForChannel( epgId=epgId ) if self._running: self._logger.warning( "Grabbing EPG data complete." ) else: self._logger.warning( "Grabbing EPG interrupted." )
def _createMytvTvRecordedProgramObjectFromDbDict(cls, recordedData): recorded = None if recordedData: recorded = cls(recordedData["chanid"], getTimestamp(recordedData["starttime"]), getTimestamp(recordedData["endtime"]), recordedData["title"], recordedData["subtitle"], recordedData["description"], recordedData["category"]) return recorded
def _createMytvTvRecordedObjectFromDbDict(cls, recordedData): recorded = None if recordedData: recorded = cls(recordedData["recordid"], recordedData["chanid"], getTimestamp(recordedData["starttime"]), getTimestamp(recordedData["endtime"]), recordedData["title"], recordedData["basename"], recordedData["filesize"], getTimestamp(recordedData["progstart"]), getTimestamp(recordedData["progend"])) return recorded
def _createMytvTvRecordedProgramObjectFromDbDict( cls, recordedData ): recorded = None if recordedData: recorded = cls( recordedData["chanid"], getTimestamp( recordedData["starttime"] ), getTimestamp( recordedData["endtime"] ), recordedData["title"], recordedData["subtitle"], recordedData["description"], recordedData["category"] ) return recorded
def _createMytvTvRecordedObjectFromDbDict( cls, recordedData ): recorded = None if recordedData: recorded = cls( recordedData["recordid"], recordedData["chanid"], getTimestamp( recordedData["starttime"] ), getTimestamp( recordedData["endtime"] ), recordedData["title"], recordedData["basename"], recordedData["filesize"], getTimestamp( recordedData["progstart"] ), getTimestamp( recordedData["progend"] ) ) return recorded
def _createMytvTvRecordObjectFromDbDict( cls, recordData ): record = None if recordData: record = cls( recordData["recordid"], recordData["type"], recordData["chanid"], getTimestamp( datetime.datetime.combine( recordData["startdate"], datetime.time.min ) + recordData["starttime"] ), getTimestamp( datetime.datetime.combine( recordData["enddate"], datetime.time.min ) + recordData["endtime"] ), recordData["title"], recordData["dupmethod"], recordData["startoffset"] * 60, recordData["endoffset"] * 60, recordData["inactive"] ) return record
def _createMytvTvRecordObjectFromDbDict(cls, recordData): record = None if recordData: record = cls( recordData["recordid"], recordData["type"], recordData["chanid"], getTimestamp( datetime.datetime.combine(recordData["startdate"], datetime.time.min) + recordData["starttime"]), getTimestamp( datetime.datetime.combine(recordData["enddate"], datetime.time.min) + recordData["endtime"]), recordData["title"], recordData["dupmethod"], recordData["startoffset"] * 60, recordData["endoffset"] * 60, recordData["inactive"]) return record
def testNowNextPrograms(self): now = getTimestamp() program11 = self._createProgram(EpgProgram, 1, epgId="test_1", startTime=now - 600, endTime=now - 300) # before now program12 = self._createProgram(EpgProgram, 2, epgId="test_1", startTime=now - 300, endTime=now + 300) # now program13 = self._createProgram(EpgProgram, 3, epgId="test_1", startTime=now + 300, endTime=now + 600) # next program14 = self._createProgram(EpgProgram, 4, epgId="test_1", startTime=now + 600, endTime=now + 900) # after next program21 = self._createProgram(EpgProgram, 5, epgId="test_2", startTime=now - 600, endTime=now - 300) # before now program22 = self._createProgram(EpgProgram, 6, epgId="test_2", startTime=now - 300, endTime=now + 300) # now program23 = self._createProgram(EpgProgram, 7, epgId="test_2", startTime=now + 300, endTime=now + 600) # next program24 = self._createProgram(EpgProgram, 8, epgId="test_2", startTime=now + 600, endTime=now + 900) # after next program11.addToDb(self.db) program12.addToDb(self.db) program13.addToDb(self.db) program14.addToDb(self.db) program21.addToDb(self.db) program22.addToDb(self.db) program23.addToDb(self.db) program24.addToDb(self.db) nowNextPrograms = EpgProgram.getNowNextFromDb(self.db) nowNextProgramsSet = set([program12, program13, program22, program23]) nowNextProgramsDbSet = set(nowNextPrograms) self.assertSetEqual(nowNextProgramsSet, nowNextProgramsDbSet, "Now/next incorrect")
def _haveEnoughEpgData( self ): conn = DBConnection() lastProgram = EpgProgram.getTimestampLastProgram( conn ) timestamp = getTimestamp() if timestamp < lastProgram: daysLeft = float(lastProgram - timestamp) / (24 * 60 * 60) self._logger.warning( "Currently %.1f days of Epg data in database." % ( daysLeft ) ) if timestamp + (24 * 60 * 60) > lastProgram: return False return True
def _haveEnoughEpgData(self): conn = DBConnection() lastProgram = EpgProgram.getTimestampLastProgram(conn) timestamp = getTimestamp() if timestamp < lastProgram: daysLeft = float(lastProgram - timestamp) / (24 * 60 * 60) self._logger.warning( "Currently %.1f days of Epg data in database." % (daysLeft)) if timestamp + (24 * 60 * 60) > lastProgram: return False return True
def run( self ): while self._running: self._event.wait() if self._running: try: self._grabAll() self._lastUpdate = getTimestamp() if not self._haveEnoughEpgData(): self._logger.warning( "Updated Epg, but there is still not enough data available.") except: self._logger.error( "run: unexcepted error: %s" % ( sys.exc_info()[0] ) ) # Request a reschedule Scheduler().requestReschedule() self._event.clear()
def getEpgInfo( self ): self._logger.debug( "getEpgInfo()" ) timestampLastProgram = getTimestamp() timestampLastUpdate = 0 numPrograms = 0; conn = DBConnection() if conn: timestampLastProgram = EpgProgram.getTimestampLastProgram( conn ) numPrograms = EpgProgram.getNumberOfPrograms( conn ) if aminopvr.providers.epgProvider: epgProvider = aminopvr.providers.epgProvider() timestampLastUpdate = epgProvider.getLastUpdate() return self._createResponse( API.STATUS_SUCCESS, { "provider": "", "num_programs": numPrograms, "last_update": timestampLastUpdate, "last_program": timestampLastProgram } )
def run(self): while self._running: self._event.wait() if self._running: try: self._grabAll() self._lastUpdate = getTimestamp() if not self._haveEnoughEpgData(): self._logger.warning( "Updated Epg, but there is still not enough data available." ) except: self._logger.error("run: unexcepted error: %s" % (sys.exc_info()[0])) # Request a reschedule Scheduler().requestReschedule() self._event.clear()
def _timerCallback( self, event, arguments ): now = getTimestamp() expiredWatchdogId = None with self._watchdogLock: for watchdogId in self._watchdogs: watchdog = self._watchdogs[watchdogId] if watchdog["lastkick"] != 0 and watchdog["lastkick"] < now: expiredWatchdogId = watchdogId break if expiredWatchdogId != None: with self._watchdogLock: watchdog = self._watchdogs[expiredWatchdogId] self._logger.warning( "Watchdog %s not kicked in time" % ( watchdogId ) ) if "callback" in watchdog: callback = watchdog["callback"] callback()
def getEpgInfo(self): self._logger.debug("getEpgInfo()") timestampLastProgram = getTimestamp() timestampLastUpdate = 0 numPrograms = 0 conn = DBConnection() if conn: timestampLastProgram = EpgProgram.getTimestampLastProgram(conn) numPrograms = EpgProgram.getNumberOfPrograms(conn) if aminopvr.providers.epgProvider: epgProvider = aminopvr.providers.epgProvider() timestampLastUpdate = epgProvider.getLastUpdate() return self._createResponse( API.STATUS_SUCCESS, { "provider": "", "num_programs": numPrograms, "last_update": timestampLastUpdate, "last_program": timestampLastProgram })
def kick( self, watchdogId, kick ): with self._watchdogLock: if watchdogId in self._watchdogs: self._watchdogs[watchdogId]["lastkick"] = getTimestamp() + kick else: self._logger.error( "Watchdog %s does not exists" % ( watchdogId ) )