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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
Tests all frontends listed in the database, and returns connection objects for all those that respond properly.
|
|
getFrontend
| Inputs
|
Outputs
|
Description
|
| host
|
|
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
|
|
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
|
|
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 |
|
|
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
|
|
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
|
|
|
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
|
|
|
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
|
|
Returns a list of programs scheduled to be recorded.
|
|
getScheduledRecordings
| Inputs
|
Outputs
|
Description
|
| n/a
|
|
Returns a list of programs scheduled to be recorded.
|
|
getUpcomingRecordings
| Inputs
|
Outputs
|
Description
|
| n/a
|
|
Returns a list of programs scheduled to be recorded, filtered for only those that will be recorded.
|
|
getConflictedRecordings
| Inputs
|
Outputs
|
Description
|
| n/a
|
|
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
|
Attempts to lock the specified tuner, or automatically chooses one if none specified. Returns the information about the locked tuner, -1 if no tuners are available, or -2 if the optionally requested tuner is already locked. Note: All locked tuners are automatically unlocked prior to closing the connection to the backend.
|
|
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
|
|
Returns the program currently being recorded by the specified recorder.
|
|
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
|
|
Returns a list of existing recordings.
|
|
getExpiring
| Inputs
|
Outputs
|
Description
|
| n/a
|
|
Returns a list of existing recordings nearing expiration.
|
|
getCheckfile
| Inputs
|
Outputs
|
Description
|
|
|
absolute path
|
Returns the path to the recording on the backend.
|
|
getFreeSpace
| Inputs
|
Outputs
|
Description
|
| all=False
|
|
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
fromUPNP
| Inputs
|
Outputs
|
Description
|
| pin=0
|
credentials dict
|
This method is used to retrieve the database connection information from the backend. It is generally only used for UPnP auto-detection of the backend, and accepts a PIN. Database may contain:
DBUserName DBName |
DBPort SecurityPin |
DBPassword |
|
|
getServDesc
| Inputs
|
Outputs
|
Description
|
| n/a
|
generator of tuples
|
Returns a generator of all available commands and inputs. Each item will be in the form (command, {in:(inputs), out:(outputs)})
|
|
getHosts
| Inputs
|
Outputs
|
Description
|
| n/a
|
hostname list
|
List of all unique hostnames found in the settings table in the database.
|
|
getKeys
| Inputs
|
Outputs
|
Description
|
| n/a
|
key list
|
List of all unique settings keys found in the settings table in the database.
|
|
getSetting
| Inputs
|
Outputs
|
Description
|
| key hostname=None default=None
|
setting or default
|
Returns defined setting, or default if setting does not exist.
|
|
getProgramGuide
| Inputs
|
Outputs
|
Description
|
| starttime endtime startchan numchan=None
|
|
Returns an iterable of Guide objects spanning the time and channel range given. Response is limited to 1000 items.
|
|
getProgramDetails
| Inputs
|
Outputs
|
Description
|
| chanid starttime
|
|
Returns a Program object for a single recording.
|
|
getChannelIcon
| Inputs
|
Outputs
|
Description
|
| chanid
|
image binary
|
None
|
|
getRecorded
| Inputs
|
Outputs
|
Description
|
| descending=True
|
|
Returns a generator that iterates through all recorded programs.
|
|
getExpiring
| Inputs
|
Outputs
|
Description
|
| n/a
|
|
Returns a generator that iterates through all recorded programs in order of expiration.
|
|
getInternetSource
| Inputs
|
Outputs
|
Description
|
| n/a
|
InternetSource iterable
|
Returns a generator that iterates through all internet video grabbers available over the xml interface.
|
|
getPreviewImage
| Inputs
|
Outputs
|
Description
|
| chanid starttime width=None height=None secsin=None
|
InternetSource iterable
|
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
| Inputs
|
Outputs
|
Description
|
| n/a
|
n/a
|
Returns a list of queries in the form (query string, description).
|
|
sendQuery
| Inputs
|
Outputs
|
Description
|
| n/a
|
n/a
|
Sends a query to the backend, returning the unprocessed response.
|
|
getPlay
| Inputs
|
Outputs
|
Description
|
| n/a
|
n/a
|
Returns a list of playback commands in the form (command, description).
|
|
sendPlay
| Inputs
|
Outputs
|
Description
|
| n/a
|
n/a
|
Sends a command to the backend, returning success or failure.
|
|
play
| Inputs
|
Outputs
|
Description
|
| n/a
|
n/a
|
Plays the given media on the frontend. Accepts media of types Recorded, Video, or Program.
|
|
getLoad
| Inputs
|
Outputs
|
Description
|
| n/a
|
1,5,15 load avg
|
None
|
|
getUptime
| Inputs
|
Outputs
|
Description
|
| n/a
|
timedelta
|
None
|
|
getTime
| Inputs
|
Outputs
|
Description
|
| n/a
|
datetime
|
None
|
|
getMemory
| Inputs
|
Outputs
|
Description
|
| n/a
|
memory usage
|
Returns memory usage in the form (totalmem, freemem, totalswap, freeswap) in MB.
|
|