Download here
I've recently been watching movies online, and have been frustrated by subtitles. Not so much the availability of subtitle files - you can find .srt subtitle files in many languages across the internet. Rather, playing them/getting them to sync correctly with videos has been very difficult. So I figured I'd just write my own program, as .srt subtitle files are very basic plain-text based files.
(For .sub files, see this
http://www.autohotkey.com/forum/viewtopic.php?t=61502 to convert to srt format.)
The main features that I wanted to incorporate were:
-Navigation by means of skipping to next/previous subtitle, rather than by time.
-Ability to increment/decrement speed very precisely
-Playing subtitles over
any program, such as a flash video embedded in a website (netflix's online player is shown in the screenshot).
Here is the code. The idea is that you set your .srt subtitle files to open with the .exe file as the default program, then "open" the srt file and fiddle with the speed until it syncs. (Also put the .ini file in the same directory as the exe.)
Controls: (editable of course)
- "F8" for next subtitle, "F7" for previous subtitle
- "F6" to fast forward 20 subtitles, "F5" to rewind 20 subtitles
- "F1" to slow speed .1%, "F2" to increase speed .1%
- "F3" to slow speed .01%, "F4" to speed .01%
- "F9" to pause/unpause, "F10" to suspend/unsuspend the controls
- Ctrl+F6 to open the .ini file. When you close the text document, it'll ask you if you'd like to apply the changes you implemented.
- Ctrl+Delete to exit
- Click on the subtitles & drag to move them (it can be a bit tricky, try pausing before you do this so they don't change on you.)
Other than that, some details:
- Tooltips near the mouse will indicate changes (e.g. speed). Alternately, you can hover over the icon in the system tray, which will also show subtitle number.
- It will start on the first subtitle, rather than waiting the prescribed amount of time before the first line, because the beginning of movies is the most variable part - plus, then you'd have to open both files simultaneously
- If you open the same file again, it will start on the last played subtitle, and at the same speed.
- Settings are in Subtitles.ini:
- Width - the width of the subtitle area (before they start to wrap)
- Height - the height of the subtitle area (not really important, just has to be large enough)
- Color - color
- Font - name of font
- Size - font size
- yCor - default y coordinate of subtitle location. Probably something high, so they'll be at the bottom of your screen. You can always move them by click and drag.
- ShadowOffset - The number of points the black shadow will be offset. Indicate 0 to have no shadow at all.
- DefaultStartingNumber - If a file has never been played before, it will start here (you'll probably want it to be 1)
- DefaultSpeed - default speed coefficient. (can be changed by F1-F4)
Code:
StartOver:
SetWorkingDir, %A_ScriptDir%
SetBatchLines, -1
DetectHiddenWindows, On
Paused = -1
Suspended = -1
Loaded = %1%
FileGetSize, FileSize, %Loaded%
If Not ((SubStr(Loaded, -2) = "srt") and FileSize) {
Msgbox Must open a .srt file.
ExitApp
}
OnExit, LastSubtitle
IniRead, Width, Subtitles.ini, Settings, Width
IniRead, Height, Subtitles.ini, Settings, Height
IniRead, Color, Subtitles.ini, Settings, Color
IniRead, Font, Subtitles.ini, Settings, Font
IniRead, Size, Subtitles.ini, Settings, Size
IniRead, yCor, Subtitles.ini, Settings, yCor
IniRead, ShadowOffset, Subtitles.ini, Settings, ShadowOffset
IniRead, CachedSettings, Subtitles.ini, CachedSettings, %FileSize%, 0
If CachedSettings {
StringSplit, CachedSettings, CachedSettings, |
Number := CachedSettings1, Speed := CachedSettings2, CachedSettings1 := "", CachedSettings2 := "", CachedSettings := ""
Text := "Continuing at #" Number "`nSpeed = " RegExReplace(Speed, "\.?0*$")
} Else {
IniRead, Number, Subtitles.ini, Settings, DefaultStartingNumber
IniRead, Speed, Subtitles.ini, Settings, DefaultSpeed
Text = Closed Captions`nby Berban
}
SoundPlay, %A_WinDir%\Media\Ding.wav
Gui, Color, 111111
If ShadowOffset {
Gui, Font, s%Size% c000000, %Font%
Gui, Add, Text, w%Width% h%Height% x0 y0 Center BackgroundTrans gMoveSubtitles, %Text%
}
Gui, Font, s%Size% c%Color%, %Font%
Gui, Add, Text, w%Width% h%Height% x%ShadowOffset% y%ShadowOffset% Center BackgroundTrans gMoveSubtitles, %Text%
Gui, +ToolWindow -SysMenu -Caption +AlwaysOnTop
Gui, Show, NA AutoSize y%yCor%
Process, Exist
WinSet, TransColor, 0x111111, ahk_pid %ErrorLevel%
Sleep 1000
FileRead, Subs, %Loaded%
Subs := RegExReplace(Subs, "^\s+")
Subs := RegExReplace(Subs, "\s+$")
Subs := RegExReplace(Subs, "\R(\S+) --> (\S+)\R", "°$1°$2°")
Subs := RegExReplace(Subs, "U)<.*>")
StringReplace, Subs, Subs, `r`n`r`n, ¢, All
Loop, Parse, Subs, ¢
{
StringSplit, %A_Index%Subs, A_LoopField, °
%A_Index%Subs2 := SubStr(%A_Index%Subs2, 1, 2) * 3600000 + SubStr(%A_Index%Subs2, 4, 2) * 60000 + SubStr(%A_Index%Subs2, 7, 2) * 1000 + SubStr(%A_Index%Subs2, 10, 3)
%A_Index%Subs3 := SubStr(%A_Index%Subs3, 1, 2) * 3600000 + SubStr(%A_Index%Subs3, 4, 2) * 60000 + SubStr(%A_Index%Subs3, 7, 2) * 1000 + SubStr(%A_Index%Subs3, 10, 3)
i++
}
Subs =
GuiShow:
GuiControl, Text, Static1, % %Number%Subs4
If ShadowOffset
GuiControl, Text, Static2, % %Number%Subs4
Menu, Tray, Tip, % "Subtitle " . Number . "/" . i . "`nSpeed: " . Round(Speed, 4)
SetTimer, GuiHide, % -1 * Abs(Floor((%Number%Subs3 - %Number%Subs2 - 100) / Speed))
Gui, Show, NA AutoSize
Hide = 0
Return
GuiHide:
GuiControl, Text, Static1
If ShadowOffset
GuiControl, Text, Static2
Number1 := Number + 1
If Not %Number1%Subs2 {
Pause, ON, 1
Paused = 1
} Else
SetTimer, GuiShow, % -1 * Abs(Floor((%Number1%Subs2 - %Number%Subs3 + 100) / Speed))
Number := Number1
Hide = 1
Return
F4::
Speed += .001
Speed := Round(Speed, 3)
ToolTip, % "Subtitle Speed: " . Round(Speed, 3)
SetTimer, ToolTipOff, -700
Return
F3::
Speed -= .001
Speed := Round(Speed, 3)
ToolTip, % "Subtitle Speed: " . Round(Speed, 3)
SetTimer, ToolTipOff, -700
Return
F2::
Speed += .0001
ToolTip, % "Subtitle Speed: " . Round(Speed, 4)
SetTimer, ToolTipOff, -700
Return
F1::
Speed -= .0001
ToolTip, % "Subtitle Speed: " . Round(Speed, 4)
SetTimer, ToolTipOff, -700
Return
F8::
If Hide {
SetTimer, GuiShow, Off
GoTo GuiShow
} Else {
SetTimer, GuiHide, Off
Number++
GoTo GuiShow
}
Return
F7::
If Hide {
SetTimer, GuiShow, Off
Number--
GoTo GuiShow
} Else {
SetTimer, GuiHide, Off
Number--
GoTo GuiShow
}
Return
F6::
If Hide {
SetTimer, GuiShow, Off
Number += 19
GoTo GuiShow
} Else {
SetTimer, GuiHide, Off
Number += 20
GoTo GuiShow
}
Return
F5::
If Hide {
SetTimer, GuiShow, Off
Number -= 20
GoTo GuiShow
} Else {
SetTimer, GuiHide, Off
Number -= 20
GoTo GuiShow
}
Return
^Del::ExitApp
F9::
Pause, , 1
Paused := Paused * -1
If (Paused + 1) {
TrayTip, , Subtitles Paused, 3
ToolTip
SoundBeep, 1000, 100
} Else {
TrayTip, , Subtitles Playing, 3
SoundBeep, 1000, 100
SoundBeep, 1000, 100
}
Return
F10::
Suspend
Suspended := Suspended * -1
If (Suspended + 1) {
ToolTip, Hotkeys Suspended
SetTimer, ToolTipOff, -700
SoundBeep, 2000, 100
} Else {
ToolTip, Hotkeys Enabled
SetTimer, ToolTipOff, -700
SoundBeep, 2000, 100
SoundBeep, 2000, 100
}
Return
^F6::
Run, Subtitles.ini
WinWait, Subtitles.ini
WinWaitClose, Subtitles.ini
MsgBox, 4, Subtitles, Apply desired changes to subtitles?
IfMsgBox YES
{
GoSub SaveGUI
SetTimer, GuiShow, Off
SetTimer, GuiHide, Off
Suspend, OFF
Pause, OFF
GoTo StartOver
}
Return
MoveSubtitles:
PostMessage, 0xA1, 2,,, A
Return
ToolTipOff:
ToolTip
Return
SaveGUI:
Gui, Destroy
IniWrite, %Number%|%Speed%, Subtitles.ini, CachedSettings, %FileSize%
Return
LastSubtitle:
Menu, Tray, NoIcon
GoSub SaveGUI
SoundPlay, %A_WinDir%\Media\Windows Default.wav, Wait
ExitApp
Return
The ini file
Code:
[Settings]
Width=1200
Height=400
Color=FFFFFF
Font=Veranda
Size=40
yCor=600
ShadowOffset=2
DefaultStartingNumber=1
DefaultSpeed=1.015
[CachedSettings]
;this section will just accumulate keys: the key is the size of a subtitle file - a good name-independent marker, and the other side has the speed and number that subtitle file was last played at. You can delete these at any time if there are too many.
110638=672|1.007200
110234=4|1.015
If there's anything you want changed, you can just ask me cause as you see it is a very, very simple app and changes would be easy - this is just how I prefer my captions to look. Or you can just do it yourself
