Sign in to follow this  
Followers 0
niklas

Rename subtitles.

3 posts in this topic

#1 ·  Posted (edited)

I made a script that gives subtitles the same name that videos have. Mostly because I watch a lot of tv shows and renaming many seasons of subtitles is really boring.

The script is working so I thought I'd share it if someone else wants it, and perhaps get some advice on how to improve it? :( I'm no good with Autoit so the code might look 'newbish' :)

There's one catch, the script finds the first .srt and the first .avi in the folder, gives them the same name then moves on to the next. So the files must be in perfect order or they will be all mixed up.

Global $fileavi
Global $filesrt
Global $filesrt2
Global $fileavi2

; Sets ESC to terminate the script.
HotKeySet("{ESC}", "Terminate")

Func Terminate()
    Exit 0
EndFunc

; Search for all .srt files.
$searchsrt = FileFindFirstFile("*.srt")
; Check if the search was successful
If $searchsrt = -1 Then
    MsgBox(0, "Error", "Can't find any .srt files (must be located in same dir.")
    Exit
EndIf

; Search for all .avi files.
$searchavi = FileFindFirstFile("*.avi")
; Check if the search was successful
If $searchavi = -1 Then
    MsgBox(0, "Error", "Can't find any .avi files (must be located in same dir.)")
    Exit
EndIf

findsub()
; Find the first/next .srt file.
Func findsub()
    $filesrt = FileFindNextFile($searchsrt)
    If @error Then Exit
    $filesrt2 = StringTrimRight($filesrt, 3)
    findavi()
EndFunc

; Find the first/next .avi file & check if the subtitle needs to be renamed.
Func findavi()
    $fileavi = FileFindNextFile($searchavi)
    If @error Then Exit
    $fileavi2 = StringTrimRight($fileavi, 3)

    If $filesrt2 = $fileavi2 Then
        findsrt()
    Else
        rename()
    EndIf
EndFunc

; Give the subtitle the same name as the video (.avi).
Func rename()
FileMove($filesrt, $fileavi2 & "srt")
findsub()
EndFunc

; Close the search handle
FileClose($searchsrt)
FileClose($searchavi)
Edited by niklas

Share this post


Link to post
Share on other sites



wow fast reply, thanks :(

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0