switched to old, dirty streammethod
[enigma2-plugins.git] / netcaster / src / bin / StreamPlayer.py
1 from enigma import eServiceReference
2 import os
3 class StreamPlayer:
4     is_playing = False
5     
6     def __init__(self,session, args = 0):
7         print " init StreamPlayer"
8         self.session = session
9         self.oldService = self.session.nav.getCurrentlyPlayingServiceReference()
10         self.session.nav.event.append(self.__event)
11     
12     def __event(self, ev):
13         print "EVENT ==>",ev
14
15     def play(self,stream):
16         print " start streaming %s" %stream.getURL()
17         if self.is_playing is True:
18             self.stop()
19             self.play(stream)
20         else:
21             if stream.getURL().startswith("/") is not True:
22                 print "playing remote stream",stream.getURL()
23                 self.session.nav.stopService()
24 #                sref = eServiceReference("4097:0:0:0:0:0:0:0:0:0:%s"%stream.getURL().replace(":",":"))
25 #                self.session.nav.playService(sref)
26                 self.targetfile = "/tmp/streamtarget."+stream.getType().lower() 
27                 os.system("mknod %s p" %self.targetfile)
28                 os.system("wget %s -O- > %s&" %(stream.getURL(),self.targetfile))
29                 self.session.nav.playService(eServiceReference("4097:0:0:0:0:0:0:0:0:0:%s"%self.targetfile))
30             else:
31                 print "playing local stream",stream.getURL()
32                 esref = eServiceReference("4097:0:0:0:0:0:0:0:0:0:%s"%stream.getURL())
33                 self.session.nav.playService(esref)
34             self.is_playing = True
35             
36     def stop(self,text=""):
37         if self.is_playing is True:
38             print " stop streaming",text
39             try:
40                 
41                 self.session.nav.stopService()
42                 os.system("killall -9 wget")
43                 os.system("rm %s" %self.targetfile)
44                 self.session.nav.playService(self.oldService)
45                 self.is_playing = False
46             except TypeError,e:
47                 print " ERROR ",e
48                 self.exit()
49         else:
50             pass
51     def exit(self):
52         self.stop()
53