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

Hika van den Hoven hikavdh at gmail.com
Wed Oct 15 19:11:49 UTC 2014


Hoi Hika,

Wednesday, October 15, 2014, 8:28:27 PM, you wrote:

> Hoi Bill,

> Tuesday, October 14, 2014, 12:05:37 AM, you wrote:

>> On 10/13/2014 04:28 PM, Hika van den Hoven wrote:
>> ...
>>> I saw, only your 'Inputs/Input' queries are not there with me.
>>> (DisplayName, ScheduleOrder and LiveTVOrder)
>>> How do I interpret the status codes.
>>> I saw 0 = inactive, 7 = recording and -1 = Not connected.

>> Unfortunately, for now you need to read the source and see
>> that the enum starts at -1. But for your case, if the value
>> is anything other than 0, the tuner isn't available.

>> There's work in progress to change the values to translated
>> text, so something meaningful (and in your chosen language
>> would print. The change would be seen in 0.28 at best.

> I've been fiddling around with your python script and already learned
> a lot about python. I am trying to let it give the state of just one
> card. I added an argument for the videodevice defaulting to
> /dev/video0 and then get the id from the database. I also let the
> hostname default to the local hostname:

> if args.host:
>         host = args.host
> else:
>         host = socket.gethostname()

> Now I can't get the filtering of the output from the webpage. I tried:

> for element in response.findall('Encoders/Encoder'):
>         if element.findtext('Id') == cardid:
>                 print '%s' % (element.findtext('State'))

> and

> for element in response.findall('Encoders/Encoder'):
>         id=element.findtext('Id')
>         state=element.findtext('State')
>         if id == cardid:
>                 print '%s' % (state)

> but get nothing. What am I doing wrong?

> Tot mails,
>   Hika                            mailto:hikavdh at gmail.com

Found it! id is a string and cardid is a value, and with the str()
function I can set cardid to a string!

This returns the state of a capture device, defaulting to /dev/video0
on a given host, which defaults to the local machine. I guess a
backend must be running on both the machine you call it from and on
the given host. If the device is not found in the database it returns
-1. Like the not connected state. 0 = free, 1 is livetv and 7 =
recording.

#!/usr/bin/env python2
# -*- coding: utf-8 -*-

import argparse, socket, subprocess, urllib2
from urllib2   import urlopen
from xml.etree import cElementTree as ET
from MythTV import MythDB

parser = argparse.ArgumentParser(description='Get Status of Backend Encoders.')

parser.add_argument('--card', type=str, required=False, metavar='<device>',
    help='tv capture device, default </dev/video0>')

parser.add_argument('--host', type=str, required=False, metavar='<hostname>',
    help='backend hostname,  default <local hostname>')

args = parser.parse_args()

if args.card:
        card = args.card
else:
        card = "/dev/video0"

if args.host:
        host = args.host
else:
        host = socket.gethostname()

DB = MythDB()
URL='http://{}:6544/Dvr/GetEncoderList'.format(host)
        
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])
                        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'))

        else:
                print '-1'
                
finally:
        c.close()


Tot mails,
  Hika                            mailto:hikavdh at gmail.com

"Zonder hoop kun je niet leven
Zonder leven is er geen hoop
Het eeuwige dilemma
Zeker als je hoop moet vernietigen om te kunnen overleven!"

De lerende Mens



More information about the mythtv-users mailing list