movielist can now be filtered by a movietag (or a part of a movietag)
[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 #import sys, traceback
10
11 class Movie( Source):
12     LIST = 0
13     DEL = 1
14     TAGS = 2
15     
16     def __init__(self, session,func = LIST):
17         Source.__init__(self)
18         self.func = func
19         self.session = session
20         self.root = eServiceReference("2:0:1:0:0:0:0:0:0:0:" + resolveFilename(SCOPE_HDD))
21         self.movielist = MovieList(self.root)
22         self.movielist.load(self.root,None)
23     
24     def handleCommand(self,cmd):
25         self.cmd = cmd
26         if self.func is self.DEL:
27             self.result = self.delMovieFiles(cmd)
28         else:
29             self.result = False,"unknown command"
30
31            
32     def delMovieFiles(self,param):
33         print "delMovieFiles:",param
34         
35         if param is None:
36             return False,"title missing"
37         
38         #os.system("rm -f %s*" % param)
39         try:
40             os.system('rm -f "%s"' % param)
41             #.ap .cuts .meta
42             if os.path.exists("%s.ap" % param):
43                 os.system('rm -f "%s.ap"' % param)
44             
45             if os.path.exists("%s.cuts" % param):
46                 os.system('rm -f "%s.cuts"' % param)
47             
48             if os.path.exists("%s.meta" % param):
49                 os.system('rm -f "%s.meta"' % param)
50             
51             if os.path.exists("%s.eit" % param):
52                 os.system('rm -f "%s.eit"' % param)
53         except OSError:
54             return False,"OSErrorSome error occurred while deleting file"
55         
56         if os.path.exists(param):
57             return False,"Some error occurred while deleting file"
58         else:
59             return True,"File deleted"
60    
61     def command(self):
62         self.movielist.reload(root=self.root)
63         list=[]
64         for (serviceref, info, begin,unknown) in self.movielist.list:
65             movie = []
66             movie.append(serviceref.toString())
67             movie.append(ServiceReference(serviceref).getServiceName())
68             movie.append(info.getInfoString(serviceref, iServiceInformation.sDescription))
69             
70             sourceERef =info.getInfoString(serviceref, iServiceInformation.sServiceref)
71             sourceRef= ServiceReference(sourceERef)
72             
73             movie.append(sourceRef.getServiceName())
74             movie.append(info.getInfoString(serviceref, iServiceInformation.sTags))
75             event = info.getEvent(serviceref)
76             if event is not None:
77                 text = event.getEventName()
78                 short = event.getShortDescription()
79                 ext = event.getExtendedDescription()
80                 movie.append(ext)
81             else:
82                 movie.append("")
83             filename = "/"+"/".join(serviceref.toString().split("/")[1:])
84             movie.append(filename)
85             if info.getInfoString(serviceref, iServiceInformation.sTags).lower().find(self.cmd.lower())>=0:
86                 """ add movie only to list, if a givven tag is applied to the movie """
87                 list.append(movie)
88         return list
89
90     def getText(self):
91         if self.func is self.DEL: 
92             (result,text) = self.result
93             xml  = "<e2simplexmlresult>\n"
94             if result:
95                 xml += "<e2state>True</e2state>\n"
96             else:
97                 xml += "<e2state>False</e2state>\n"            
98             xml += "<e2statetext>%s</e2statetext>\n" % text
99             xml += "</e2simplexmlresult>\n"
100             return xml
101         elif self.func is self.TAGS:
102             xml = "<e2movietags>\n"
103             for tag in self.movielist.tags:
104                 xml += "<e2movietag>%s</e2movietag>\n"%tag
105             xml += "</e2movietags>\n"
106             return xml
107             
108     text = property(getText)        
109     
110     list = property(command)
111     lut = {"ServiceReference": 0
112            ,"Title": 1
113            ,"Description": 2
114            ,"ServiceName": 3
115            ,"Tags": 4
116            ,"DescriptionExtended": 5
117            ,"Filename": 6
118            }
119