#!/usr/bin/env python # -*- coding: UTF-8 -*- # Copyright 2006-2009 (C) Raster Software Vigo (Sergio Costas) # Copyright 2006-2009 (C) Peter Gill - win32 parts # This file is part of DeVeDe # # DeVeDe is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # DeVeDe is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . import signal import os import sys import re import shutil import devede_executor import devede_other class subtitles_adder(devede_executor.executor): def expand_xml(self,text): text=text.replace('&','&') text=text.replace('<','<') text=text.replace('>','>') text=text.replace('"','"') text=text.replace("'",''') return text def __init__(self,videofile,filename,filefolder,progresbar,proglabel,disctype,title,chapter,stream): """ This class adds the subtitles to an already converted file VIDEOFILE contains the parameters to convert the video FILENAME is the generic file name given by the user FILEFOLDER is the path where all the temporary and finall files will be created PROGRESBAR is the progress bar where the class will show the progress PROGLABEL is the label where the class will show what is it doing DISCTYPE can be dvd, vcd, svcd, cvd or divx TITLE and CHAPTER are the numbers used to identify the TITLE and CHAPTER number for this file STREAMS is the stream number (to allow to add several subtitles) """ devede_executor.executor.__init__(self,filename,filefolder,progresbar) progresbar.pulse() proglabel.set_text(_("Adding subtitles to")+"\n"+videofile["filename"]) self.currentfile=self.create_filename(filefolder+filename,title,chapter,disctype=="divx") subtitle_list=videofile["sub_list"][stream] # generate the XML file self.error="" try: print "Trying to create "+filefolder+filename+"_sub.xml" fichero=open(filefolder+filename+"_sub.xml","w") except IOError: print "IOError en subtitulos" self.print_error=_("Failed to write to the destination directory.\nCheck that you have privileges and free space there.") self.initerror=True return fichero.write('\n\t') if (subtitle_list["sub_codepage"]!="UTF-8"): final_type="UTF-8" subfilename=os.path.join(filefolder,filename+"_sub_tmp.sub") self.deletesub=subfilename if 0!=devede_other.check_utf().convert_to_UTF8(subtitle_list["subtitles"],subfilename,subtitle_list["sub_codepage"]): #except IOError: print "IOError al convertir a UTF8" self.print_error=_("Failed to write to the destination directory.\nCheck that you have privileges and free space there.") self.initerror=True return else: self.deletesub="" final_type=subtitle_list["sub_codepage"] subfilename=subtitle_list["subtitles"] fichero.write('\n\t\t') fichero.write("\n\t\n") fichero.close() comando="" if (sys.platform=="win32") or (sys.platform=="win64"): comando=["spumux.exe"] comando.append("-m") if disctype=="vcd": comando.append("svcd") else: comando.append(disctype) comando.append("-s") comando.append(str(stream)) comando.append(filefolder+filename+"_sub.xml") comando.append("-i") comando.append(self.currentfile) comando.append("-o") comando.append(self.currentfile+".sub") self.print_error=_("Conversion failed.\nIt seems a bug of SPUMUX.") self.launch_program(comando,output=False) else: comando="spumux -m " if disctype=="vcd": comando+="svcd" else: comando+=disctype comando+=' -s '+str(stream)+' "'+filefolder+filename+'_sub.xml"' self.print_error=_("Conversion failed.\nIt seems a bug of SPUMUX.") self.launch_shell(comando,output=True,stdinout=[self.currentfile,self.currentfile+".sub"]) def end_process(self,eraser,erase_temporal_files): shutil.move(self.currentfile+".sub", self.currentfile) if erase_temporal_files: eraser.delete_sub_xml(self.deletesub) def set_progress_bar(self): self.bar.pulse() position=self.cadena.find("STAT: ") if (position!=-1): position2=self.cadena.find(".",position+6) if position2!=-1: self.bar.set_text(self.cadena[position:position2]) return True