moved from screen to tmux
[tvweb.git] / tv_controller.py
blob343298224b5dd9eade8738d099aca26de92248cf
2 import os
3 import string
4 import signal
5 import alsaaudio
7 class VideoController:
9 def __init__(self):
10 pass
12 def is_running(self):
13 process = os.popen('pgrep vlc').readline()
14 if process != "":
15 return int(string.strip(process))
16 return -1
18 def getchannels(self):
19 process = os.popen('tv lschan').readline()
20 if process != "":
21 channels = map(string.strip, process.split(","))
22 return channels
23 return -1
25 def kill(self):
26 pid = self.is_running()
27 if pid < 0:
28 print "PID < 0"
29 return
30 else:
31 print "Sending SIGTERM to", pid
32 os.kill(pid,signal.SIGTERM)
34 def play_tv(self, channel):
35 pid = self.is_running()
36 if pid > 0:
37 print "Another mplayer is running with pid", pid
38 return
39 else:
40 q = "tmux neww '/home/honza801/bin/tv "+channel+"'"
41 ret = os.system(q)
42 print q, ret
44 def play(self, file):
45 if not os.path.isfile(file):
46 return
47 pid = self.is_running()
48 if pid > 0:
49 print "Another mplayer is running with pid", pid
50 return
51 else:
52 q = "tmux neww '/home/honza801/bin/tv \""+file+"\"'"
53 ret = os.system(q)
54 print q, ret
57 class VolumeController:
59 def __init__(self, mixdevice='Master'):
60 self.mixdevice = alsaaudio.Mixer(mixdevice)
62 def getvolume(self):
63 return self.mixdevice.getvolume()
65 def volup(self):
66 newvol = int(self.mixdevice.getvolume()[0])+10
67 if newvol > 100:
68 newvol = 100
69 self.mixdevice.setvolume(newvol)
71 def voldown(self):
72 newvol = int(self.mixdevice.getvolume()[0])-10
73 if newvol < 0:
74 newvol = 0
75 self.mixdevice.setvolume(newvol)
77 class MonitorController:
79 def turnon(self):
80 ret = os.system("m on")
81 return ret
83 def turnoff(self):
84 ret = os.system("m off")
85 return ret
88 if __name__ == "__main__":
89 mpc = VideoController()
90 mpc.play_tv("ct1")