資源簡介
WebVTT字幕格式轉(zhuǎn)換為SRT字幕格式,Python+PyQt4

代碼片段和文件信息
#!/usr/bin/python
#?-*-?coding:?utf-8?-*-
import?sys
import?re
from?PyQt4?import?QtGui
from?vtt2srt_ui?import?Ui_vtt2srt
class?VTT2SRT(QtGui.QMainWindow?Ui_vtt2srt):
????def?__init__(self?parent=None):
????????super(VTT2SRT?self).__init__(parent)
????????self.setupUi(self)
????????self.show()
????????self.output_button.clicked.connect(lambda:?self.open_file(1))
????????self.input_button.clicked.connect(lambda:?self.open_file(0))
????????self.convert.clicked.connect(self.vtt2srt)
????def?open_file(self?flag):
????????fname?=?QtGui.QFileDialog.getOpenFileName(self?u‘打開文件‘)
????????if?flag?==?1:
????????????self.output_file.setText(fname)
????????else:
????????????self.input_file.setText(fname)
????def?vtt2srt(self):
????????infile?=?self.input_file.text()
????????outfile?=?self.output_file.text()
????????#?using?thread?is?more?reasonable
????????inf?=?open(infile?‘r‘)
????????outf?=?open(outfile?‘w‘)
????????line?=?inf.readline()
????????rep?=?re.compile(‘\.‘)
????????for?line?in?inf:
????????????if?re.search(‘^WEBVTT‘?line):
????????????????continue
????????????if?re.search(‘^[0-9][0-9]:[0-9][0-9].+?-->‘?line):
????????????????line?=?rep.sub(‘‘?line)
????????????outf.write(line)
????????inf.close()
????????outf.close()
def?main():
????app?=?QtGui.QApplication(sys.argv)
????vtt2srt?=?VTT2SRT()
????sys.exit(app.exec_())
if?__name__?==?‘__main__‘:
????main()
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2015-11-22?13:49??Convert?WebVTT?to?SRT\
?????文件????????5856??2015-11-22?13:28??Convert?WebVTT?to?SRT\python?vtt?轉(zhuǎn)?srt.md
?????文件????11023133??2015-11-22?13:42??Convert?WebVTT?to?SRT\vtt2srt.exe
?????文件????????3821??2015-11-21?22:52??Convert?WebVTT?to?SRT\vtt2srt.png
?????文件????????1462??2015-11-21?22:22??Convert?WebVTT?to?SRT\vtt2srt.py
?????文件????????2753??2015-11-21?20:13??Convert?WebVTT?to?SRT\vtt2srt_ui.py
評論
共有 條評論