I have tried to make a folder action that renames the subtitle file and moves it with the video file to another folder.
Once the folder gets a new subtitle file, it compares the first 4 characters of the subtitle file with the name of every video file in the folder, if it matchs, it renames the subtitle. (That´s how it should work)
Sometimes when there are 2 or 3 files in the folder, it works. But when I have several subtitles and video files, it does not.
The source code is in spanish. If anyone wants it in english, please let me know.
on adding folder items to this_folder after receiving these_items
subtituloSeries()
end adding folder items to
on subtituloSeries()
tell application "Finder"
delay 1
-- Indicamos las carpetas de origen y destino para los subtitulos y videos
set origen to folder "TV SERIES" of disk "WINOSX"
set destinofinal to alias "WINOSX:TV SERIES:Series Subtituladas:"
-- Hacemos una lista con las extensiones de video que buscará
set listaExtensiones to {"mkv", "mp4", "avi"}
try
-- Inciamos un bucle para que cuente el numero de archivos en origen
repeat with i from 1 to the count of files in origen
-- Asignamos a subtituloBajado el archvivo de subtitulo
set subtituloBajado to (item i of origen whose name extension is "srt")
-- Asignamos a capituloBajado el archivo de video
set capituloBajado to (item i of origen whose name extension is in listaExtensiones)
set nombrecapitulo to name of capituloBajado
-- Asignamos a NombrecapituloSinExtension el nombre del capitulo sin extensión
set NombrecapituloSinExtension to (characters 1 thru -5 in nombrecapitulo as string)
-- Aqui comprobamos que si el subtitulo contiene los primeros 4 caracteres del nombre del episodio, renombre el subtitulo al capitulo y le añada la extension srt
if name of subtituloBajado contains (characters 1 thru 4) in nombrecapitulo then
set the name of subtituloBajado to NombrecapituloSinExtension & ".srt"
end if
-- Chequeamos si existe un subtitulo con el mismo nombre que un capitulo, y si es así los mueve al destino final (Carpeta de Series Subtituladas)
if name of subtituloBajado contains NombrecapituloSinExtension then
delay 2
move subtituloBajado to destinofinal
delay 2
move capituloBajado to destinofinal
end if
end repeat
end try
end tell
end subtituloSeries