1 from Plugins.Plugin import PluginDescriptor
2 from Screens.Screen import Screen
3 from Screens.MessageBox import MessageBox
4 from Screens.ChoiceBox import ChoiceBox
5 from Screens.LocationBox import MovieLocationBox
7 from Components.config import config, ConfigText, ConfigSelection, ConfigNothing, getConfigListEntry
8 from Components.ActionMap import ActionMap
9 from Components.ConfigList import ConfigList, ConfigListScreen
10 from Components.Sources.StaticText import StaticText
11 from enigma import eTimer, eServiceCenter, iServiceInformation, eConsoleAppContainer
12 from os import access, chmod, X_OK
14 def main(session, service, **kwargs):
15 # Hack to make sure it is executable
16 mcut_path = "/usr/lib/enigma2/python/Plugins/Extensions/MovieCut/bin/mcut"
17 if not access(mcut_path, X_OK):
19 session.open(MovieCut, service, **kwargs)
21 def Plugins(**kwargs):
22 return PluginDescriptor(name="MovieCut", description=_("Execute cuts..."), where = PluginDescriptor.WHERE_MOVIELIST, fnc=main)
25 class MovieCut(ChoiceBox):
26 def __init__(self, session, service):
27 self.service = service
28 serviceHandler = eServiceCenter.getInstance()
29 path = self.service.getPath()
30 info = serviceHandler.info(self.service)
34 self.name = info.getName(self.service)
36 (_("Don't cut"), "CALLFUNC", self.confirmed0),
37 (_("Replace the original movie with the cut movie"), "CALLFUNC", self.confirmed1),
38 (_("Place the cut movie in a new file ending with \" cut\""), "CALLFUNC", self.confirmed2),
39 (_("Advanced cut specification..."), "CALLFUNC", self.confirmed3),
41 ChoiceBox.__init__(self, session, _("How would you like to cut \"%s\"?") % (self.name), list = tlist, selection = 0)
42 self.skinName = "ChoiceBox"
44 def confirmed0(self, arg):
47 def confirmed1(self, arg):
48 MovieCutSpawn(self.session, self, [mcut_path, "-r", self.service.getPath()], self.name)
50 def confirmed2(self, arg):
51 MovieCutSpawn(self.session, self, [mcut_path, self.service.getPath()], self.name)
53 def confirmed3(self, arg):
54 serviceHandler = eServiceCenter.getInstance()
55 info = serviceHandler.info(self.service)
56 path = self.service.getPath()
57 self.name = info.getName(self.service)
58 descr = info.getInfoString(self.service, iServiceInformation.sDescription)
59 self.session.openWithCallback(self.advcutConfirmed, AdvancedCutInput, self.name, path, descr)
61 def advcutConfirmed(self, ret):
62 if len(ret) <= 1 or not ret[0]:
68 clist.append(self.service.getPath())
70 clist += ["-o", ret[2]]
72 clist += ["-n", ret[3]]
74 clist += ["-d", ret[4]]
78 MovieCutSpawn(self.session, self, clist, self.name)
80 class AdvancedCutInput(Screen, ConfigListScreen):
81 def __init__(self, session, name, path, descr):
82 Screen.__init__(self, session)
83 self.skinName = [ "AdvancedCutInput", "Setup" ]
85 self["key_green"] = StaticText(_("OK"))
86 self["key_red"] = StaticText(_("Cancel"))
88 if self.baseName(path) == self.baseName(name):
92 dir = self.dirName(path)
93 file = self.baseName(path) + " cut"
94 self.input_replace = ConfigSelection(choices = [("no", _("No")), ("yes", _("Yes"))], default = "no")
95 self.input_file = ConfigText(default = file, fixed_size = False, visible_width = 45)
96 self.input_title = ConfigText(default = title, fixed_size = False, visible_width = 45)
97 self.input_descr = ConfigText(default = descr, fixed_size = False, visible_width = 45)
98 tmp = config.movielist.videodirs.value
101 self.input_dir = ConfigSelection(choices = tmp, default = dir)
102 self.input_manual = ConfigSelection(choices = [("no", _("Cutlist")), ("yes", _("Manual specification"))], default = "no")
103 self.input_space = ConfigNothing()
104 self.input_manualcuts = ConfigText(default = "", fixed_size = False)
105 self.input_manualcuts.setUseableChars(" 0123456789:.")
107 self["actions"] = ActionMap(["SetupActions"],
109 "ok": self.keySelectOrGo,
111 "cancel": self.keyCancel,
115 ConfigListScreen.__init__(self, self.list)
116 self.entry_replace = getConfigListEntry(_("Replace original:"), self.input_replace)
117 self.entry_file = getConfigListEntry(_("New filename:"), self.input_file)
118 self.entry_title = getConfigListEntry(_("New title:"), self.input_title)
119 self.entry_descr = getConfigListEntry(_("New description:"), self.input_descr)
120 self.entry_dir = getConfigListEntry(_("New location:"), self.input_dir)
121 self.entry_manual = getConfigListEntry(_("Cut source:"), self.input_manual)
122 self.entry_space = getConfigListEntry(_("Cuts (an IN OUT IN OUT ... sequence of hour:min:sec)"), self.input_space)
123 self.entry_manualcuts = getConfigListEntry(":", self.input_manualcuts)
124 self.createSetup(self["config"])
126 self.onLayoutFinish.append(self.layoutFinished)
128 def layoutFinished(self):
129 self.setTitle(_("Cut Parameter Input"))
131 def createSetup(self, configlist):
135 if self.input_replace.value == "no":
145 if self.input_manual.value == "yes":
148 self.entry_manualcuts,
151 configlist.list = list
152 configlist.l.setList(list)
155 ConfigListScreen.keyLeft(self)
156 cc = self["config"].getCurrent()
157 if cc is self.entry_replace or cc is self.entry_manual:
158 self.createSetup(self["config"])
161 ConfigListScreen.keyRight(self)
162 cc = self["config"].getCurrent()
163 if cc is self.entry_replace or cc is self.entry_manual:
164 self.createSetup(self["config"])
166 def pathSelected(self, res):
168 if config.movielist.videodirs.value != self.input_dir.choices:
169 self.input_dir.setChoices(config.movielist.videodirs.value, default=res)
170 self.input_dir.value = res
172 def keySelectOrGo(self):
173 if self["config"].getCurrent() == self.entry_dir:
174 self.session.openWithCallback(
177 _("Choose target folder"),
178 self.input_dir.value,
184 if self.input_replace.value == "yes":
187 path = self.rejoinName(self.input_dir.value, self.input_file.value)
188 if self.input_manual.value == "no":
191 cuts = self.input_manualcuts.value.split(' ')
194 self.close((True, self.input_replace.value, path, self.input_title.value, self.input_descr.value, cuts))
199 def baseName(self, str):
200 name = str.split('/')[-1]
201 if name.endswith(".ts") is True:
206 def dirName(self, str):
207 return '/'.join(str.split('/')[:-1]) + '/'
209 def rejoinName(self, dir, name):
211 if name.endswith(".ts") is True:
212 return dir + name[:-3]
218 self.container = eConsoleAppContainer()
219 self.container.appClosed.append(self.runDone)
223 def enqueue(self, cb, cmd):
224 self.queue.append((cb, cmd))
236 self.container.execute(*self.queue[0][1])
238 def runDone(self, retval):
239 cb = self.queue[0][0]
240 self.queue = self.queue[1:]
244 global_mcut_errors = [_("The movie \"%s\" is successfully cut"),
245 _("Cutting failed for movie \"%s\"")+":\n"+_("Bad arguments"),
246 _("Cutting failed for movie \"%s\"")+":\n"+_("Couldn't open input .ts file"),
247 _("Cutting failed for movie \"%s\"")+":\n"+_("Couldn't open input .cuts file"),
248 _("Cutting failed for movie \"%s\"")+":\n"+_("Couldn't open input .ap file"),
249 _("Cutting failed for movie \"%s\"")+":\n"+_("Couldn't open output .ts file"),
250 _("Cutting failed for movie \"%s\"")+":\n"+_("Couldn't open output .cuts file"),
251 _("Cutting failed for movie \"%s\"")+":\n"+_("Couldn't open output .ap file"),
252 _("Cutting failed for movie \"%s\"")+":\n"+_("Empty .ap file"),
253 _("Cutting failed for movie \"%s\"")+":\n"+_("No cuts specified"),
254 _("Cutting failed for movie \"%s\"")+":\n"+_("Read/write error (disk full?)"),
255 _("Cutting was aborted for movie \"%s\"")]
257 global_mcut_queue = MovieCutQueue()
259 global_mcut_block = False
262 def __init__(self, session, parent, clist, name):
263 global global_mcut_queue
264 global global_mcut_block
265 self.session = session
268 self.clist = [clist[0]] + clist
271 self.waitTimer = eTimer()
272 self.waitTimer.callback.append(self.doWaitAck)
273 if global_mcut_queue.enqueue(self.doAck, self.clist):
274 mess = _("The movie \"%s\" is cut in the background.") % (self.name)
276 mess = _("Another movie is currently cut.\nThe movie \"%s\" will be cut in the background after it.") % (self.name)
277 global_mcut_block = True
278 self.dialog = self.session.openWithCallback(self.endc, MessageBox, mess, MessageBox.TYPE_INFO)
280 def doAck(self, retval):
281 global global_mcut_errors
282 # if WIFEXITED(retval):
283 # self.mess = global_mcut_errors[WEXITSTATUS(retval)] % (self.name)
285 # self.mess = global_mcut_errors[-1] % (self.name)
286 self.mess = global_mcut_errors[retval] % (self.name)
290 global global_mcut_block
291 if Screens.Standby.inStandby or not self.session.in_exec or (global_mcut_block and not self.dialog):
292 self.waitTimer.start(2000, True)
294 global_mcut_block = True
295 self.session.openWithCallback(self.endw, MessageBox, self.mess, MessageBox.TYPE_INFO)
297 def endw(self, arg = 0):
298 global global_mcut_block
299 global_mcut_block = False
300 if self.session.current_dialog == self.dialog:
301 self.session.current_dialog.close(True)
304 def endc(self, arg = 0):
305 global global_mcut_block
306 global_mcut_block = False
309 # self.session.current_dialog.close()