| 1 |
#!/usr/bin/env python3 |
| 2 |
|
| 3 |
# Copyright 2014 (C) Raster Software Vigo (Sergio Costas) |
| 4 |
# |
| 5 |
# This file is part of DeVeDe-NG |
| 6 |
# |
| 7 |
# DeVeDe-NG is free software; you can redistribute it and/or modify |
| 8 |
# it under the terms of the GNU General Public License version 3 |
| 9 |
# as published by the Free Software Foundation. |
| 10 |
# |
| 11 |
# DeVeDe-NG is distributed in the hope that it will be useful, |
| 12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
# GNU General Public License for more details. |
| 15 |
# |
| 16 |
# You should have received a copy of the GNU General Public License |
| 17 |
# along with this program. If not, see <http://www.gnu.org/licenses/> |
| 18 |
|
| 19 |
import os |
| 20 |
import subprocess |
| 21 |
|
| 22 |
import devedeng.configuration_data |
| 23 |
import devedeng.executor |
| 24 |
|
| 25 |
class subtitles_mux(devedeng.executor.executor): |
| 26 |
|
| 27 |
def __init__(self): |
| 28 |
|
| 29 |
devedeng.executor.executor.__init__(self) |
| 30 |
self.config = devedeng.configuration_data.configuration.get_config() |
| 31 |
|
| 32 |
def multiplex_subtitles(self, file_path, subtitles_path, subt_codepage, subt_lang, |
| 33 |
subt_upper, font_size, pal, force_subtitles, aspect, duration, stream_id, fill_color, outline_color, outline_thick): |
| 34 |
|
| 35 |
if len(fill_color) == 4: |
| 36 |
fill_color = fill_color[:3] |
| 37 |
if len(outline_color) == 4: |
| 38 |
outline_color = outline_color[:3] |
| 39 |
|
| 40 |
self.subt_path = file_path |
| 41 |
self.duration = duration |
| 42 |
self.text = _("Adding %(L)s subtitles to %(X)s") % { |
| 43 |
"X": os.path.basename(file_path), "L": subt_lang} |
| 44 |
|
| 45 |
out_xml = open(file_path + "_s" + str(stream_id) + ".xml", "w") |
| 46 |
out_xml.write('<subpictures format="') |
| 47 |
if pal: |
| 48 |
out_xml.write('PAL') |
| 49 |
else: |
| 50 |
out_xml.write('NTSC') |
| 51 |
out_xml.write('">\n') |
| 52 |
out_xml.write('\t<stream>\n') |
| 53 |
out_xml.write('\t\t<textsub filename="') |
| 54 |
out_xml.write(self.expand_xml(subtitles_path)) |
| 55 |
out_xml.write('" characterset="') |
| 56 |
out_xml.write(self.expand_xml(subt_codepage)) |
| 57 |
out_xml.write('" fontsize="') |
| 58 |
out_xml.write(str(font_size)) |
| 59 |
if subt_upper: |
| 60 |
out_xml.write('" bottom-margin="50') |
| 61 |
out_xml.write('" fill-color="#%02X%02X%02X"' % |
| 62 |
tuple([int(fill_color[i] * 255) for i in range(len(fill_color))])) |
| 63 |
out_xml.write(' outline-color="#%02X%02X%02X"' % |
| 64 |
tuple([int(outline_color[i] * 255) for i in range(len(outline_color))])) |
| 65 |
out_xml.write(' outline-thickness="%d"' % outline_thick) |
| 66 |
out_xml.write( |
| 67 |
' font="arial" horizontal-alignment="center" vertical-alignment="bottom" aspect="') |
| 68 |
out_xml.write(str(aspect)) |
| 69 |
out_xml.write('" force="') |
| 70 |
if force_subtitles: |
| 71 |
out_xml.write('yes') |
| 72 |
else: |
| 73 |
out_xml.write('no') |
| 74 |
out_xml.write('" />\n') |
| 75 |
out_xml.write('\t</stream>\n') |
| 76 |
out_xml.write('</subpictures>') |
| 77 |
out_xml.close() |
| 78 |
|
| 79 |
self.command_var = [] |
| 80 |
self.command_var.append("spumux") |
| 81 |
mode = self.config.disc_type |
| 82 |
if mode == "vcd": |
| 83 |
mode = "svcd" |
| 84 |
self.command_var.append("-m") |
| 85 |
self.command_var.append(mode) |
| 86 |
self.command_var.append("-s") |
| 87 |
self.command_var.append(str(stream_id)) |
| 88 |
self.command_var.append(file_path + "_s" + str(stream_id) + ".xml") |
| 89 |
self.stdin_file = file_path + ".tmp" |
| 90 |
self.stdout_file = file_path |
| 91 |
|
| 92 |
def pre_function(self): |
| 93 |
|
| 94 |
final_path = self.subt_path + ".tmp" |
| 95 |
if os.path.exists(final_path): |
| 96 |
os.remove(final_path) |
| 97 |
os.rename(self.subt_path, final_path) |
| 98 |
|
| 99 |
def process_stderr(self, data): |
| 100 |
|
| 101 |
if (data is None) or (len(data) == 0): |
| 102 |
return |
| 103 |
|
| 104 |
if self.duration == 0: |
| 105 |
return |
| 106 |
|
| 107 |
if data[0].startswith("STAT: "): |
| 108 |
time_pos = data[0][6:].split(":") |
| 109 |
current_time = 0 |
| 110 |
for t in time_pos: |
| 111 |
current_time *= 60 |
| 112 |
current_time += float(t) |
| 113 |
t = current_time / self.duration |
| 114 |
self.progress_bar[1].set_fraction(t) |
| 115 |
self.progress_bar[1].set_text("%.1f%%" % (100.0 * t)) |
| 116 |
|
| 117 |
return |