diff --git a/mythtv/bindings/python/MythTV/database.py b/mythtv/bindings/python/MythTV/database.py index 332d4bb..54538e0 100644 --- a/mythtv/bindings/python/MythTV/database.py +++ b/mythtv/bindings/python/MythTV/database.py @@ -1088,6 +1088,16 @@ class DBCache( MythSchema ): def gethostname(self): return self.dbconn['LocalHostName'] + def getMasterBackend(self): + ip = self.settings.NULL.MasterServerIP + with self as cursor: + if cursor.execute("""SELECT hostname FROM settings + WHERE value='BackendServerIP' + AND data=?""", [ip]) == 0: + # no match found + raise MythDBError(MythError.DB_SETTING, 'BackendServerIP', ip) + return cursor.fetchone()[0] + def getStorageGroup(self, groupname=None, hostname=None): """ obj.getStorageGroup(groupname=None, hostname=None) diff --git a/mythtv/bindings/python/MythTV/dataheap.py b/mythtv/bindings/python/MythTV/dataheap.py index 2817f55..5a0cc98 100644 --- a/mythtv/bindings/python/MythTV/dataheap.py +++ b/mythtv/bindings/python/MythTV/dataheap.py @@ -28,6 +28,7 @@ class Record( CMPRecord, DBDataWrite, RECTYPE ): 'inetref':'', 'next_record':datetime(1900,1,1), 'season':0, 'last_delete':datetime(1900,1,1), 'episode':0} + _artwork = None def __str__(self): if self._wheredat is None: @@ -60,6 +61,24 @@ class Record( CMPRecord, DBDataWrite, RECTYPE ): return FileOps(db=self._db)._getSortedPrograms('QUERY_GETALLPENDING', header=1, recordid=self.recordid, recstatus=recstatus) + @property + def artwork(self): + if self._artwork is None: + if (self.inetref is None) or (self.inetref == ""): + raise MythError("Record cannot have artwork without inetref") + + try: + self._artwork = \ + RecordedArtwork((self.inetref, self.season), self._db) + except MythError: + #artwork does not exist, create new + self._artwork = RecordedArtwork(db=self._db) + self._artwork.inetref = self.inetref + self._artwork.season = self.season + self._artwork.host = self._db.getMasterBackend() + self._artwork.create() + return self._artwork + @classmethod def fromGuide(cls, guide, type=RECTYPE.kAllRecord, wait=False): if datetime.now() > guide.endtime: @@ -146,6 +165,7 @@ class Recorded( CMPRecord, DBDataWrite ): 'profile':'No', 'duplicate':1, 'transcoded':0, 'watched':0, 'storagegroup':'Default', 'inetref':'', 'season':0, 'episode':0} + _artwork = None class _Cast( DBDataCRef ): _table = ['recordedcredits','people'] @@ -237,6 +257,25 @@ class Recorded( CMPRecord, DBDataWrite ): """Recorded.getRecordedProgram() -> RecordedProgram object""" return RecordedProgram.fromRecorded(self) + @property + def artwork(self): + if self._artwork is None: + if (self.inetref is None) or (self.inetref == ""): + raise MythError("Recorded cannot have artwork without inetref") + + try: + self._artwork = \ + RecordedArtwork((self.inetref, self.season), self._db) + except MythError: + #artwork does not exist, create new + self._artwork = RecordedArtwork(db=self._db) + self._artwork.inetref = self.inetref + self._artwork.season = self.season + self._artwork.host = self._db.getMasterBackend() + self._artwork.create() + return self._artwork + + def formatPath(self, path, replace=None): """ Recorded.formatPath(path, replace=None) -> formatted path string @@ -469,19 +508,49 @@ class RecordedArtwork( DBDataWrite ): """ RecordedArtwork(data=None, db=None) """ - _key = ('inetref', 'season', 'host') + _key = ('inetref', 'season') _defaults = {'inetref':'', 'season':0, 'host':'', 'coverart':'', 'fanart':'', 'banner':''} + class _open(object): + def __init__(self, func): + self.__name__ = func.__name__ + self.__module__ = func.__module__ + self.__doc__ = """RecordedArtwork.%s(mode='r', nooverwrite=False) + -> file or FileTransfer object""" % self.__name__ + self.type, self.sgroup = \ + {'Banner':('banner','Banners'), + 'Coverart':('coverart','Coverart'), + 'Fanart':('fanart','Fanart')}[self.__name__[4:]] + def __get__(self, inst, own): + self.inst = inst + return self + + def __call__(self, mode='r', nooverwrite=False): + if self.inst.host == '': + raise MythFileError('File access only works ' + 'with Storage Group content') + return ftopen('myth://%s@%s/%s' % ( self.sgroup, + self.inst.host, + self.inst[self.type]), + mode, False, nooverwrite, self.inst._db) + def __str__(self): if self._wheredat is None: return u"" % hex(id(self)) - return u"" % \ + return u"" % \ (self.inetref, self.season, hex(id(self))) def __repr__(self): return str(self).encode('utf-8') + @_open + def openCoverart(self,mode='r',nooverwrite=False): pass + @_open + def openBanner(self,mode='r',nooverwrite=False): pass + @_open + def openFanart(self,mode='r',nooverwrite=False): pass + class Job( DBDataWrite, JOBTYPE, JOBCMD, JOBFLAG, JOBSTATUS ): """ Job(id=None, db=None) -> Job object