class Channel(DBDataWrite): """Channel(chanid=None, db=None) -> Channel object""" _defaults = { 'icon': 'none', 'videofilters': '', 'callsign': u'', 'xmltvid': '', 'recpriority': 0, 'contrast': 32768, 'brightness': 32768, 'colour': 32768, 'hue': 32768, 'tvformat': u'Default', 'visible': 1, 'outputfilters': '', 'useonairguide': 0, 'atsc_major_chan': 0, 'tmoffset': 0, 'default_authority': '', 'commmethod': -1, 'atsc_minor_chan': 0, 'last_record': datetime(1900, 1, 1) } def __str__(self): if self._wheredat is None: return u"<Uninitialized Channel at %s>" % hex(id(self)) return u"<Channel '%s','%s' at %s>" % \ (self.chanid, self.name, hex(id(self))) def __repr__(self): return str(self).encode('utf-8')
class Record(DBDataWrite, RECTYPE, CMPRecord): """ Record(id=None, db=None) -> Record object """ _defaults = { 'type': RECTYPE.kAllRecord, 'title': u'Unknown', 'subtitle': '', 'description': '', 'category': '', 'station': '', 'seriesid': '', 'search': 0, 'last_record': datetime(1900, 1, 1), 'next_record': datetime(1900, 1, 1), 'last_delete': datetime(1900, 1, 1) } def __str__(self): if self._wheredat is None: return u"<Uninitialized Record Rule at %s>" % hex(id(self)) return u"<Record Rule '%s', Type %d at %s>" \ % (self.title, self.type, hex(id(self))) def __repr__(self): return str(self).encode('utf-8') def create(self, data=None, wait=False): """Record.create(data=None) -> Record object""" DBDataWrite._create_autoincrement(self, data) FileOps(db=self._db).reschedule(self.recordid, wait) return self def delete(self, wait=False): DBDataWrite.delete(self) FileOps(db=self._db).reschedule(self.recordid, wait) def update(self, *args, **keywords): wait = keywords.get('wait', False) DBDataWrite.update(self, *args, **keywords) FileOps(db=self._db).reschedule(self.recordid, wait) def getUpcoming(self, deactivated=False): recstatus = None if not deactivated: recstatus = Program.rsWillRecord return FileOps(db=self._db)._getSortedPrograms('QUERY_GETALLPENDING', header=1, recordid=self.recordid, recstatus=recstatus) @classmethod def fromGuide(cls, guide, type=RECTYPE.kAllRecord, wait=False): if datetime.now() > guide.endtime: raise MythError('Cannot create recording rule for past recording.') rec = cls(None, db=guide._db) for key in ('chanid', 'title', 'subtitle', 'description', 'category', 'seriesid', 'programid'): rec[key] = guide[key] rec.startdate = guide.starttime.date() rec.starttime = guide.starttime - datetime.combine( rec.startdate, time()) rec.enddate = guide.endtime.date() rec.endtime = guide.endtime - datetime.combine(rec.enddate, time()) rec.station = Channel(guide.chanid, db=guide._db).callsign rec.type = type return rec.create(wait=wait) @classmethod def fromProgram(cls, program, type=RECTYPE.kAllRecord, wait=False): if datetime.now() > program.endtime: raise MythError('Cannot create recording rule for past recording.') rec = cls(None, db=program._db) for key in ('chanid', 'title', 'subtitle', 'description', 'category', 'seriesid', 'programid'): rec[key] = program[key] rec.station = program.callsign rec.startdate = program.starttime.date() rec.starttime = program.starttime - datetime.combine( rec.startdate, time()) rec.enddate = program.endtime.date() rec.endtime = program.endtime - datetime.combine(rec.enddate, time()) if program.recordid: rec.parentid = program.recordid if program.recstatus == RECTYPE.kNotRecording: rec.type = RECTYPE.kOverrideRecord else: rec.type = RECTYPE.kDontRecord else: rec.type = type return rec.create(wait=wait) @classmethod def fromPowerRule(cls, title='unnamed (Power Search)', where='', args=None, join='', db=None, type=RECTYPE.kAllRecord, searchtype=RECSEARCHTYPE.kPowerSearch, wait=False): if type not in (RECTYPE.kAllRecord, RECTYPE.kFindDailyRecord, RECTYPE.kFindWeeklyRecord, RECTYPE.kFindOneRecord): raise MythDBError("Invalid 'type' set for power recording rule.") rec = cls(None, db=db) if args is not None: where = rec._db.literal(where, args) now = datetime.now() rec.starttime = now.time() rec.endtime = now.time() rec.startdate = now.date() rec.enddate = now.date() rec.title = title rec.description = where rec.subtitle = join rec.type = type rec.search = searchtype return rec.create(wait=wait)