add Movietag List avaible with http://dm7025/web/movietags
[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         if self.func is self.DEL:
26             self.result = self.delMovieFiles(cmd)
27         else:
28             self.result = False,"unknown command"
29
30            
31     def delMovieFiles(self,param):
32         print "delMovieFiles:",param
33         
34         if param is None:
35             return False,"title missing"
36         
37         #os.system("rm -f %s*" % param)
38         try:
39             os.system('rm -f "%s"' % param)
40             #.ap .cuts .meta
41             if os.path.exists("%s.ap" % param):
42                 os.system('rm -f "%s.ap"' % param)
43             
44             if os.path.exists("%s.cuts" % param):
45                 os.system('rm -f "%s.cuts"' % param)
46             
47             if os.path.exists("%s.meta" % param):
48                 os.system('rm -f "%s.meta"' % param)
49             
50             if os.path.exists("%s.eit" % param):
51                 os.system('rm -f "%s.eit"' % param)
52         except OSError:
53             return False,"OSErrorSome error occurred while deleting file"
54         
55         if os.path.exists(param):
56             return False,"Some error occurred while deleting file"
57         else:
58             return True,"File deleted"
59    
60     def command(self):
61         self.movielist.reload(root=self.root)
62         list=[]
63         for (serviceref, info, begin,unknown) in self.movielist.list:
64             movie = []
65             movie.append(serviceref.toString())
66             movie.append(ServiceReference(serviceref).getServiceName())
67             movie.append(info.getInfoString(serviceref, iServiceInformation.sDescription))
68             
69             sourceERef =info.getInfoString(serviceref, iServiceInformation.sServiceref)
70             sourceRef= ServiceReference(sourceERef)
71             
72             movie.append(sourceRef.getServiceName())
73             movie.append(info.getInfoString(serviceref, iServiceInformation.sTags))
74             event = info.getEvent(serviceref)
75             if event is not None:
76                 text = event.getEventName()
77                 short = event.getShortDescription()
78                 ext = event.getExtendedDescription()
79                 movie.append(ext)
80             else:
81                 movie.append("")
82             filename = "/"+"/".join(serviceref.toString().split("/")[1:])
83             movie.append(filename)
84             list.append(movie)
85         return list
86
87     def getText(self):
88         if self.func is self.DEL: 
89             (result,text) = self.result
90             xml  = "<e2simplexmlresult>\n"
91             if result:
92                 xml += "<e2state>True</e2state>\n"
93             else:
94                 xml += "<e2state>False</e2state>\n"            
95             xml += "<e2statetext>%s</e2statetext>\n" % text
96             xml += "</e2simplexmlresult>\n"
97             return xml
98         elif self.func is self.TAGS:
99             xml = "<e2movietags>\n"
100             for tag in self.movielist.tags:
101                 xml += "<e2movietag>%s</e2movietag>\n"%tag
102             xml += "</e2movietags>\n"
103             return xml
104             
105     text = property(getText)        
106     
107     list = property(command)
108     lut = {"ServiceReference": 0
109            ,"Title": 1
110            ,"Description": 2
111            ,"ServiceName": 3
112            ,"Tags": 4
113            ,"DescriptionExtended": 5
114            ,"Filename": 6
115            }
116