[Python-es] Renombrar subtítulos según archivos de video.

Manuel malvarez99 en gmail.com
Lun Mayo 9 15:29:26 EDT 2016


Hola amigos. 

Llevo desde hace un tiempo queriendo un script que al chequear un directorio y ver que hay archivos de video y de subtítulos, 
si los 4 o 5 primeros caracteres coinciden entre ellos, me renombre los subtítulos acorde al nombre del video. 

Videos:
House.Of.Cards.4x01.mp4
Elementary S04E16 HDTV x264-LOL EZTV.mkv

Subtítulos:
Elementary 4x16 - Hounded (Español).srt
House of Cards (2013) 4x01 - Chapter 40 (Español).srt

El código que os adjunto, me renombra la primera coincidencia que encuentra, pero se para ahí y no continua. 
Os agradecería cualquier comentario y/o ayuda. 

Un saludo. 
Manuel.


#!/usr/local/bin/python3.5
 
import os
import os.path
 
archivos = os.listdir(os.getcwd())
lista_videos = []
lista_subtitulos = []
 
for archivo in archivos:
    if archivo.endswith('mkv') or archivo.endswith('mp4'):
        lista_videos.append(archivo)
    elif archivo.endswith('srt'):
        lista_subtitulos.append(archivo)
 
for video in lista_videos:
    for subtitulo in lista_subtitulos:
        for i in range(0,len(lista_videos)):
 
            if subtitulo[i][0:4] == video[i][0:4]:
                subtitulo_final = video[0:-4] + '.srt'
                os.rename(subtitulo, subtitulo_final)

------------ próxima parte ------------
Se ha borrado un adjunto en formato HTML...
URL: <http://mail.python.org/pipermail/python-es/attachments/20160509/0929affe/attachment.html>


Más información sobre la lista de distribución Python-es