chmod from 775 to 755
[enigma2-plugins.git] / webinterface / src / WebChilds / PlayService.py
1 from enigma import eServiceReference
2 from twisted.web2 import resource, stream, responsecode, http
3 import os
4
5 class ServiceplayerResource(resource.Resource):
6     def __init__(self,session):
7         resource.Resource.__init__(self)
8         self.session = session
9         self.oldservice = None
10         
11     def render(self, req):
12         if req.args.has_key("file"):
13             output = self.playFile(req.args['file'][0])
14         elif req.args.has_key("url"):
15             output = self.playURL(req.args['url'][0])
16         elif req.args.has_key("stop"):
17             output = self.stopServicePlay()
18         else:
19             output = True,"unknown command"
20         return http.Response(responsecode.OK,stream=output[1])
21     
22     def playFile(self,path):
23         print "[ServiceplayerResource] playing file",path
24         if os.path.exists(path) is not True:
25             return False,"given path is not existing, %s"%path
26         else:
27             sref = "4097:0:0:0:0:0:0:0:0:0:%s"%path
28             self.startServicePlay(eServiceReference(sref))
29             return True,"playing path started, %s"%path
30         
31     def playURL(self,url):
32         #url= url.replace("%3a",":").replace("%20"," ")
33         #print "[ServiceplayerResource] playing url",url
34         #sref = "4097:0:0:0:0:0:0:0:0:0:%s"%url
35         #self.startServicePlay(eServiceReference(sref))
36         return False,"Not implemented"
37     
38     def startServicePlay(self,esref):
39         print "[ServiceplayerResource] playing sref",esref.toString()
40         csref = self.session.nav.getCurrentlyPlayingServiceReference()
41         if csref is not None:
42             if csref.toString().startswith("4097") is not True:
43                 self.oldservice = csref.toString(),csref
44         
45         self.session.nav.stopService()
46         self.session.nav.playService(esref)
47         
48     def stopServicePlay(self):
49         print "[ServiceplayerResource] stopping service",self.oldservice
50         self.session.nav.stopService()
51         if self.oldservice is not None:
52             self.session.nav.playService(self.oldservice[1])
53             return True, "[ServiceplayerResource] stopped, now playing old service, %s"%self.oldservice[0]
54         else:
55             return True, "[ServiceplayerResource] stopped"