Many changes, commented in
[enigma2-plugins.git] / webinterface / src / WebComponents / Sources / Movie.py
1 from enigma import *
2 from enigma import eServiceReference, iServiceInformation
3 from Components.Sources.Source import Source
4 from ServiceReference import ServiceReference,eServiceCenter
5 from Components.MovieList import MovieList
6 from Tools.Directories import *
7
8 import os
9
10 class Movie( Source):
11     LIST = 0
12     DEL = 1
13     
14     def __init__(self, session,func = LIST):
15         Source.__init__(self)
16         self.func = func
17         self.session = session
18         self.root = eServiceReference("2:0:1:0:0:0:0:0:0:0:" + resolveFilename(SCOPE_HDD))
19         self.movielist = MovieList(self.root)
20         self.movielist.load(self.root,None)
21     
22     def handleCommand(self,cmd):
23         if self.func is self.DEL:
24             self.result = self.delMovieFiles(cmd)
25         else:
26             self.result = False,"unknown command"
27         
28     def delMovieFiles(self,param):
29         print "delMovieFiles:",param
30         
31         if param is None:
32             return False,"title missing"
33         
34         #os.system("rm -f %s*" % param)
35         try:
36             os.system("rm -f %s*" % param)
37         except OSError:
38             print False,"Some error occurred while deleting file"
39         
40         if os.path.exists(param):
41             print False,"Some error occurred while deleting file"
42         else:
43             return True,"File deleted"
44    
45     def command(self):
46         self.movielist.reload(root=self.root)
47         list=[]
48         for (serviceref, info, begin,unknown) in self.movielist.list:
49             movie = []
50             movie.append(serviceref.toString())
51             movie.append(ServiceReference(serviceref).getServiceName())
52             movie.append(info.getInfoString(serviceref, iServiceInformation.sDescription))
53             
54             sourceERef =info.getInfoString(serviceref, iServiceInformation.sServiceref)
55             sourceRef= ServiceReference(sourceERef)
56             
57             movie.append(sourceRef.getServiceName())
58             movie.append(info.getInfoString(serviceref, iServiceInformation.sTags))
59             event = info.getEvent(serviceref)
60             if event is not None:
61                 text = event.getEventName()
62                 short = event.getShortDescription()
63                 ext = event.getExtendedDescription()
64                 movie.append(ext)
65             else:
66                 movie.append("")
67             filename = "/"+"/".join(serviceref.toString().split("/")[1:])
68             movie.append(filename)
69             list.append(movie)
70         print "tags",self.movielist.tags
71         return list
72
73     def getText(self):
74         print self.result
75         (result,text) = self.result
76         xml = "<?xml version=\"1.0\"?>\n"
77         xml  += "<e2simplexmlresult>\n"
78         if result:
79             xml += "<e2state>True</e2state>\n"
80         else:
81             xml += "<e2state>False</e2state>\n"            
82         xml += "<e2statetext>%s</e2statetext>\n" % text
83         xml += "</e2simplexmlresult>\n"
84         return xml
85     
86     text = property(getText)        
87     
88     list = property(command)
89     lut = {"ServiceReference": 0
90            ,"Title": 1
91            ,"Description": 2
92            ,"ServiceName": 3
93            ,"Tags": 4
94            ,"DescriptionExtended": 5
95            ,"Filename": 6
96            }
97