[mythtv-users] How to check if a tuner is in use
Hika van den Hoven
hikavdh at gmail.com
Thu Oct 16 00:33:45 UTC 2014
Hoi Bill and others,
My final result with your help. It returns the value for the status in
the returncode ($?). If you supply the -v or --verbose option it is
also printed to the screen. If the capture-device is not found, -1 (or
255) equal to not connected is returned. On error -2 (or 254) is
returned. -h or --help gives the options. Feel free to use it.
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
import argparse, socket, urllib2, sys
from urllib2 import urlopen
from xml.etree import cElementTree as ET
parser = argparse.ArgumentParser(description='Get Status of Backend Encoders.')
parser.add_argument('-c', '--card', type=str, required=False,
metavar='<device>', default='/dev/video0',
help='tv capture device, defaults to </dev/video0>')
parser.add_argument('-m', '--host', type=str, required=False,
metavar='<hostname>', default=socket.gethostname(),
help='backend dns hostname, defaults to the local hostname')
parser.add_argument('-v', '--verbose', action='store_true',
required=False, help='print the result to the screen')
args = parser.parse_args()
URL0 = 'http://{}:6544//Myth/GetHostName'.format(args.host)
try:
response = ET.parse(urlopen(URL0))
root = response.getroot()
except:
if args.verbose:
print 'GetHostName failed, is the backend running?'
sys.exit(-2)
URL1 = 'http://{}:6544/Capture/GetCaptureCardList?HostName={}' \
.format(args.host, root.text)
try:
response = ET.parse(urlopen(URL1))
except:
if args.verbose:
print 'GetCaptureCardList failed, is the backend running?'
sys.exit(-2)
for element1 in response.findall('CaptureCards/CaptureCard'):
if element1.findtext('VideoDevice') == args.card:
URL2 = 'http://{}:6544/Dvr/GetEncoderList'.format(args.host)
try:
response = ET.parse(urlopen(URL2))
except:
if args.verbose:
print'GetEncoderList failed, is the backend running?'
sys.exit(-2)
for element2 in response.findall('Encoders/Encoder'):
if element2.findtext('Id') == element1.findtext('CardId'):
if args.verbose:
if int(element2.findtext('State')) == -1:
print 'The status of %s on %s is: -1, not Connected' \
% (args.card, args.host)
elif int(element2.findtext('State')) == 0:
print 'The status of %s on %s is: 0, Inactive' \
% (args.card, args.host)
elif int(element2.findtext('State')) == 1:
print 'The status of %s on %s is: 1, watching Live TV' \
% (args.card, args.host)
elif int(element2.findtext('State')) == 7:
print 'The status of %s on %s is: 7, Recording' \
% (args.card, args.host)
else:
print 'The status of %s on %s is: %s' % \
(args.card, args.host, \
element2.findtext('State'))
sys.exit(int(element2.findtext('State')))
break
break
if args.verbose:
print 'The capture device is not found in MythTV'
sys.exit(-1)
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