Difference between revisions of "0.23 Python bindings"

From MythTV Official Wiki
Jump to: navigation, search
m
m (Add category (Python))
Line 133: Line 133:
 
==MythError(*args)==
 
==MythError(*args)==
 
=[[Python bindings/Advanced|Advanced Objects]]=
 
=[[Python bindings/Advanced|Advanced Objects]]=
 +
[[Category:Python]]

Revision as of 20:52, 1 February 2010

The Python bindings received a rewrite in the 0.23 development cycle.

All objects which may use the database for any purpose will have a 'db' keyword input, providing it an existing database connection to use. This allows one to specify the database to use at the beginning of the application, and have it carried through out all subsequent calls. The input will accept any object or subclass of type 'MythDBConn'.

Contents

Data Objects

Program(raw)

FreeSpace(raw)

StorageGroup(id=None, db=None, raw=None)

Guide(data=None, db=None, raw=None)

Job(id=None, chanid=None, starttime=None, db=None, raw=None)

Channel(chanid=None, db=None, raw=None)

Video(id=None, db=None, raw=None)

Recorded(data=None, db=None, raw=None)

RecordedProgram(data=None, db=None, raw=None)

OldRecorded(data=None, db=None, raw=None)

Connection Objects

MythDB(db=None, args=None, **kwargs)

This is the database connection class. It accepts connection settings through the 'args' input as a tuple of tuples, or through several keywords. The usable keywords are 'DBHostName', 'DBName', 'DBUserName', 'DBPassword', 'DBPort', and 'SecurityPin'.

>>> db1 = MythDB(args=(('DBHostname','mybackend'),
                  ('DBName','mythconverg'),
                  ('DBUserName','mythtv'),
                  ('DBPassword','mythtv')))
>>> db2 = MythDB(DBHostname='mybackend',  DBName='mythconverg',
            DBUserName='mythtv',     DBPassword='mythtv')
>>> db3 = MythDB(db=db2)

If the connection settings are not given by the user, they are searched for in '~/.mythtv/config.xml'. If not found there, the object will attempt to find a backend on the network over UPnP, using 0000 if 'SecurityPin' has not been defined.

settings

This is a pseudo-variable with access to the settings table. It accepts two values, the hostname (or 'NULL') and the setting name, and can take them as keys or attributes.

>>> db.settings.NULL.DBSchemaVer
u'1252'
>>> db.settings['mybackend']['BackendServerPort']
u'6543'
>>> db.settings.mybackend.BackendServerPort = 6553

tablefields

This is another pseudo-variable providing access to the database field names.

>>> db.tablefields.jobqueue
[u'id', u'chanid', u'starttime', u'inserttime', u'type', u'cmds', u'flags', u'status', u'statustime', u'hostname', u'args', u'comment', u'schedruntime']
>>> db.tablefields['storagegroup']
[u'id', u'groupname', u'hostname', u'dirname']

cursor(log=None)

This returns a cursor for manual database access. Queries are automatically logged, and an initialized logging object can be specified.

getStorageGroup(groupname=None, hostname=None)

Return a tuple of StorageGroup objects, optionally filtering by groupname and hostname.

>>> db.getStorageGroup(groupname='Videos')
(<StorageGroup 'myth://Videos@mybackend/mnt/mythtv/store/media/video/' at 0x8031eff90,)

getFrontends()

Attempt to connect to all frontends listed in the database, and return a tuple of Frontend objects to all successfully connected to.

getFrontend(host)

Attempt to connect to a single frontend, using the port defined in the database for the given hostname.

getChannels()

Return a tuple of Channel objects.

getRecorded(title=None, subtitle=None, chanid=None, starttime=None, progstart=None)

Return a single Recorded object, or None, matching the specified search parameters.

searchRecorded(**kwargs)

Return a tuple of Recorded objects, matching the specified search parameters. Accepts the following keywords: title, subtitle, chanid, starttime, progstart, category, hostname, autoexpire, commflagged, stars, recgroup, playgroup, duplicate, transcoded, watched, storagegroup, airdate, stereo, subtitled, hdtv, closecaptioned, partnumber, parttotal, seriesid, showtype, syndicatedepisodenumber, programid, manualid, generic, cast, livetv.

>>> db.searchRecorded(cast='Kiefer Sutherland')
(<Recorded '24','2010-01-18 20:00:00' at 0x803922850>, <Recorded '24','2010-01-25 21:00:00' at 0x803924310>)

>>> db.searchRecorded(title='24', subtitle='Day 8: 6:00PM - 8:00PM') (<Recorded '24','2010-01-18 20:00:00' at 0x80391ff50>,)

searchOldRecorded(**kwargs)

Return a tuple of OldRecorded objects, matching the specified search parameters. Accepts the following keywords: title, subtitle, chanid, starttime, endtime, category, seriesid, programid, station, duplicate, generic.

searchJobs(**kwargs)

Return a tuple of Job objects, matching the specified search parameters. Accepts the following keywords: chanid, starttime, type, status, hostname, title, subtitle, flags, olderthan, newerthan.

searchGuide(**kwargs)

Return a tuple of Guide objects, matching the specified search parameters. Accepts the following keywords: chanid, starttime, endtime, title, subtitle, category, airdate, stars, previouslyshown, stereo, subtitled, hdtv, closecaptioned, partnumber, parttotal, seriesid, originalairdate, showtype, syndicatedepisodenumber, programid, generic, startbefore, startafter, endbefore, endafter.

MythBE(backend=None, type='Monitor', db=None, single=False)

This is the backend socket connection class. It accepts a 'backend' as a hostname, or IP, otherwise using the master backend. Port number is always pulled from the database. Type can be either 'Monitor' or 'Playback', to determine whether or not the backend is allowed to shut down. This class provides automatic connection sharing between multiple instances, and 'single' tells the class to always create a new connection.

getPendingRecordings()

getScheduledRecordings()

getUpcomingRecordings()

getRecorderList()

getFreeRecorderList()

lockTuner(id=None)

freeTuner(id=None)

getCurrentRecording(recorder)

isRecording(recorder)

isActiveBackend(hostname)

getRecording(chanid, starttime)

getRecordings()

getExpiring()

getCheckfile(program)

getFreeSpace(all=False)

getFreeSpaceSummary()

getLoad()

getUptime()

walkSG(host, sg, top)

getSGList(host, sg, path, filenamesonly=False)

getSGFile(host, sg, path)

getLastGuideData()

Frontend(host, port)

getJump()

getKey()

getQuery()

getPlay()

sendJump(jumppoint)

sendKey(key)

sendQuery(query)

sendPlay(play)

MythVideo()

scanStorageGroups(returnnew=True, deleteold=True)

searchVideos(**kwargs)

getVideo(**kwargs)

MythXML(backend=None, db=None)

_query(path=None, **kwargs)

_queryTree(path=None, **kwargs)

System Objects

Grabber(path=None, setting=None, db=None)

append(*args)

command(*args)

VideoGrabber(mode, lang='en', db=None)

setOverride(data)

searchTitle(title, year=None)

searchEpisode(title, subtitle)

getData(inetref, season=None, episode=None, additional=False)

NetVisionGrabber(name, type, db=None)

searchXML(title, page=1)

treeXML()

setUpdated()

Accessory Objects

MythLog(module='pythonbindings', lstr=None, lbit=None, db=None, logfile=None)

log(level, message, detail=None)

MythError(*args)

Advanced Objects