0.24 Python bindings/Connection Handlers

From MythTV Official Wiki
Revision as of 16:23, 16 August 2010 by Wagnerrp (talk | contribs) (Frontend)

Jump to: navigation, search

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
groupname=None <string>
hostname=None <string>
outputs
StorageGroup generator
description
The two optional arguments can be used to filter the available storage groups.
>>> db = MythDB()
>>> db.getStorageGroup(groupname='Videos').next()
<StorageGroup 'myth://Videos@mythbe/mnt/mythtv/videos/' at 0x804e7d560>

cursor

inputs
log=None <MythLog object>
outputs
LoggedCursor object
description
Returns a cursor for direct database access

MythDB

searchRecorded

inputs
All inputs are optional, and can be mixed and matched.

title
autoexpire
watched
closecaptioned
generic

subtitle
commflagged
storagegroup
partnumber
cast

chanid
stars
category_type
parttotal
livetv

starttime
recgroup
airdate
seriesid
basename

progstart
playgroup
stereo
showtype
syndicatedepisodenumber

category
duplicate
subtitled
programid
 

hostname
transcoded
hdtv
manualid
 

outputs
Recorded generator
description
Returns multiple recordings matching the given data
>>> db.searchRecorded(title='Chuck')
>>> db.searchRecorded(category='Documentary', hdtv=True)

searchOldRecorded

inputs
All inputs are optional, and can be mixed and matched.

title
category
generic

subtitle
seriesid
recstatus

chanid
programid
 

starttime
station
 

endtime
duplicate
 

outputs
OldRecorded generator
description
Returns multiple old recordings matching the given data

searchJobs

inputs
All inputs are optional, and can be mixed and matched.

chanid
title

starttime
subtitle

type
flags

status
olderthan

hostname
newerthan

outputs
Job generator
description
Returns multiple job entries matching the given data

searchGuide

inputs
All inputs are optional, and can be mixed and matched.

chanid
category
subtitled
seriesid
syndicatedepisodenumber

starttime
airdate
hdtv
originalairdate
 

endtime
stars
closecaptioned
showtype
 

title
previouslyshown
partnumber
programid
 

subtitle
stereo
parttotal
generic
 

outputs
Guide generator
description
Returns multiple guide programs matching the given data

searchRecord

inputs
All inputs are optional, and can be mixed and matched.

type
enddate
recgroup

chanid
title
station

starttime
subtitle
seriesid

startdate
category
programid

endtime
profile
playgroup

outputs
OldRecorded generator
description
Returns multiple recording rules matching the given data

searchInternetContent

inputs
All inputs are optional, and can be mixed and matched.

feedtitle
url
width
ondate
country

title
type
height
olderthan
description

subtitle
author
language
newerthan
 

season
rating
podcast
longerthan
 

episode
player
downloadable
shorterthan
 

outputs
InternetContentArticles generator
description
Returns multiple internet video entries matching the given data

getFrontends

inputs
outputs
generator of active Frontends
description
this tests all frontends listed in the database, and returns those that respond properly to a connection

getFrontend

inputs
host <string>
outputs
Frontend object
description
this returns a Frontend object for a single frontend defined in the database

MythVideo

scanStorageGroups

inputs
deleteold=True <boolean>
outputs
(newvids, oldvids) <list of Video objects>
description
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.

searchVideos

inputs
All inputs are optional, and can be mixed and matched.

title
directory
category

subtitle
year
insertedbefore

season
cast
insertedafter

episode
genre
 

host
country
 

outputs
Video generator
description
Returns multiple videometadata entries matching the given data

MythMusic

searchMusic

inputs
All inputs are optional, and can be mixed and matched.

name
year
bitrate

track
genre
 

disc_number
rating
 

artist
format
 

album
sample_rate
 

outputs
Music generator
description
Returns multiple music entries matching the given data

MythProto Connections

MythBE

backendCommand

inputs
command <string>
outputs
response <string>
description
This method sends a low level string to the backend, and returns the response.

getRecording

inputs
chanid <str or int>
starttime <datetime>
outputs
None -- if recording not found
Program object
description
Returns information for a single recording

deleteRecording

inputs
program <Program object>
force=False <boolean>
description
Informs the backend to delete the recording using whatever mechanism was selected

forgetRecording

inputs
program <Program object>
description
Informs the backend to mark a recording as re-recordable

deleteFile

inputs
relative file path <string>
storage group name <string>
description
Delete a single managed file on the backend

getHash

inputs
relative file path <string>
storage group name <string>
outputs
file hash <string>
description
Calculate the hash value for a managed file

reschedule

inputs
recordid=-1 <int>
wait=False <boolean>
description
Issue a scheduler run on all rules, or on one specific rule if other than '-1'. Will optionally wait for the scheduler to finish before returning.

fileExists

| relative path to file
sgroup='Default' (optional) | None or full path to file | Searches storage groups on the backend for given file

download

| url | DownloadFileTransfer object | Starts a managed download on the backend to the Temp storage group, and returns a file object. The downloaded file will be automatically deleted when the file is closed.

downloadTo

| url
storage group
relative path to file
openfile=False (optional) | None or DownloadFileTransfer object (if openfile is True) | Starts a managed download on the backend to the specified location. Optionally opens the new file for reading.

allocateEventLock

| regular expression | EventLock object | Opens a lock object that cannot be acquired until an event matching the regular expression has been received.

getPendingRecordings

outputs
list of Program objects
description
Returns a list of programs scheduled to be recorded

getScheduledRecordings

outputs
list of Program objects
description
Returns a list of programs scheduled to be recorded

getUpcomingRecordings

outputs
list of Program objects
description
Returns a list of programs scheduled to be recorded, filtered for only those that will be recorded

getConflictedRecordings

outputs
list of Program objects
description
Returns a list of programs scheduled to be recorded, filtered for only those with scheduling conflicts

getRecorderList

outputs
list of integers
description
Returns a list of defined card IDs

getFreeRecorderList

outputs
list of integers
description
Returns a list of available card IDs

lockTuner

inputs
id=None <int>
outputs
(ID <int>, video node <string>, audio node <string>, VBI node <string>)
error value <int>
description
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
id=None <int>
description
Free all tuners currently locked by this connection, or one specific tuner. This is automatically run when the connection is closed.

getCurrentRecording

inputs
recorder <int>
outputs
Program object
description
Returns the program currently being recorded by the given ID.

isRecording

inputs
recorder <int>
outputs
isrecording <boolean>
description
Returns True or False whether the recorder is actively being used.

isActiveBackend

inputs
hostname <string>
outputs
isactive <boolean>
description
Returns True or False whether the provided host is connected as a backend.

getRecordings

outputs
list of Program objects
description
Returns a list of existing recordings.

getExpiring

outputs
list of Program objects
description
Returns a list of existing recordings nearing expiration.

getCheckfile

inputs
program <Program object>
outputs
absolute path <string>
error code <int>
description
Returns the path to the recording on the backend.

getFreeSpace

inputs
all=False <boolean>
outputs
list of FreeSpace objects
description
Returns information about the recording directories on the local or all backends.

getFreeSpaceSummary

outputs
(total space, used space) <int KB>
description
Returns information about disk usage.

getLoad

outputs
(1, 5, 15) <int>

getUptime

outputs
uptime <int secs>

walkSG

getSGList

getSGFile

getLastGuideData

outputs
date of last guide data <datetime>

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

Command Inputs Returns Description
_queryObject
_query
_queryTree
getConnectionInfo
getServDesc
getHosts
getKeys
getSetting
getProgramGuide
getProgramDetails
getChannelIcon
getRecorded
getExpiring
getInternetSources

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