Share project "powerlink" into "http://mirror/eclipse"
[tvweb.git] / tv_controller.py
blob52ce497a225b768aac6963158bb68f353049b921
1 #!/usr/bin/python
3 import os
4 import string
5 import signal
6 import alsaaudio
8 class MplayerController:
10 def __init__(self):
11 self.vars = "XAUTHORITY=/home/honza801/.Xauthority DISPLAY=:0.0"
13 def is_running(self):
14 process = os.popen('pgrep mplayer').readline()
15 if process != "":
16 return int(string.strip(process))
17 return -1
19 def getchannels(self):
20 process = os.popen('tv lschan').readline()
21 if process != "":
22 channels = map(string.strip, process.split(","))
23 return channels
24 return -1
26 def kill(self):
27 pid = self.is_running()
28 if pid < 0:
29 print "PID < 0"
30 return
31 else:
32 print "Sending SIGTERM to", pid
33 os.kill(pid,signal.SIGTERM)
35 def play(self, channel):
36 pid = self.is_running()
37 if pid > 0:
38 print "Another mplayer is running with pid", pid
39 return
40 else:
41 ret = os.system(self.vars+" tv "+channel+" >/dev/null 2>&1 &")
42 print ret
45 class VolumeController:
47 def __init__(self, mixdevice='Master'):
48 self.mixdevice = alsaaudio.Mixer(mixdevice)
50 def getvolume(self):
51 return self.mixdevice.getvolume()
53 def volup(self):
54 newvol = int(self.mixdevice.getvolume()[0])+10
55 if newvol > 100:
56 newvol = 100
57 self.mixdevice.setvolume(newvol)
59 def voldown(self):
60 newvol = int(self.mixdevice.getvolume()[0])-10
61 if newvol < 0:
62 newvol = 0
63 self.mixdevice.setvolume(newvol)
65 class MonitorController:
67 def turnon(self):
68 ret = os.system("m on")
69 return ret
71 def turnoff(self):
72 ret = os.system("m off")
73 return ret
76 if __name__ == "__main__":
77 mpc = MplayerController()
78 mpc.play("ct1")