0.24 Python bindings/System Calls

From MythTV Official Wiki
Revision as of 18:28, 6 August 2010 by Wagnerrp (talk | contribs) (add examples)

Jump to: navigation, search

This page is for classes intended for use calling external functions and programs.

System

This class is the base handler for external calls. The class is designed to take function paths from an entry in the settings table, but direct paths can be provided instead.

Inputs are:

  • path=None - absolute path to external executable
  • setting=None - name of value in settings table to use for path
  • db=None - will read from config.xml if not provided

Either `path` or `setting` must be defined.

>>> s = System(path='echo')
>>> s.path
'echo'

append

Accepts one or more strings as arguments, and appends them to the internal path. Can be used to add an argument to a call that is to be used repeatedly.

>>> s.append('some appended','"string"')
>>> s.path
'echo some appended "string"'

command

Accepts one or more strings as arguments, and appends them to the path for this run only. Method returns the terminal output from the run. If an errorcode not equal to one is returned, the method will error, and `returncode` and `stderr` attributes will be populated for inspection.

>>> s.command('some string')
'some appended string some string\n'
>>> s.command('another','string')
'some appended string another string\n'

Grabber

This class is a modified System class, following the MythTV Universal Metadata Format. This class cannot be called directly, but must be subclasses, with a 'cls' attribute defined as a result handler.

search

Inputs are:

  • phrase - title or phrase to search for
  • subtitle=None - optional secondary search argument
  • tolerance=None - pull from database value if not defined

This method will return a generator of Metadata objects, filtering for only those equal or less than the Levenshtein distance. The default value if undefined is 5 shifts.

sortedSearch

Accepts the same inputs as search, but returns a list sorted by the Levenshtein distance.

grabInetref

Inputs are:

  • inetref - TMDB/TTVDB/IMDB reference string, to be handled as a unique identifier by the grabber script
  • season=None - optional integer season number
  • episode=None - optional integer episode number

Returns a generator with a single matching Metadata object.

VideoGrabber

This class is a modified Grabber class, with pre-defined setting names for use with MythVideo.

Inputs are:

  • mode - 'TV' or 'Movie', depending on which MythVideo grabber to use
  • lang='en' - optional language to pass to grabber script
  • db=None
>>> grab = VideoGrabber('TV')
>>> grab.search('Better Off Ted', 'Heroes')
<generator object search at 0x804f1e1e0>
>>> grab.search('Better Off Ted', 'Heroes').next()
{'subtitle': 'Heroes', 'revenue': None, ... 'trailer': None}
>>> grab.grabInetref(84021, 1, 2).next()
{'subtitle': 'Heroes', 'revenue': None, ... 'trailer': None}

InternetSource

The class does not call external executables directly, but accesses data from them being run on the backend over MythXML. This class should not be run directly, but instead retrieved through MythXML.getInternetSources().

searchContent

Inputs are:

  • query - search string to pass to grabber
  • page=1 - optional paging argument to pass to grabber

Returns a generator of InternetMetadata objects.

>>> igrab = xml.getInternetSources().next()
>>> igrab.searchContent('Top Gear')
<generator object searchContent at 0x804f1e410>
>>> igrab.searchContent('Top Gear').next()
{'description': "Jeremy Clarkson asks why there aren't more three-wheeled cars in the world. (R)", ... 'length': None}

SystemEvent

This class is a modified System class for handling system events received from the backend. This class is only to be called automatically by MythSystemEvent, in order to run the executable defined in the database, and should not be called directly.