update sv,tr language
[enigma2.git] / lib / python / Plugins / Extensions / DVDBurn / DVDTitle.py
1 from Components.config import config, ConfigSubsection, ConfigSubList, ConfigInteger, ConfigText, ConfigSelection, getConfigListEntry, ConfigSequence, ConfigYesNo
2
3 class ConfigFixedText(ConfigText):
4         def __init__(self, text, visible_width=60):
5                 ConfigText.__init__(self, default = text, fixed_size = True, visible_width = visible_width)
6         def handleKey(self, key):
7                 pass
8
9 class ConfigActiveTrack(ConfigYesNo):
10         def __init__(self, default = True):
11                 ConfigYesNo.__init__(self, default)
12
13 class DVDTitle:
14         def __init__(self):
15                 self.properties = ConfigSubsection()
16                 self.properties.menutitle = ConfigText(fixed_size = False, visible_width = 80)
17                 self.properties.menusubtitle = ConfigText(fixed_size = False, visible_width = 80)
18                 self.DVBname = _("Title")
19                 self.DVBdescr = _("Description")
20                 self.DVBchannel = _("Channel")
21                 self.properties.aspect = ConfigSelection(choices = [("4:3", "4:3"), ("16:9", "16:9")])
22                 self.properties.widescreen = ConfigSelection(choices = [("nopanscan", "nopanscan"), ("noletterbox", "noletterbox")])
23                 self.properties.audiotracks = ConfigSubList()
24                 self.cuesheet = [ ]
25                 self.source = None
26                 self.filesize = 0
27                 self.estimatedDiskspace = 0
28                 self.inputfile = ""
29                 self.cutlist = [ ]
30                 self.chaptermarks = [ ]
31                 self.timeCreate = None
32                 self.VideoType = -1
33
34         def addService(self, service):
35                 from os import path
36                 from enigma import eServiceCenter, iServiceInformation
37                 from ServiceReference import ServiceReference
38                 from time import localtime, time
39                 self.source = service
40                 serviceHandler = eServiceCenter.getInstance()
41                 info = serviceHandler.info(service)
42                 sDescr = info and " " + info.getInfoString(service, iServiceInformation.sDescription) or ""
43                 self.DVBdescr = sDescr
44                 sTimeCreate = info.getInfo(service, iServiceInformation.sTimeCreate)
45                 if sTimeCreate > 1:
46                         self.timeCreate = localtime(sTimeCreate)
47                 serviceref = ServiceReference(info.getInfoString(service, iServiceInformation.sServiceref))
48                 name = info and info.getName(service) or "Title" + sDescr
49                 self.DVBname = name
50                 self.DVBchannel = serviceref.getServiceName()
51                 self.inputfile = service.getPath()
52                 self.filesize = path.getsize(self.inputfile)
53                 self.estimatedDiskspace = self.filesize
54                 self.length = info.getLength(service)
55
56         def initDVDmenuText(self, project, track):
57                 self.properties.menutitle.setValue(self.formatDVDmenuText(project.settings.titleformat.getValue(), track))
58                 self.properties.menusubtitle.setValue(self.formatDVDmenuText(project.settings.subtitleformat.getValue(), track))
59
60         def formatDVDmenuText(self, template, track):
61                 properties = self.properties
62                 template = template.replace("$i", str(track))
63                 template = template.replace("$t", self.DVBname)
64                 template = template.replace("$d", self.DVBdescr)
65                 template = template.replace("$c", str(len(self.chaptermarks)+1))
66                 template = template.replace("$f", self.inputfile)
67                 template = template.replace("$C", self.DVBchannel)
68                 
69                 #if template.find("$A") >= 0:
70                 from TitleProperties import languageChoices
71                 audiolist = [ ]
72                 for audiotrack in self.properties.audiotracks:
73                         active = audiotrack.active.getValue()
74                         if active:
75                                 trackstring = audiotrack.format.getValue()
76                                 language = audiotrack.language.getValue()
77                                 if languageChoices.langdict.has_key(language):
78                                         trackstring += ' (' + languageChoices.langdict[language] + ')'
79                                 audiolist.append(trackstring)
80                 audiostring = ', '.join(audiolist)
81                 template = template.replace("$A", audiostring)
82                 
83                 if template.find("$l") >= 0:
84                         l = self.length
85                         lengthstring = "%d:%02d:%02d" % (l/3600, l%3600/60, l%60)
86                         template = template.replace("$l", lengthstring)
87                 if self.timeCreate:
88                         template = template.replace("$Y", str(self.timeCreate[0]))
89                         template = template.replace("$M", str(self.timeCreate[1]))
90                         template = template.replace("$D", str(self.timeCreate[2]))
91                         timestring = "%d:%02d" % (self.timeCreate[3], self.timeCreate[4])
92                         template = template.replace("$T", timestring)
93                 else:
94                         template = template.replace("$Y", "").replace("$M", "").replace("$D", "").replace("$T", "")
95                 return template
96         
97         def produceFinalCuesheet(self):
98                 CUT_TYPE_IN = 0
99                 CUT_TYPE_OUT = 1
100                 CUT_TYPE_MARK = 2
101                 CUT_TYPE_LAST = 3
102
103                 accumulated_in = 0
104                 accumulated_at = 0
105                 last_in = 0
106
107                 self.cutlist = [ ]
108                 self.chaptermarks = [ ]
109
110                 # our demuxer expects *strictly* IN,OUT lists.
111                 currently_in = not any(type == CUT_TYPE_IN for pts, type in self.cuesheet)
112                 if currently_in:
113                         self.cutlist.append(0) # emulate "in" at first          
114
115                 for (pts, type) in self.cuesheet:
116                         #print "pts=", pts, "type=", type, "accumulated_in=", accumulated_in, "accumulated_at=", accumulated_at, "last_in=", last_in
117                         if type == CUT_TYPE_IN and not currently_in:
118                                 self.cutlist.append(pts)
119                                 last_in = pts
120                                 currently_in = True
121
122                         if type == CUT_TYPE_OUT and currently_in:
123                                 self.cutlist.append(pts)
124
125                                 # accumulate the segment
126                                 accumulated_in += pts - last_in 
127                                 accumulated_at = pts
128                                 currently_in = False
129
130                         if type == CUT_TYPE_MARK and currently_in:
131                                 # relocate chaptermark against "in" time. This is not 100% accurate,
132                                 # as the in/out points are not.
133                                 reloc_pts = pts - last_in + accumulated_in
134                                 self.chaptermarks.append(reloc_pts)
135                                 
136                 if len(self.cutlist) > 1:
137                         part = accumulated_in / (self.length*90000.0)
138                         usedsize = int ( part * self.filesize )
139                         self.estimatedDiskspace = usedsize
140                         self.length = accumulated_in / 90000
141
142         def produceAutoChapter(self, minutes):
143                 if len(self.chaptermarks) < 1:
144                         chapterpts = self.cutlist[0]
145                         while chapterpts < self.length*90000:
146                                 chapterpts += 90000 * 60 * minutes
147                                 self.chaptermarks.append(chapterpts)
148
149         def getChapterMarks(self):
150                 timestamps = []
151                 for p in self.chaptermarks:
152                         h = p / (90000 * 3600)
153                         m = p % (90000 * 3600) / (90000 * 60)
154                         s = p % (90000 * 60) / 90000
155                         ms = (p % 90000) / 90
156                         timestamps.append("%d:%02d:%02d.%03d" % (h, m, s, ms))
157                 return timestamps