aboutsummaryrefslogtreecommitdiff
path: root/lib/python/Plugins/Extensions/DVDBurn/DVDTitle.py
blob: 660005e628ebfb2f9a5f67c7f018bb26504992bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
from Components.config import config, ConfigSubsection, ConfigSubList, ConfigInteger, ConfigText, ConfigSelection, getConfigListEntry, ConfigSequence, ConfigYesNo

class ConfigFixedText(ConfigText):
	def __init__(self, text, visible_width=60):
		ConfigText.__init__(self, default = text, fixed_size = True, visible_width = visible_width)
	def handleKey(self, key):
		pass

class DVDTitle:
	def __init__(self):
		self.properties = ConfigSubsection()
		self.properties.menutitle = ConfigText(fixed_size = False, visible_width = 80)
		self.properties.menusubtitle = ConfigText(fixed_size = False, visible_width = 80)
		self.DVBname = _("Title")
		self.DVBdescr = _("Description")
		self.DVBchannel = _("Channel")
		self.properties.aspect = ConfigSelection(choices = [("4:3", _("4:3")), ("16:9", _("16:9"))])
		self.properties.widescreen = ConfigSelection(choices = [("nopanscan", "nopanscan"), ("noletterbox", "noletterbox")])
		self.properties.autochapter = ConfigInteger(default = 0, limits = (0, 60))
		self.properties.audiotracks = ConfigSubList()
		self.cuesheet = [ ]
		self.source = None
		self.filesize = 0
		self.estimatedDiskspace = 0
		self.inputfile = ""
		self.cutlist = [ ]
		self.chaptermarks = [ ]
		self.timeCreate = None
		self.VideoType = -1

	def addService(self, service):
		from os import path
		from enigma import eServiceCenter, iServiceInformation
		from ServiceReference import ServiceReference
		from time import localtime, time
		self.source = service
		serviceHandler = eServiceCenter.getInstance()
		info = serviceHandler.info(service)
		sDescr = info and " " + info.getInfoString(service, iServiceInformation.sDescription) or ""
		self.DVBdescr = sDescr
		sTimeCreate = info.getInfo(service, iServiceInformation.sTimeCreate)
		if sTimeCreate > 1:
			self.timeCreate = localtime(sTimeCreate)
		serviceref = ServiceReference(info.getInfoString(service, iServiceInformation.sServiceref))
		name = info and info.getName(service) or "Title" + sDescr
		self.DVBname = name
		self.DVBchannel = serviceref.getServiceName()
		self.inputfile = service.getPath()
		self.filesize = path.getsize(self.inputfile)
		self.estimatedDiskspace = self.filesize
		self.length = info.getLength(service)

	def initDVDmenuText(self, project, track):
		s = project.menutemplate.settings
		self.properties.menutitle.setValue(self.formatDVDmenuText(s.titleformat.getValue(), track))
		self.properties.menusubtitle.setValue(self.formatDVDmenuText(s.subtitleformat.getValue(), track))

	def formatDVDmenuText(self, template, track):
		template = template.replace("$i", str(track))
		template = template.replace("$t", self.DVBname)
		template = template.replace("$d", self.DVBdescr)
		template = template.replace("$c", str(len(self.chaptermarks)+1))
		template = template.replace("$f", self.inputfile)
		template = template.replace("$C", self.DVBchannel)
		
		#if template.find("$A") >= 0:
		from TitleProperties import languageChoices
		audiolist = [ ]
		for audiotrack in self.properties.audiotracks:
			active = audiotrack.active.getValue()
			if active:
				trackstring = audiotrack.format.getValue()
				language = audiotrack.language.getValue()
				if languageChoices.langdict.has_key(language):
					trackstring += ' (' + languageChoices.langdict[language] + ')'
				audiolist.append(trackstring)
		audiostring = ', '.join(audiolist)
		template = template.replace("$A", audiostring)

		if template.find("$l") >= 0:
			l = self.length
			lengthstring = "%d:%02d:%02d" % (l/3600, l%3600/60, l%60)
			template = template.replace("$l", lengthstring)
		if self.timeCreate:
			template = template.replace("$Y", str(self.timeCreate[0]))
			template = template.replace("$M", str(self.timeCreate[1]))
			template = template.replace("$D", str(self.timeCreate[2]))
			timestring = "%d:%02d" % (self.timeCreate[3], self.timeCreate[4])
			template = template.replace("$T", timestring)
		else:
			template = template.replace("$Y", "").replace("$M", "").replace("$D", "").replace("$T", "")
		return template

	def produceFinalCuesheet(self):
		CUT_TYPE_IN = 0
		CUT_TYPE_OUT = 1
		CUT_TYPE_MARK = 2
		CUT_TYPE_LAST = 3

		accumulated_in = 0
		accumulated_at = 0
		last_in = 0

		self.cutlist = [ ]
		self.chaptermarks = [ ]

		# our demuxer expects *strictly* IN,OUT lists.
		currently_in = not any(type == CUT_TYPE_IN for pts, type in self.cuesheet)
		if currently_in:
			self.cutlist.append(0) # emulate "in" at first		

		for (pts, type) in self.cuesheet:
			#print "pts=", pts, "type=", type, "accumulated_in=", accumulated_in, "accumulated_at=", accumulated_at, "last_in=", last_in
			if type == CUT_TYPE_IN and not currently_in:
				self.cutlist.append(pts)
				last_in = pts
				currently_in = True

			if type == CUT_TYPE_OUT and currently_in:
				self.cutlist.append(pts)

				# accumulate the segment
				accumulated_in += pts - last_in 
				accumulated_at = pts
				currently_in = False

			if type == CUT_TYPE_MARK and currently_in:
				# relocate chaptermark against "in" time. This is not 100% accurate,
				# as the in/out points are not.
				reloc_pts = pts - last_in + accumulated_in
				self.chaptermarks.append(reloc_pts)
				
		if len(self.cutlist) > 1:
			part = accumulated_in / (self.length*90000.0)
			usedsize = int ( part * self.filesize )
			self.estimatedDiskspace = usedsize
			self.length = accumulated_in / 90000

	def getChapterMarks(self, template="$h:$m:$s.$t"):
		timestamps = [ ]
		chapters = [ ]
		minutes = self.properties.autochapter.getValue()
		if len(self.chaptermarks) < 1 and minutes > 0:
			chapterpts = 0
			while chapterpts < (self.length-60*minutes)*90000:
				chapterpts += 90000 * 60 * minutes
				chapters.append(chapterpts)
		else:
			chapters = self.chaptermarks
		for p in chapters:
			timestring = template.replace("$h", str(p / (90000 * 3600)))
			timestring = timestring.replace("$m", ("%02d" % (p % (90000 * 3600) / (90000 * 60))))
			timestring = timestring.replace("$s", ("%02d" % (p % (90000 * 60) / 90000)))
			timestring = timestring.replace("$t", ("%03d" % ((p % 90000) / 90)))
			timestamps.append(timestring)
		return timestamps