Ticket #6678: pyth.update4.patch

File pyth.update4.patch, 8.7 KB (added by Raymond Wagner <raymond@…>, 15 years ago)
  • mythtv/bindings/python/MythTV/MythTV.py

     
    1414import socket
    1515import code
    1616from datetime import datetime
     17from time import mktime
    1718
    1819from MythDB import *
    1920from MythLog import *
     
    162163                Returns a list of recorders, or an empty list if none.
    163164                """
    164165                recorders = []
    165                 c = self.db.cursor()
     166                pc = self.db.cursor()
    166167                c.execute('SELECT cardid FROM capturecard')
    167168                row = c.fetchone()
    168169                while row is not None:
     
    220221                else:
    221222                        return False
    222223
     224        def getRecording(self, chanid, starttime):
     225                """
     226                Returns a Program object matching the channel id and start time
     227                """
     228                res = self.backendCommand('QUERY_RECORDING TIMESLOT %d %d' % (chanid, starttime)).split(BACKEND_SEP)
     229                if res[0] == 'ERROR':
     230                        return None
     231                else:
     232                        return Program(res[1:])
     233
     234        def getRecordings(self):
     235                """
     236                Returns a list of all Program objects which have already recorded
     237                """
     238                programs = []
     239                res = self.backendCommand('QUERY_RECORDINGS RECORDING').split('[]:[]')
     240                num_progs = int(res.pop(0))
     241                log.Msg(DEBUG, '%s total recordings', num_progs)
     242                for i in range(num_progs):
     243                        programs.append(Program(res[i * PROGRAM_FIELDS:(i * PROGRAM_FIELDS)
     244                                + PROGRAM_FIELDS]))
     245                return programs
     246
     247        def getCheckfile(self,program):
     248                """
     249                Returns location of recording in file system
     250                """
     251                res = self.backendCommand('QUERY_CHECKFILE[]:[]1[]:[]%s' % program.toString()).split(BACKEND_SEP)
     252                if res[0] == 0:
     253                        return None
     254                else:
     255                        return res[1]
     256
    223257class Recorder:
    224258        """
    225259        Represents a MythTV capture card.
     
    265299                self.callsign = data[6] #chansign
    266300                self.channame = data[7]
    267301                self.filename = data[8] #pathname
    268                 self.fs_high = data[9]
    269                 self.fs_low = data[10]
     302                self.fs_high = int(data[9])
     303                self.fs_low = int(data[10])
    270304                self.starttime = datetime.fromtimestamp(int(data[11])) # startts
    271305                self.endtime = datetime.fromtimestamp(int(data[12])) #endts
    272306                self.duplicate = int(data[13])
     
    303337                self.video_props = data[44]
    304338                self.subtitle_type = data[45]
    305339                self.year = data[46]
     340               
     341                self.filesize = (self.fs_high + (self.fs_low<0))*2**32 + self.fs_low
    306342
     343        def toString(self):
     344                string =            self.title
     345                string += BACKEND_SEP + self.subtitle
     346                string += BACKEND_SEP + self.description
     347                string += BACKEND_SEP + self.category
     348                if self.chanid:
     349                        string += BACKEND_SEP + str(self.chanid)
     350                else:
     351                        string += BACKEND_SEP
     352                string += BACKEND_SEP + self.channum
     353                string += BACKEND_SEP + self.callsign
     354                string += BACKEND_SEP + self.channame
     355                string += BACKEND_SEP + self.filename
     356                string += BACKEND_SEP + str(self.fs_high)
     357                string += BACKEND_SEP + str(self.fs_low)
     358                string += BACKEND_SEP + str(int(mktime(self.starttime.timetuple())))
     359                string += BACKEND_SEP + str(int(mktime(self.endtime.timetuple())))
     360                string += BACKEND_SEP + str(self.duplicate)
     361                string += BACKEND_SEP + str(self.shareable)
     362                string += BACKEND_SEP + str(self.findid)
     363                string += BACKEND_SEP + self.hostname
     364                string += BACKEND_SEP + str(self.sourceid)
     365                string += BACKEND_SEP + str(self.cardid)
     366                string += BACKEND_SEP + str(self.inputid)
     367                string += BACKEND_SEP + str(self.recpriority)
     368                string += BACKEND_SEP + str(self.recstatus)
     369                string += BACKEND_SEP + str(self.recordid)
     370                string += BACKEND_SEP + self.rectype
     371                string += BACKEND_SEP + self.dupin
     372                string += BACKEND_SEP + self.dupmethod
     373                string += BACKEND_SEP + str(int(mktime(self.recstartts.timetuple())))
     374                string += BACKEND_SEP + str(int(mktime(self.recendts.timetuple())))
     375                string += BACKEND_SEP + str(self.repeat)
     376                string += BACKEND_SEP + self.programflags
     377                string += BACKEND_SEP + self.recgroup
     378                string += BACKEND_SEP + str(self.commfree)
     379                string += BACKEND_SEP + self.outputfilters
     380                string += BACKEND_SEP + self.seriesid
     381                string += BACKEND_SEP + self.programid
     382                string += BACKEND_SEP + self.lastmodified
     383                string += BACKEND_SEP + str(self.stars)
     384                string += BACKEND_SEP + self.airdate
     385                string += BACKEND_SEP + str(self.hasairdate)
     386                string += BACKEND_SEP + self.playgroup
     387                string += BACKEND_SEP + str(self.recpriority2)
     388                string += BACKEND_SEP + self.parentid
     389                string += BACKEND_SEP + self.storagegroup
     390                string += BACKEND_SEP + self.audio_props
     391                string += BACKEND_SEP + self.video_props
     392                string += BACKEND_SEP + self.subtitle_type
     393                string += BACKEND_SEP + self.year
     394
     395                return string
     396
    307397if __name__ == '__main__':
    308398        banner = '\'m\' is a MythTV instance.'
    309399        try:
  • mythtv/bindings/python/MythTV/MythDB.py

     
    160160                else:
    161161                        return None
    162162
     163        def setSetting(self, value, data, hostname=None):
     164                """
     165                Sets the value for the given MythTV setting.
     166                """
     167                log.Msg(DEBUG, 'Setting %s for host %s to %s', value, hostname, data)
     168                c = self.db.cursor()
     169                ws = None
     170                ss = None
     171
     172                if hostname is None:
     173                        ws = "WHERE value LIKE ('%s') AND hostname IS NULL" % (value)
     174                        ss = "(value,data) VALUES ('%s','%s')" % (value, data)
     175                else:
     176                        ws = "WHERE value LIKE ('%s') AND hostname LIKE ('%s%%')" % (value, hostname)
     177                        ss = "(value,data,hostname) VALUES ('%s','%s','%s')" % (value, data, hostname)
     178
     179                if c.execute("""UPDATE settings SET data %s LIMIT 1""" % ws) == 0:
     180                        c.execute("""INSERT INTO settings %s""" % ss)
     181                c.close()
     182
     183        def getCast(self, chanid, starttime, roles=None):
     184                """
     185                Returns cast members for a recording
     186                A string for 'roles' will return a tuple of members for that role
     187                A tuple of strings will return a touple containing all listed roles
     188                No 'roles' will return a dictionary of tuples
     189                """
     190                if roles is None:
     191                        c = self.db.cursor()
     192                        length = c.execute("SELECT name,role FROM people,credits WHERE people.person=credits.person AND chanid=%d AND starttime=%d ORDER BY role" % (chanid, starttime))
     193                        if length == 0:
     194                                return ()
     195                        crole = None
     196                        clist = []
     197                        dict = {}
     198                        for name,role in c.fetchall():
     199                                if crole is None:
     200                                        crole = role
     201                                if crole == role:
     202                                        clist.append(name)
     203                                else:
     204                                        dict[crole] = tuple(clist)
     205                                        clist = []
     206                                        clist.append(name)
     207                                        crole = role
     208                        dict[crole] = tuple(clist)
     209                        c.close()
     210                        return dict
     211                elif isinstance(roles,str):
     212                        c = self.db.cursor()
     213                        length = c.execute("SELECT name FROM people,credits WHERE people.person=credits.person AND chanid=%d AND starttime=%d AND role='%s'" % (chanid, starttime, roles))
     214                        if length == 0:
     215                                return ()
     216                        names = []
     217                        for name in c.fetchall():
     218                                names.append(name[0])
     219                        return tuple(names)
     220                elif isinstance(roles,tuple):
     221                        c = self.db.cursor()
     222                        length = c.execute("SELECT name FROM people,credits WHERE people.person=credits.person AND chanid=%d AND starttime=%d AND role IN %s" % (chanid, starttime, roles))
     223                        if length == 0:
     224                                return ()
     225                        names = []
     226                        for name in c.fetchall():
     227                                names.append(name[0])
     228                        return tuple(names)
     229
    163230        def cursor(self):
    164231                return self.db.cursor()
    165232
     233class Job:
     234        jobid = None
     235        chanid = None
     236        starttime = None
     237        host = None
     238        mythdb = None
     239        def __init__(self, *inp):
     240                if len(inp) == 1:
     241                        self.jobid = inp[0]
     242                        self.getProgram()
     243                elif len(inp) == 2:
     244                        self.chanid = inp[0]
     245                        self.starttime = inp[1]
     246                        self.getJobID()
     247                else:
     248                        print("improper input length")
     249                        return None
     250                self.getHost()
     251
     252        def getProgram(self):
     253                if self.mythdb is None:
     254                        self.mythdb = MythDB()
     255                c = self.mythdb.cursor()
     256                c.execute("SELECT chanid,starttime FROM jobqueue WHERE id=%d" % self.jobid)
     257                self.chanid, self.starttime = c.fetchone()
     258                c.close()
     259
     260        def getJobID(self):
     261                if self.mythdb is None:
     262                        self.mythdb = MythDB()
     263                if self.jobid is None:
     264                        c = self.mythdb.cursor()
     265                        c.execute("SELECT id FROM jobqueue WHERE chanid=%d AND starttime=%d" % (self.chanid, self.starttime))
     266                        self.jobid = c.fetchone()[0]
     267                        c.close()
     268                return self.jobid
     269
     270        def getHost(self):
     271                if self.mythdb is None:
     272                        self.mythdb = MythDB()
     273                if self.host is None:
     274                        c = self.mythdb.cursor()
     275                        c.execute("SELECT hostname FROM jobqueue WHERE id=%d" % self.jobid)
     276                        self.host = c.fetchone()[0]
     277                        c.close()
     278                return self.host
     279
     280        def setComment(self,comment):
     281                if self.mythdb is None:
     282                        self.mythdb = MythDB()
     283                c = self.mythdb.cursor()
     284                c.execute("UPDATE jobqueue SET comment='%s' WHERE id=%d" % (comment,self.jobid))
     285                c.close()
     286
     287        def setStatus(self,status):
     288                if self.mythdb is None:
     289                        self.mythdb = MythDB()
     290                c = self.mythdb.cursor()
     291                c.execute("UPDATE jobqueue SET status=%d WHERE id=%d" % (status,self.jobid))
     292                c.close()
     293
    166294if __name__ == '__main__':
    167295        banner = "'mdb' is a MythDB instance."
    168296        try: