Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Universal .srt Subtitle Player


  • Please log in to reply
9 replies to this topic
berban
  • Members
  • 202 posts
  • Last active: Apr 12 2019 01:08 AM
  • Joined: 30 Dec 2009
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.autohotke...pic.php?t=61502 to convert to srt format.)

Posted Image

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:[*:cb56wd4f]Width - the width of the subtitle area (before they start to wrap)
[*:cb56wd4f]Height - the height of the subtitle area (not really important, just has to be large enough)
[*:cb56wd4f]Color - color
[*:cb56wd4f]Font - name of font
[*:cb56wd4f]Size - font size
[*:cb56wd4f]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.
[*:cb56wd4f]ShadowOffset - The number of points the black shadow will be offset. Indicate 0 to have no shadow at all.
[*:cb56wd4f]DefaultStartingNumber - If a file has never been played before, it will start here (you'll probably want it to be 1)
[*:cb56wd4f]DefaultSpeed - default speed coefficient. (can be changed by F1-F4)
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

[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 :)

Find me on the new AutoHotkey forums and send me a message if you have a question about any of the scrips I've posted to this forum!


Bebert
  • Members
  • 84 posts
  • Last active: Jan 03 2011 06:47 AM
  • Joined: 08 Jun 2009
what a coincidence - just posted a media player script at the same time as you, and I am half way across the world ...

a treat for AHK movie buffs :)

berban
  • Members
  • 202 posts
  • Last active: Apr 12 2019 01:08 AM
  • Joined: 30 Dec 2009
haha yeah, I was just looking at that! the screenshot is platoon in media player classic. And yes I do own a wireless mouse, so i will certainly take a look at your script!

Find me on the new AutoHotkey forums and send me a message if you have a question about any of the scrips I've posted to this forum!


gahks
  • Members
  • 32 posts
  • Last active: Feb 23 2011 02:52 AM
  • Joined: 10 Jan 2009
Wow! Thanks very much for this great script! Since my first language isn't one of the most spoken languages, I watch pretty much all my movies with subtitles.

I use TheKMPlayer for playing most of my media files and it has some great features for synching/displaying subtitles. It'd be great to have some of those features in this script. Specifically:

- Increasing/decreasing font size
- Applying bold/underscored/italic style
- Changing the x/y coordinates of the subtitles - moving them around the screen
- Changing vertical alignment (aligning the subtitles to the bottom, so that longer lines aren't cut in half, when y coordinate is too high)

- Adjusting subtitle delay
- Jumping to a specific time in the subtitle

Also if you don't mind me shamelessly promoting one of my scripts:
With these you could add a pseudo-support for MicroDVD .sub files by converting them into Subrip format at runtime :D

Thanks again for this script!

Cheers,

gahks

alexball
  • Members
  • 8 posts
  • Last active: Nov 17 2012 09:57 AM
  • Joined: 04 Jun 2008
berban: The zip link you posted is dead. Could you please repost.

Thanks
Cheers
Alex

berban_
  • Members
  • 202 posts
  • Last active: Aug 05 2014 11:52 PM
  • Joined: 16 Mar 2011
Hi alexball,

Unfortunately, all AutoHotkey.net (the web host for AutoHotkey-related files) have been dead for a few months... we're having some issues with the website and it's a bit of a nuisance. But I updated the link from the first post to something that should now work so give it a try.

This is a pretty old script of mine as you can see from the post date, and it's pretty basic. But I'd be more than happy to expand it a bit if there are some features that you'd like to see in it, so just let me know if that's the case

alexball
  • Members
  • 8 posts
  • Last active: Nov 17 2012 09:57 AM
  • Joined: 04 Jun 2008
Very nice. Thanks a lot. Finaly a player that can read German umlaute, French, Portugese...

:)

Cattleya
  • Members
  • 90 posts
  • Last active: Sep 13 2013 05:11 AM
  • Joined: 28 Sep 2011

Thank you, I like your idea, and I also think about a song lyric player, like MiniLyrics did, seem also helpful happy.png

 

I found this script, seem better than your version: https://github.com/d...btitles-overlay



brian99
  • Members
  • 1 posts
  • Last active: Oct 12 2013 07:07 AM
  • Joined: 12 Oct 2013

I'm completely new to AHK, and I'm not a programmer, so my apologies if these are 'dumb' questions. I downloaded and installed AHK, then I copied the first script given into text file and ended the name .ahk

 

When I double click on the file, it keeps giving an error message and says "Must open a .srt file". I did that, but it continues to give the error message. I'm using VLC media player and I made the .ini file and put it in the VLC folder. With a video playing and a .srt file open, I still get the error message.

 

Please help!! And if I can get it working, will the hotkey also move the video forward (and back, etc)? Thanks in advance.



tuamamma
  • Members
  • 1 posts
  • Last active: Apr 02 2015 08:17 PM
  • Joined: 21 Feb 2015

Just a year and a half late :D

 

But anyway: you have to drag & drop the srt file on the AHK file. It works. Thanks scripter :)