本文整理汇总了Python中pysrt.SubRipFile.open方法的典型用法代码示例。如果您正苦于以下问题:Python SubRipFile.open方法的具体用法?Python SubRipFile.open怎么用?Python SubRipFile.open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pysrt.SubRipFile
的用法示例。
在下文中一共展示了SubRipFile.open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_videos_to_index
# 需要导入模块: from pysrt import SubRipFile [as 别名]
# 或者: from pysrt.SubRipFile import open [as 别名]
def add_videos_to_index(subtitle_index, output_file, index):
vindexReader = csv.reader(open(subtitle_index, 'rb'))
vinfoWriter = csv.writer(open(output_file, 'wt'))
vinfoWriter.writerow(['title', 'filename', 'id', 'views', 'type', 'url', 'text'])
for row in vindexReader:
try:
filename = row[1] + '.en.srt'
url = 'http://www.youtube.com/watch?v=' + row[2]
text = open(filename).read()
text_ascii = removeNonAscii(text)
subtitles = SubRipFile.open(filename)
vinfoWriter.writerow([row[0], row[1], row[2], row[3], row[4], url, text_ascii])
punctuation = '!"#$%&\'()*+,-./:;<=>[email protected][\\]^_`{|}~'
stopwords = ['']
with open('/Users/connormendenhall/Python/DaveDaveFind/DaveDaveFind/data/stopwords.csv', 'rb') as f:
wordlist = csv.reader(f)
for stopword in wordlist:
stopwords.append(stopword[0])
for sentence in subtitles:
text = (sentence.text)
wordlist = text.split()
for word in wordlist:
word = word.lstrip(punctuation)
word = word.rstrip(punctuation)
word = word.lower()
if word not in stopwords:
add_to_index(index, word, url)
except:
pass
print "[add_videos_to_index()] Videos added."
return index
示例2: mostrarSubtitulos
# 需要导入模块: from pysrt import SubRipFile [as 别名]
# 或者: from pysrt.SubRipFile import open [as 别名]
def mostrarSubtitulos(self, escena, ruta):
if (self.ok==1):
self.escena= escena
#subs = SubRipFile.open(ruta, encoding='iso-8859-1')
subs = SubRipFile.open(ruta, encoding='UTF-8') # Con esta codificacion logramos ver los tildes
#print("Hay" ,subs.__len__()," subtitulos")
#print "SEGUNDOS=", cant_segs
if (self.tmp== subs.__len__()): # cuando llega al final de los subtitulos
#self.tmp= subs.__len__()-1
self.tmp= 0
self.ok= 0
#print("entro en tiempo " ,self.tiempoActual)
self.tiempoActual= 0
linea= subs[self.tmp]
tics_ini = (linea.start.minutes*60*1000)+(linea.start.seconds*1000)+linea.start.milliseconds
tics_fin = (linea.end.minutes*60*1000)+(linea.end.seconds*1000)+linea.end.milliseconds
if ((tics_ini<=(pygame.time.get_ticks()-self.offset)) and ((pygame.time.get_ticks()-self.offset)<=tics_fin)):
if (self.imprimir==1):
self.escena.draw() # reimprime la escena
self.printTexto(linea.text) # imprime mensaje
self.imprimir= 0
self.tmp= self.tmp+1
self.entrar= 1
else:
if (self.entrar==1):
self.printTexto("")
self.imprimir= 1
self.entrar=0
示例3: input_file
# 需要导入模块: from pysrt import SubRipFile [as 别名]
# 或者: from pysrt.SubRipFile import open [as 别名]
def input_file(self):
if not hasattr(self, '_source_file'):
with open(self.arguments.file, 'rb') as f:
content = f.read()
encoding = detect(content).get('encoding')
encoding = self.normalize_encoding(encoding)
self._source_file = SubRipFile.open(self.arguments.file,
encoding=encoding, error_handling=SubRipFile.ERROR_LOG)
return self._source_file
示例4: test_eol_conversion
# 需要导入模块: from pysrt import SubRipFile [as 别名]
# 或者: from pysrt.SubRipFile import open [as 别名]
def test_eol_conversion(self):
input_file = open(self.windows_path, 'rU')
input_file.read()
self.assertEquals(input_file.newlines, '\r\n')
srt_file = SubRipFile.open(self.windows_path, encoding='windows-1252')
srt_file.save(self.temp_path, eol='\n')
output_file = open(self.temp_path, 'rU')
output_file.read()
self.assertEquals(output_file.newlines, '\n')
示例5: save
# 需要导入模块: from pysrt import SubRipFile [as 别名]
# 或者: from pysrt.SubRipFile import open [as 别名]
def save(self, *args, **kwargs):
episode = super(Episode, self).save(*args, **kwargs)
# Delete existing subtitles
self.subtitle_set.all().delete()
# Import subtitles from file
subs = SubRipFile.open(self.subtitles.path)
with transaction.commit_on_success():
for sub in subs:
self.subtitle_set.create(
start=sub.start.ordinal, end=sub.end.ordinal,
text=sub.text)
示例6: generate_vocap_file
# 需要导入模块: from pysrt import SubRipFile [as 别名]
# 或者: from pysrt.SubRipFile import open [as 别名]
def generate_vocap_file(self):
######### Generate subs in vocap format
subs = SubRipFile.open(self.path+"/"+self.srt_file, encoding="utf-8")
fileobj=codecs.open(self.path+"/"+self.vocap_file, "w", "utf-8")
for i in range(len(subs)):
text = subs[i].text
text = text.replace(u"###", u"#.#.#")
text = text.replace(u"\n", u" ")
#text = cgi.escape(text)
start = subs[i].start.seconds
start += 60*subs[i].start.minutes
start += 3600*subs[i].start.hours
time = unicode(str(start),"utf-8")
line = u"###"+time+u" "+text+u"\n"
fileobj.write(line)
fileobj.close()
示例7: __init__
# 需要导入模块: from pysrt import SubRipFile [as 别名]
# 或者: from pysrt.SubRipFile import open [as 别名]
def __init__(self, filename):
self.filename = filename
self.model = Gtk.ListStore(object, str)
self.srt_model = []
if not os.path.exists(filename) :
raise(FileNameError(filename))
try:
self.srt_model = SubRipFile.open(path=filename)
except UnicodeDecodeError as unic:
debug(unic)
try:
info("trying ...", "ISO-8859-1")
self.srt_model = SubRipFile(path = filename, encoding = "iso-8859-1")
except Exception as excep :
debug(excep)
self.model = None
except IOError as error:
info("Impossible de lire le fichier de sous titre: error {}".format(error))
for line in self.srt_model:
# print("appending",line)
self.model.append([line, line.text])
示例8: get_video_length
# 需要导入模块: from pysrt import SubRipFile [as 别名]
# 或者: from pysrt.SubRipFile import open [as 别名]
length1Time = get_video_length(args.inputVideo1[0])
offset2Time = SubRipTime.from_string(zeroTime)
inVid1 = args.inputVideo1[0]
if args.offset2:
offset2Time = SubRipTime.from_string(args.offset2[0])
length1Time = SubRipTime.from_string(zeroTime)
offset2 = args.offset2[0]
inSubName1 = args.input1
inSubName2 = args.input2
outSubName = args.output
if args.encoding:
encoding = args.encoding[0]
else:
encoding = args.encoding
try:
inSub1 = SubRipFile.open(inSubName1,encoding)
except AttributeError:
print "No such file: ",inSubName1
sys.exit(1)
except LookupError:
print "No such encoding: ",encoding
sys.exit(1)
except UnicodeDecodeError:
print "Not encoded as utf-8"
sys.exit(1)
try:
inSub2 = SubRipFile.open(inSubName2,encoding)
except AttributeError:
print "No such file: ",inSubName1
sys.exit(1)
except LookupError:
示例9: test_compare_from_string_and_from_path
# 需要导入模块: from pysrt import SubRipFile [as 别名]
# 或者: from pysrt.SubRipFile import open [as 别名]
def test_compare_from_string_and_from_path(self):
unicode_content = codecs.open(self.utf8_path, encoding="utf_8").read()
iterator = izip(SubRipFile.open(self.utf8_path), SubRipFile.from_string(unicode_content))
for file_item, string_item in iterator:
self.assertEquals(unicode(file_item), unicode(string_item))
示例10: test_save
# 需要导入模块: from pysrt import SubRipFile [as 别名]
# 或者: from pysrt.SubRipFile import open [as 别名]
def test_save(self):
srt_file = SubRipFile.open(self.windows_path, encoding="windows-1252")
srt_file.save(self.temp_path, eol="\n", encoding="utf-8")
self.assertEquals(open(self.temp_path, "rb").read(), open(self.utf8_path, "rb").read())
os.remove(self.temp_path)
示例11: test_utf8
# 需要导入模块: from pysrt import SubRipFile [as 别名]
# 或者: from pysrt.SubRipFile import open [as 别名]
def test_utf8(self):
self.assertEquals(len(SubRipFile.open(self.utf8_path)), 1332)
self.assertRaises(UnicodeDecodeError, SubRipFile.open, self.windows_path, encoding="utf_8")
示例12: test_windows1252
# 需要导入模块: from pysrt import SubRipFile [as 别名]
# 或者: from pysrt.SubRipFile import open [as 别名]
def test_windows1252(self):
srt_file = SubRipFile.open(self.windows_path, encoding="windows-1252")
self.assertEquals(len(srt_file), 1332)
self.assertEquals(srt_file.eol, "\r\n")
self.assertRaises(UnicodeDecodeError, SubRipFile.open, self.utf8_path, encoding="ascii")
示例13: numbers
# 需要导入模块: from pysrt import SubRipFile [as 别名]
# 或者: from pysrt.SubRipFile import open [as 别名]
import glob
# Change paths where applicable
path = "/home/elastictest/srt/"
x = glob.glob(path + '*.srt')
EsPath = "http://192.168.1.48:2600/subtitles/subtitle/"
for i in x:
# This needs to change for the srt paths sonwell has as they are numbers (just get a key/val of the numbers)
subsName = i
subsName = subsName[:-4]
subsName = subsName.replace(path, '')
# // end needs to change
subs = SubRipFile.open(i)
for i, val in enumerate(subs):
d = {}
d['title'] = subsName
h = str(subs[i].start.hours).zfill(2)
m = str(subs[i].start.minutes).zfill(2)
s = str(subs[i].start.seconds).zfill(2)
ms = str(subs[i].start.milliseconds).zfill(3)
hms = '%s:%s:%s,%s' % (h, m, s, ms)
d['startTime'] = hms
h = str(subs[i].end.hours).zfill(2)
m = str(subs[i].end.minutes).zfill(2)
s = str(subs[i].end.seconds).zfill(2)
ms = str(subs[i].end.milliseconds).zfill(3)
hms = '%s:%s:%s,%s' % (h, m, s, ms)
d['endTime'] = hms
示例14: test_file_with_empty_items
# 需要导入模块: from pysrt import SubRipFile [as 别名]
# 或者: from pysrt.SubRipFile import open [as 别名]
def test_file_with_empty_items(self):
path = os.path.join(self.base_path, "empty.srt")
file = SubRipFile.open(path)
self.assertEquals(len(file), 7)
示例15: test_save
# 需要导入模块: from pysrt import SubRipFile [as 别名]
# 或者: from pysrt.SubRipFile import open [as 别名]
def test_save(self):
srt_file = SubRipFile.open(self.windows_path, encoding='windows-1252')
srt_file.save(self.temp_path, eol='\n', encoding='utf-8')
self.assertEquals(open(self.temp_path, 'rb').read(),
open(self.utf8_path, 'rb').read())
os.remove(self.temp_path)