1 | #!/usr/bin/env python |
---|
2 | # |
---|
3 | # myth-chan |
---|
4 | # A wrapper for MythTV external channel changers |
---|
5 | # This is setup to remedy a known audio instability with certian |
---|
6 | # TV Capture devices. |
---|
7 | # |
---|
8 | # Copyright 2009 Nick Fox <nfox@foxmediasystems.com> |
---|
9 | # |
---|
10 | # This program is free software; you can redistribute it and/or modify |
---|
11 | # it under the terms of the GNU General Public License as published by |
---|
12 | # the Free Software Foundation; either version 2 of the License, or |
---|
13 | # (at your option) any later version. |
---|
14 | # |
---|
15 | # This program is distributed in the hope that it will be useful, |
---|
16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
18 | # GNU General Public License for more details. |
---|
19 | # |
---|
20 | # You should have received a copy of the GNU General Public License |
---|
21 | # along with this program; if not, write to the Free Software |
---|
22 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
---|
23 | # MA 02110-1301, USA. |
---|
24 | |
---|
25 | |
---|
26 | # Get python defaults |
---|
27 | import os |
---|
28 | import sys |
---|
29 | from optparse import OptionParser |
---|
30 | import subprocess |
---|
31 | |
---|
32 | |
---|
33 | def main(self): |
---|
34 | # Go Baby GO! |
---|
35 | # Setup the options |
---|
36 | parser = OptionParser() |
---|
37 | parser.add_option("-c", "--dct-channel", nargs=3, help="Use DCT Channel Binary to change channels.\ |
---|
38 | usage: myth-chan <-c | --dct-channel> <port> <video_source> <channel>", dest="dct") |
---|
39 | parser.add_option("-d", "--direct-tv", nargs=4, help="Use the DirectTV external channel changer.\ |
---|
40 | usage: myth-chan <-d | --direct-tv> <set-top-box-type> <port> <video_source> <channel>", dest="dtv") |
---|
41 | |
---|
42 | (options, args) = parser.parse_args() |
---|
43 | |
---|
44 | if options.dct: |
---|
45 | dct_channel(options.dct[0],options.dct[1],options.dct[2]) |
---|
46 | if options.dtv: |
---|
47 | dtv_channel(options.dtv[0],options.dtv[1],options.dtv[2],options.dtv[3]) |
---|
48 | |
---|
49 | def dct_channel(port, vidsrc, chan): |
---|
50 | # Wrapper up and Use the channel binary |
---|
51 | try: |
---|
52 | if os.path.exists("/usr/local/bin/channel"): |
---|
53 | cmd = "/usr/local/bin/channel -p " + port + " " + chan |
---|
54 | subprocess.Popen4(["v4l2-ctl -d " + vidsrc + " --set-audio-input=2"]) |
---|
55 | subprocess.Popen4([cmd]) |
---|
56 | subprocess.Popen4(["v4l2-ctl -d " + vidsrc + " --set-audio-input=1"]) |
---|
57 | else: |
---|
58 | print "/usr/local/bin/channel not found!" |
---|
59 | except: |
---|
60 | print "Channel Binary failed to change channels." |
---|
61 | |
---|
62 | def dtv_channel(stb_type, port, vidsrc, chan): |
---|
63 | # directtv.pl wrapper |
---|
64 | try: |
---|
65 | if os.path.exists("/usr/local/bin/directv.pl"): |
---|
66 | cmd = "/usr/local/bin/directtv.pl port " + port + " box_type " + stb_type + " setup_channel " + chan |
---|
67 | subprocess.Popen4(["v4l2-ctl -d " + vidsrc + " --set-audio-input=2"]) |
---|
68 | subprocess.Popen4([cmd]) |
---|
69 | subprocess.Popen4(["v4l2-ctl -d " + vidsrc + " --set-audio-input=1"]) |
---|
70 | else: |
---|
71 | print "/usr/local/bin/directv.pl not found!" |
---|
72 | except: |
---|
73 | print "directv.pl failed to change channels." |
---|
74 | |
---|
75 | if __name__ == "__main__": |
---|
76 | main(sys.argv[1:]) |
---|