[mythtv-users] Noob questions on Frontend socket and Python Bindings

Raymond Wagner raymond at wagnerrp.com
Mon Jan 18 16:44:46 UTC 2010


On 1/18/2010 06:01, Marius Schrecker wrote:
>
> <snip>
>

Access to the frontend socket can be had in one of three manners, you 
can connect directly through the Frontend class, or you can have the 
bindings provide you the port or a list of available frontends. (NOTE: 
these commands are from the new bindings to be in 0.23, however the only 
difference in the code below is that 'getFrontend' and 'getFrontends' 
were formerly under the 'MythTV' class in 0.22)


 >>> Frontend('mythbe',6546)
<Frontend 'mythbe at 6546' at 0x8036afdd0>

 >>> from MythTV import MythDB
 >>> db = MythDB()
 >>> db.getFrontend('mythbe')
<Frontend 'mythbe at 6546' at 0x8024ae490>

 >>> import pprint
 >>> pp = pprint.PrettyPrinter()
 >>> pp.pprint(db.getFrontends())
myth2 is not a valid frontend
[<Frontend 'myth1 at 6546' at 0x8036afe10>,
<Frontend 'mythbe at 6546' at 0x8036affd0>]

Note that one frontend was found in the database, but was currently 
offline, so the last search only returned the other two.  So lets use 
one.  When you create the instance, it will check to see if it can 
connect to the frontend, throw an error if not.

 >>> fe = db.getFrontend('myth2')
Traceback (most recent call last):
   File "<console>", line 1, in <module>
   File "/usr/local/lib/python2.6/site-packages/MythTV/MythFunc.py", 
line 688, in getFrontend
     return Frontend(host,port)
   File "/usr/local/lib/python2.6/site-packages/MythTV/MythFunc.py", 
line 365, in __init__
     self.connect()
   File "/usr/local/lib/python2.6/site-packages/MythTV/MythFunc.py", 
line 383, in connect
     self.socket.connect((self.host, self.port))
   File "<string>", line 1, in connect
timeout: timed out
 >>> fe = db.getFrontend('mythbe')

Now lets get a list of available functions, and use one.

 >>> pp.pprint(fe.getQuery())
(('location', 'Query current screen or location'),
  ('recordings', 'List currently available recordings'),
  ('recording CHANID STARTTIME', 'List info about the specified program'),
  ('liveTV', 'List current TV schedule'),
  ('liveTV CHANID', 'Query current program for specified channel'),
  ('load', 'List 1/5/15 load averages'),
  ('memstats', 'List free and total, physical and swap memory'),
  ('time', 'Query current time on frontend'),
  ('uptime', 'Query machine uptime'),
  ('verbose', 'Get current VERBOSE filter'),
  ('version', 'Query Frontend version details'))
 >>> fe.sendQuery('memstats')
'1756 1105 1032 1029'
 >>> fe.sendQuery('time')
'2010-01-18T10:59:40'
 >>> fe.sendQuery('liveTV 4091')
' 4091 2010-01-18T10:00:00 2010-01-18T11:00:00 The Ellen DeGeneres Show'
 >>> fe.sendQuery('liveTV')
'ERROR: Unable to retrieve current schedule list'

Well, that last one seems to be broken, and running the same command 
from telnet gets the same response. It's a known bug, and here's the 
respective ticket to watch.
http://svn.mythtv.org/trac/ticket/7704
Since that's broken, you need another mechanism to find out what shows 
are on.  (NOTE: this only exists in the new bindings, 
http://svn.mythtv.org/trac/ticket/7264)

 >>> from datetime import datetime
 >>> pp.pprint(db.searchGuide(startbefore=datetime.now(), 
endafter=datetime.now()))
(<Guide 'WordWorld','2010-01-18 11:30:00' at 0x803623290>,
<Guide 'Quick Fix Meals With Robin Miller','2010-01-18 11:30:00' at 
0x803623390>,
<Guide 'Fetch! With Ruff Ruffman','2010-01-18 11:30:00' at 0x803623690>,
.....
<Guide 'ER','2010-01-18 11:00:00' at 0x803612350>,
<Guide 'WordWorld','2010-01-18 11:30:00' at 0x803612650>,
<Guide 'WordWorld','2010-01-18 11:30:00' at 0x803612950>)
 >>> guidedata = db.searchGuide(startbefore=datetime.now(), 
endafter=datetime.now())
 >>> guidedata[0].title
u'WordWorld'
 >>> guidedata[0].subtitle
u"Bear's Bed Sled; Sh-Sh-Shark!"
 >>> guidedata[0].chanid
2013L


More information about the mythtv-users mailing list