私は2つのサブタイトルブロックをマージして、簡単に翻訳を使用しようとしています。文章をマージして終了時間を変更することができますが、私はインデックス番号を変更することに問題があります。 count変数はインクリメントされますが、インデックスから減算されることはありません。問題がある2つのサブタイトルブロックをマージする
5
00:00:23,315 --> 00:00:25,108
A streetwise but soulful
teen needed somewhere to live
6
00:00:25,192 --> 00:00:26,610
as he waited for his Juilliard audition.
7
00:00:26,693 --> 00:00:29,488
We'd support his dancing and let
him stay in the guest room, right.
5および6をマージしようとしている:私たちは、この字幕ブロックを持っている場合たとえば、
。終了時間でしょう、それは合併だとき、それは私が5と6のインデックスを取得する必要がありますが、代わりに、私は5を取得し、私が作るしようとしているものの7
例を除いてもworkjs 6と:
5
00:00:23,315 --> 00:00:26,610
A streetwise but soulful
teen needed somewhere to live
as he waited for his Juilliard audition.
6
00:00:26,693 --> 00:00:29,488
We'd support his dancing and let
him stay in the guest room, right.
これは私のコードです。私は2つの場所を追加しようとしましたが、subs[sub.index].index = subs[sub.index] - count
を試しましたが、そのどれもはうまくいきませんでした。
import pysrt
import os
count = 0
# Init pysrt
subs = pysrt.open(" Bojack Horseman36.srt")
# Go through each subtitle
for sub in subs:
try:
# Check if it's a sentence if not check if there is another sentence there if not nothing just remove index
sentence = None
if subs[sub.index].text.endswith('.') or subs[sub.index].text.endswith('?') or subs[sub.index].text.endswith('!'):
subs[sub.index].index - count
else:
subs[sub.index].text = subs[sub.index].text + '\n' + subs[sub.index+1].text
count+=1
subs[sub.index].index - count
subs[sub.index].end = subs[sub.index+1].end
del subs[sub.index+1]
except IndexError:
pass
subs.save('translatedsubs.srt', encoding='utf-8')
すべてのヘルプは感謝感謝されようとしている:D
マージされた出力が実際にどのように表示されるべきかを含めることができます。これにより、理解するのがはるかに明確になります。 –
@MartinEvans今すぐチェック – MatejMecka