0.24 Python bindings/Connection Handlers

From MythTV Official Wiki
Revision as of 00:24, 5 October 2010 by Wagnerrp (talk | contribs) (MythBE)

Jump to: navigation, search

Contents

Database Connections

shared

All database connection objects share these common utilities.

tablefields

MythDB.tablefields is populated with an object providing information of database table fields. Tables can be selected as an attribute or item, and return a subclass with further information. The subclass can be converted into a list of field names, or information about each field can be accessed.

>>> db = MythDB()
>>> db.tablefields.settings
[u'value', u'data', u'hostname']
>>> db.tablefields.settings.value
{'default': u'', 'null': u'NO', 'type': u'varchar(128)', 'key': u'MUL', 'extra': u''}
>>> db.tablefields.settings.value.null
u'NO'

settings

MythDB.settings is populated with an object providing access to settings table data. Data is accessed through two levels, first the hostname, and then value. The second level supports a '.getall()' method that returns all settings set for that host. Global settings can be accessed through the 'NULL' hostname.

>>> db = MythDB()
>>> db.settings.NULL.DBSchemaVer
u'1262'
>>> db.settings.NULL.getall()
<itertools.izip object at 0x804e4ac20>

getStorageGroup

Inputs Outputs Description
groupname=None
hostname=None
StorageGroup iterable
Returns an iterable of all storagegroup folders matching the optional filter settings.
Example:
>>> db = MythDB()
>>> db.getStorageGroup(groupname='Videos').next()
<StorageGroup 'myth://Videos@mythbe/mnt/mythtv/videos/' at 0x804e7d560>

cursor

Inputs Outputs Description
log=None
LoggedCursor object
Returns a cursor, with an optional log object.
Example:
db = MythDB()
with db as cursor:
    cursor.execute("""select ...""")

log = MythLog('custom log')
with db.cursor(log) as cursor:
    cursor.execute("""insert ...""")

MythDB

searchRecorded

Inputs Outputs Description
**kwargs
Recorded iterable
Returns an iterable of Recorded objects, matching the given search filters. Accepts the following keywords:
title
autoexpire
watched
closecaptioned
generic
hostname
category
subtitle
commflagged
storagegroup
partnumber
cast
transcoded
duplicate
chanid
stars
category_type
parttotal
livetv
hdtv
subtitled
starttime
recgroup
airdate
seriesid
basename
manualid
 
progstart
playgroup
stereo
showtype
syndicatedepisodenumber
programid
 
Example:
>>> db.searchRecorded(title='Chuck')
>>> db.searchRecorded(category='Documentary', hdtv=True)

searchOldRecorded

Inputs Outputs Description
**kwargs
OldRecorded iterable
Returns an iterable of OldRecorded objects, matching the given search filters. Accepts the following keywords:
title
category
generic
subtitle
seriesid
recstatus
chanid
programid
 
starttime
station
 
endtime
duplicate
 

searchJobs

Inputs Outputs Description
**kwargs
Job iterable
Returns an iterable of Job objects, matching the given search filters. Accepts the following keywords:
chanid
title
starttime
subtitle
type
flags
status
olderthan
hostname
newerthan

searchGuide

Inputs Outputs Description
**kwargs
Guide iterable
Returns an iterable of Guide objects, matching the given search filters. Accepts the following keywords:
chanid
category
subtitled
seriesid
syndicatedepisodenumber
starttime
airdate
hdtv
originalairdate
 
endtime
stars
closecaptioned
showtime
 
title
previouslyshown
partnumber
programid
 
subtitle
stereo
parttotal
generic
 

searchRecord

Inputs Outputs Description
**kwargs
Record iterable
Returns an iterable of recording rules, matching the given search filters. Accepts the following keywords:
type
enddate
recgroup
chanid
title
station
starttime
subtitle
seriesid
startdate
category
programid
endtime
profile
playgroup

searchInternetContent

Inputs Outputs Description
**kwargs
Returns an iterable of internet content, matching the given search filters. Accepts the following keywords:
feedtitle
url
width
ondate
country
title
type
height
olderthan
description
subtitle
author
language
newerthan
 
season
rating
podcast
longerthan
 
episode
player
downloadable
shorterthan
 

getFrontends

Inputs Outputs Description
n/a
active Frontend iterable
Tests all frontends listed in the database, and returns connection objects for all those that respond properly.

getFrontend

Inputs Outputs Description
host
Frontend object
Returns a Frontend object, pulling the connection port from the database.

MythVideo

scanStorageGroups

Inputs Outputs Description
deleteold=True
newvids
oldvids
Scans through all storage groups on all accessible hosts, and returns a pair of lists: new content to be added, and old content to be deleted. If `deleteold` is True, the old content has already been deleted, and is just returned for information.

searchRecorded

Inputs Outputs Description
**kwargs
Video iterable
Returns an iterable of Video objects, matching the given search filters. Accepts the following keywords:
title
directory
category
subtitle
year
insertedbefore
season
cast
insertedafter
episode
genre
 
host
country
 

MythMusic

searchMusic

Inputs Outputs Description
**kwargs
Music iterable
Returns an iterable of Music objects, matching the given search filters. Accepts the following keywords:
name
year
bitrate
track
genre
 
disc_number
rating
 
artist
format
 
album
sample_rate
 

MythProto Connections

MythBE

backendCommand

Inputs Outputs Description
command
backend response
This method is low level access to the backend socket. It can be used to send and receive raw strings with the backend. The command and response length is automatically processed and does not have to be provided in the string.

getRecording

Inputs Outputs Description
chanid
starttime
Program object
Returns information for a single recording, or None if no match is found. chanid can be a string or integer, starttime can be any format supported by the datetime class.

deleteRecording

Inputs Outputs Description
Program object
force=False
retcode
Deletes a single recording on the backend, optionally forcing the deletion of database information if the cannot be found. Returns -1 on success, or -2 on failure.

forgetRecording

Inputs Outputs Description
Program object
force=False
n/a
Marks an existing recording as available for re-recording.

deleteFile

Inputs Outputs Description
file
storagegroup
retcode
Manually delete a single file on the backend. file is a path relative to the root of the storage group.

getHash

Inputs Outputs Description
file
storagegroup
file hash
Calculate the hash value for a managed file. file is a path relative to the root of the storage group.

reschedule

Inputs Outputs Description
recordid=-1
wait=False
n/a
Issues a scheduler run, optionally limiting it to a single rule. Optionally wait for the scheduler run to complete before returning.

fileExists

Inputs Outputs Description
file
sgroup='Default'
absolute path
Searches for a file on the backend, returning the full path, or None if not found.

download

Inputs Outputs Description
url
file object
Issues a download on the backend to a temporary path, and provides a file object to access it. File will be deleted automatically when the object is closed.

downloadTo

Inputs Outputs Description
url
storagegroup
file path
openfile=False
file object
Issues a download on the backend to the defined storagegroup and relative path. Optionally provides a file object to the in-progress download.

allocateEventLock

Inputs Outputs Description
compiled regex
mutex object
Creates a new mutex which will remain locked until the specified event has been received.

getPendingRecordings

Inputs Outputs Description
n/a
Program list
Returns a list of programs scheduled to be recorded.

getScheduledRecordings

Inputs Outputs Description
n/a
Program list
Returns a list of programs scheduled to be recorded.

getUpcomingRecordings

Inputs Outputs Description
n/a
Program list
Returns a list of programs scheduled to be recorded, filtered for only those that will be recorded.

getConflictedRecordings

Inputs Outputs Description
n/a
Program list
Returns a list of programs scheduled to be recorded, filtered for only those with scheduling conflicts.

getRecorderList

Inputs Outputs Description
n/a
list of integers
Returns a list of defined card IDs.

getFreeRecorderList

Inputs Outputs Description
n/a
list of integers
Returns a list of defined card IDs.

lockTuner

Inputs Outputs Description
int=None
card id
video node
audio node
VBI node
Returns the information about the locked tuner, -1 if no tuners are available, or -2 if the optionally requested tuner is already locked.

freeTuner

Inputs Outputs Description
int=None
n/a
Free all tuners currently locked by this connection, or one specific tuner. This is automatically run when the connection is closed.

getCurrentRecording

Inputs Outputs Description
recorder
Program object
Free all tuners currently locked by this connection, or one specific tuner. This is automatically run when the connection is closed.

isRecording

Inputs Outputs Description
recorder
boolean
Returns whether the recorder is actively being used.

isActiveBackend

Inputs Outputs Description
hostname
boolean
Returns whether the hostname is connected as a backend.

getRecordings

Inputs Outputs Description
n/a
Program list
Returns a list of existing recordings.

getExpiring

Inputs Outputs Description
n/a
Program list
Returns a list of existing recordings nearing expiration.

getCheckfile

Inputs Outputs Description
Program object
absolute path
Returns the path to the recording on the backend.

getFreeSpace

Inputs Outputs Description
all=False
FreeSpace object
Returns information about the recording directories on the local or all backends.

getFreeSpaceSummary

Inputs Outputs Description
n/a
total space
used space
Returns information about disk usage (in KB).

getLoad

Inputs Outputs Description
n/a
1,5,15 averages
Returns the load averages.

getUptime

Inputs Outputs Description
n/a
uptime
Returns uptime, in seconds.

walkSG

Inputs Outputs Description
n/a
n/a
None

getSGList

Inputs Outputs Description
n/a
n/a
None

getSGFile

Inputs Outputs Description
n/a
n/a
None

getLastGuideData

Inputs Outputs Description
n/a
datetime
Pulls data of last guide data available in the database.

BEEventMonitor

This class is intended for development use only. Its purpose is to connect to the backend, listen for any events, and print them in raw form to the terminal.

MythSystemEvent

Other Connections

MythXML

getConnectionInfo

inputs
pin=0
outputs
{DBUserName, DBPort, DBPassword, DBName, SecurityPin}
description
This method is used to retrieve the database connection information from the backend. It is generally only used for UPNP auto-detection.

getServDesc

outputs
generator of (command <string>, {in <list of arguments>, out <list of arguments>})
description
Returns a generator of all available commands and inputs.

getHosts

outputs
list of hostnames <string>

getKeys

outputs
list of settings <string>

getSetting

inputs
key <string>
hostname=None <string>
default=None
outputs
response <string>
default
description
returns defined setting, or `default` input if no setting exists

getProgramGuide

inputs
starttime <datetime>
endtime <datetime>
startchan <int or string>
numchan=None <int or string>
outputs
Guide generator
description
Returns a generator that iterates through all programs between the given times and range of channels.

getProgramDetails

inputs
chanid <int or string>
starttime <datetime>
outputs
Program object

getChannelIcon

inputs
chanid <int or string>
outputs
image binary

getRecorded

inputs
descending=True <boolean>
outputs
Program generator
description
Returns a generator that iterates through all recorded programs

getExpiring

outputs
Program generator
description
Returns a generator that iterates through all recorded programs in order of expiration

getInternetSources

outputs
InternetSource generator
description
Returns a generator that iterates through all internet video grabbers available over the xml interface

getPreviewImage

inputs
chanid <int or string>
starttime <datetime>
width=None <int or string>
height=None <int or string>
secsin=None <int or string>
outputs
image binary
description
Polls the preview generator for a preview image.

Frontend

jump

Frontend.jump is populated with an object intended for use sending jumppoints to the frontend. The '.list()' and '.dict()' methods return the available jumppoints, and jumps can be sent by accessing a jumppoint as an attribute or item. Returns True on successful jump.

>>> fe = Frontend.fromUPNP().next()
>>> fe.sendQuery('location')
'mainmenu'
>>> fe.jump.mythvideo
True
>>> fe.sendQuery('location')
'mythvideo'
>>> fe.jump['playbackrecordings']
True
>>> fe.sendQuery('location')
'playbackbox'

key

Frontend.key is populated with an object intended for use sending keypresses to the frontend. The '.list()' method returns a list of special keys allowed, in addition to any alphanumeric keys. Keypresses can be sent as an attribute or item, and accept both literal strings and ordinal scancodes. Returns True on success.

>>> fe = Frontend.fromUPNP().next()
>>> fe.key
['#', '$', '%', '&', '(', ')', ..... ,'tab', 'underscore', 'up', '|']
>>> fe.key.escape
True
>>> fe.key['enter']
True
>>> fe.key[68]
True

getQuery

output
list of (location, description) <string>
description
returns all available data queries from the backend

sendQuery

input
query <string>
output
response <string>
description
sends a query to the backend, returning the unprocessed result

getPlay

output
list of (command, description) <string>
description
returns all available playback commands from the backend

sendPlay

input
command <string>
output
response <string>
description
sends a command to the backend, returning success or failure

play

input
media <Recorded, Program, Video>
output
boolean
description
plays the given media object on the frontend

getLoad

output
(1, 5, 15) <float>
description
returns the 1/5/15 load averages

getUptime

output
timedelta
description
returns the system uptime

getTime

output
datetime
description
returns the current system time

getMemory

output
{totalmem, freemem, totalswap, freeswap} <int MB>
description
returns a dictionary of memory and swap usage in megabytes