[mythtv-users] How to check if a tuner is in use

Bill Meek keemllib at gmail.com
Wed Oct 15 19:45:50 UTC 2014


On 10/15/2014 02:11 PM, Hika van den Hoven wrote:
...
> parser.add_argument('--host', type=str, required=False, metavar='<hostname>',
>      help='backend hostname,  default <local hostname>')

You could just add: default='localhost' to the above. Or,
leave required=True and on the command line type --host=localhost
or whatever you choose.

> URL='http://{}:6544/Dvr/GetEncoderList'.format(host)

Try the URL developed above (e.g. with your hostname
where {} is), from a browser to see everything that's
returned. And there's a lot. E.g. <DisplayName>ATSC-0</DisplayName>
could be used assuming your cards have unique names.

> try:
>          request = 'SELECT `cardid` FROM `capturecard` WHERE `videodevice` = "%s" AND `hostname` = "%s"' \
>                                  % (card, host)
>          c = DB.cursor()
>          c.execute(request)
>          if c.rowcount == 1:
>                  for row in c.fetchall():
>                          cardid = str(row[0])

One intent of the Services API is to avoid direct access to the
MythTV DB. I thought that was the intent of the bindings too.
I'd strive to get rid of the code above.

>                          try:
>                                  response = ET.parse(urlopen(URL))
>                          except:
>                                  raise SystemExit('GetEncoderList failed, is the backend running?')
>                          for element in response.findall('Encoders/Encoder'):
>                                  if element.findtext('Id') == cardid:
>                                          print '%s' % (element.findtext('State'))
                                            break


Added the break above because once you've found the
card if interest, there's no reason to keep looking.

To answer your other question. Yes, import sys and then
if the script fails, use: sys.exit(2), when the card is
idle, sys.exit(0) otherwise 1 etc.

-- 
Bill


More information about the mythtv-users mailing list