Created
May 9, 2020 17:31
-
-
Save mniak/7ae4f6f53c0f2728420c013bebe123a2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import srt | |
with open('legenda2.srt') as f: | |
subs = srt.parse(f.read()) | |
def corrige_coincidencia(anterior, atual): | |
if anterior is None: | |
return atual | |
anterior_linhas = anterior.content.split('\n') | |
atual_linhas = atual.content.split('\n') | |
anterior_ultimalinha = anterior_linhas[-1] | |
atual_primeiralinha = atual_linhas[0] | |
if anterior_ultimalinha == atual_primeiralinha: | |
atual_linhas = atual_linhas[1:] | |
atual.content = '\n'.join(atual_linhas) | |
return atual | |
novalista = [] | |
anterior = None | |
for atual in subs: | |
if (atual.end - atual.start).microseconds <= 20000: | |
continue | |
atual = corrige_coincidencia(anterior, atual) | |
novalista.append(atual) | |
anterior = atual | |
with open('legenda_filtrada.srt', 'w+') as f: | |
f.write(srt.compose(novalista)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment