Merge branch 'bug_570_playback_skip_fixes_and_cleanup_ml_aholst'
[enigma2.git] / lib / python / Plugins / Extensions / DVDBurn / TitleCutter.py
1 from Plugins.Extensions.CutListEditor.plugin import CutListEditor
2 from Components.ServiceEventTracker import ServiceEventTracker
3 from enigma import iPlayableService, iServiceInformation
4 from Tools.Directories import fileExists
5
6 class TitleCutter(CutListEditor):
7         def __init__(self, session, t):
8                 CutListEditor.__init__(self, session, t.source)
9                 self.skin = CutListEditor.skin
10                 self.session = session
11                 self.t = t
12                 self.__event_tracker = ServiceEventTracker(screen=self, eventmap=
13                         {
14                                 iPlayableService.evUpdatedInfo: self.getPMTInfo,
15                                 iPlayableService.evCuesheetChanged: self.refillList
16                         })
17                 self.onExecBegin.remove(self.showTutorial)
18
19         def getPMTInfo(self):
20                 service = self.session.nav.getCurrentService()
21                 audio = service and service.audioTracks()
22                 n = audio and audio.getNumberOfTracks() or 0
23                 if n > 0:
24                         from DVDTitle import ConfigFixedText
25                         from TitleProperties import languageChoices
26                         from Components.config import config, ConfigSubsection, ConfigSubList, ConfigSelection, ConfigYesNo
27                         self.t.properties.audiotracks = ConfigSubList()
28                         for x in range(n):
29                                 i = audio.getTrackInfo(x)
30                                 DVB_lang = i.getLanguage()
31                                 description = i.getDescription()
32                                 pid = str(i.getPID())
33                                 if description == "MPEG":
34                                         description = "MP2"
35                                 print "[audiotrack] pid:", pid, "description:", description, "language:", DVB_lang, "count:", x, "active:", (x < 8)
36                                 self.t.properties.audiotracks.append(ConfigSubsection())
37                                 self.t.properties.audiotracks[-1].active = ConfigYesNo(default = (x < 8))
38                                 self.t.properties.audiotracks[-1].format = ConfigFixedText(description)
39                                 self.t.properties.audiotracks[-1].language = ConfigSelection(choices = languageChoices.choices, default=languageChoices.getLanguage(DVB_lang))
40                                 self.t.properties.audiotracks[-1].pid = ConfigFixedText(pid)
41                                 self.t.properties.audiotracks[-1].DVB_lang = ConfigFixedText(DVB_lang)
42                 sAspect = service.info().getInfo(iServiceInformation.sAspect)
43                 if sAspect in ( 1, 2, 5, 6, 9, 0xA, 0xD, 0xE ):
44                         aspect = "4:3"
45                 else:
46                         aspect = "16:9"
47                 self.t.properties.aspect.setValue(aspect)
48                 self.t.VideoType = service.info().getInfo(iServiceInformation.sVideoType)
49
50         def checkAndGrabThumb(self):
51                 if not fileExists(self.t.inputfile.rsplit('.',1)[0] + ".png"):
52                         CutListEditor.grabFrame(self)
53
54         def exit(self):
55                 if self.t.VideoType == -1:
56                         self.getPMTInfo()
57                 self.checkAndGrabThumb()
58                 self.session.nav.stopService()
59                 self.close(self.cut_list[:])
60
61 class CutlistReader(TitleCutter):
62         skin = """
63                 <screen position="0,0" size="720,576">
64                 <eLabel position="0,0" size="720,576" zPosition="1" backgroundColor="#000000" />
65                 <widget name="Video" position="0,0" size="100,75" />
66                 <widget name="SeekState" position="0,0" />
67                 <widget source="cutlist" position="0,0" render="Listbox" >
68                         <convert type="TemplatedMultiContent">
69                                 {"template": [
70                                                 MultiContentEntryText(text = 1),
71                                                 MultiContentEntryText(text = 2)
72                                         ],
73                                  "fonts": [gFont("Regular", 18)],
74                                  "itemHeight": 20
75                                 }
76                         </convert>
77                 </widget>
78                 <widget name="Timeline" position="0,0" />
79         </screen>"""
80
81         def __init__(self, session, t):
82                 TitleCutter.__init__(self, session, t)
83                 self.skin = CutlistReader.skin
84
85         def getPMTInfo(self):
86                 TitleCutter.getPMTInfo(self)
87                 TitleCutter.checkAndGrabThumb(self)
88                 self.close(self.cut_list[:])