Documentation ¶
Overview ¶
Package srtgears implements a subtitle engine for reading subtitle files, manipulating / transforming them and then saving the result into another file.
Home page: https://srt-gears.appspot.com
Open source: https://github.com/gophergala2016/srtgears
Example (Concat) ¶
This example shows how to concatenate 2 files where 2nd part of the movie starts at 51 min 15 sec.
package main import ( "github.com/icza/srtgears" "time" ) func main() { sp1, err := srtgears.ReadSrtFile("cd1.srt") check(err) // Check / handle error sp2, err := srtgears.ReadSrtFile("cd2.srt") check(err) // Check / handle error secPartStart := time.Minute*51 + time.Second*15 sp1.Concatenate(sp2, secPartStart) err = srtgears.WriteSrtFile("cd12.srt", sp1) check(err) // Check / handle error } func check(err error) {}
Output:
Example (Merge) ¶
This example shows how to merge 2 subtitle files to have a dual sub saved in Sub Station Alpha (*.ssa) format.
package main import ( "github.com/icza/srtgears" ) func main() { sp1, err := srtgears.ReadSrtFile("eng.srt") check(err) // Check / handle error sp2, err := srtgears.ReadSrtFile("hun.srt") check(err) // Check / handle error sp1.Merge(sp2) err = srtgears.WriteSsaFile("eng+hun.ssa", sp1) check(err) // Check / handle error } func check(err error) {}
Output:
Example (Misc) ¶
This example shows how to change subtitle color to yellow, move to top, remove HI (hearing impaired lines), increase display duration by 10% and save result as a Sub Station Alpha (*.ssa) file.
package main import ( "github.com/icza/srtgears" ) func main() { sp1, err := srtgears.ReadSrtFile("eng.srt") check(err) // Check / handle error sp1.SetColor("yellow") sp1.SetPos(srtgears.Top) sp1.RemoveHI() sp1.Lengthen(1.1) err = srtgears.WriteSsaFile("eng2.ssa", sp1) check(err) // Check / handle error } func check(err error) {}
Output:
Index ¶
- Constants
- Variables
- func WriteSrtFile(name string, sp *SubsPack) (err error)
- func WriteSrtTo(w io.Writer, sp *SubsPack) error
- func WriteSsaFile(name string, sp *SubsPack) (err error)
- func WriteSsaTo(w io.Writer, sp *SubsPack) (err error)
- type Pos
- type SortSubtitles
- type SubsPack
- func (sp *SubsPack) Concatenate(sp2 *SubsPack, secPartStart time.Duration)
- func (sp *SubsPack) Lengthen(factor float64)
- func (sp *SubsPack) Merge(sp2 *SubsPack)
- func (sp *SubsPack) RemoveControl()
- func (sp *SubsPack) RemoveHI()
- func (sp *SubsPack) RemoveHTML()
- func (sp *SubsPack) Scale(factor float64)
- func (sp *SubsPack) SetColor(color string)
- func (sp *SubsPack) SetPos(pos Pos)
- func (sp *SubsPack) Shift(delta time.Duration)
- func (sp *SubsPack) Sort()
- func (sp *SubsPack) Split(at time.Duration) (sp2 *SubsPack)
- func (sp *SubsPack) Stats() *SubsStats
- type SubsStats
- type Subtitle
- func (s *Subtitle) DisplayDuration() time.Duration
- func (s *Subtitle) Lengthen(factor float64)
- func (s *Subtitle) RemoveControl() (removed bool)
- func (s *Subtitle) RemoveHI() (remove bool)
- func (s *Subtitle) RemoveHTML() (removed bool)
- func (s *Subtitle) Scale(factor float64)
- func (s *Subtitle) Shift(delta time.Duration)
Examples ¶
Constants ¶
const ( // HomePage is the Srtgears home page HomePage = "https://srt-gears.appspot.com/" // Author name Author = "Andras Belicza" )
Variables ¶
var ( // Debug tells whether to print debug messages. Debug bool )
Functions ¶
func WriteSrtFile ¶
WriteSrtFile generates SubRip format (*.srt) and writes it to a file.
func WriteSrtTo ¶
WriteSrtTo generates SubRip format (*.srt) and writes it to an io.Writer.
func WriteSsaFile ¶
WriteSsaFile generates Sub Station Alpha format (*.ssa) and writes it to a file.
Types ¶
type SortSubtitles ¶
type SortSubtitles []*Subtitle
SortSubtitles is a type that implements sorting
func (SortSubtitles) Len ¶
func (s SortSubtitles) Len() int
func (SortSubtitles) Less ¶
func (s SortSubtitles) Less(i, j int) bool
func (SortSubtitles) Swap ¶
func (s SortSubtitles) Swap(i, j int)
type SubsPack ¶
type SubsPack struct {
Subs []*Subtitle
}
SubsPack represents subtitles of a movie, a collection of Subtitles and other meta info.
func ReadSrtFile ¶
ReadSrtFile reads and parses a SubRip file (*.srt) and builds the model from it.
func ReadSrtFrom ¶
ReadSrtFrom reads and parses a SubRip from an io.Reader (*.srt) and builds the model from it.
func (*SubsPack) Concatenate ¶
Concatenate concatenates another SubsPack to this. Subtitles are not copied, only their addresses are appended to ours.
In order to get correct timing for the concatenated 2nd part, timestamps of the concatenated subtitles have to be shifted with the start time of the 2nd part of the movie (which is usually the length of the first part).
Useful if movie is present in 1 part but there are 2 subtitles for 2 parts.
func (*SubsPack) Merge ¶
Merge merges another SubsPack into this to create a "dual subtitle". Subtitles are not copied, only their addresses are merged to ours.
Useful if 2 different subtitles are to be displayed at the same time, e.g. 2 different languages.
func (*SubsPack) RemoveControl ¶
func (sp *SubsPack) RemoveControl()
RemoveControl removes controls such as {\anX} (or {\aY}), {\pos(x,y)} from all subtitles.
func (*SubsPack) RemoveHI ¶
func (sp *SubsPack) RemoveHI()
RemoveHI removes hearing impaired lines from subtitles (such as "[PHONE RINGING]" or "(phone ringing)").
func (*SubsPack) RemoveHTML ¶
func (sp *SubsPack) RemoveHTML()
RemoveHTML removes HTML formatting from all subtitles.
func (*SubsPack) Scale ¶
Scale scales the timestamps of the subtitles. The duration for which subtitles are visible is not changed.
func (*SubsPack) Sort ¶
func (sp *SubsPack) Sort()
Sort sorts the subtitles by appearance timestamp.
func (*SubsPack) Split ¶
Split splits this SubsPack into 2 at the specified time. Subtitles before the split time will remain in this, subtitles after the split time will be added to a new SubsPack that is returned.
Useful to create 2 subtitles if movie is present in 2 parts but subtitle is for one.
type SubsStats ¶
type SubsStats struct { Subs int // Total number of subs. Lines int // # of lines AvgLinesPerSub float64 // Avg lines per sub Chars int // # of characters (spaces included) CharsNoSpace int // # of characters (without spaces) AvgCharsPerLine float64 // Avg chars (no space) per line Words int // # of words AvgWordsPerLine float64 // Avg words per line AvgCharsPerWord float64 // Avg chars per word TotalDispDur time.Duration // Total subtitle display time SubVisibRatio float64 // Subtitle visible ratio (compared to total time) AvgDispDurPerNonSpaceChar time.Duration // Avg. display duration per non-space char HTMLs int // # of subs having HTML formatting Controls int // # of subs having controls HIs int // # of subs having hearing impaired lines }
SubsStats is statistics that can be gathered from a SubsPack.
type Subtitle ¶
type Subtitle struct { TimeIn time.Duration // Timestamp when subtitle appears TimeOut time.Duration // Timestamp when subtitle disappears Lines []string // Lines of text to be displayed Pos Pos // Position where to display it Color string // Color of the text, HTML RRGGBB format or a color name }
Subtitle represents 1 subtitle, 1 displayable text (which may be broken into multiple lines).
func (*Subtitle) DisplayDuration ¶
DisplayDuration returns the duration for which the subtitle is visible.
func (*Subtitle) RemoveControl ¶
RemoveControl removes controls such as {\anX} (or {\aY}), {\pos(x,y)}. Returns true if controls were present.
func (*Subtitle) RemoveHI ¶
RemoveHI removes hearing impaired lines (such as "[PHONE RINGING]" or "(phone ringing)"). Returns true if HI lines were present.
func (*Subtitle) RemoveHTML ¶
RemoveHTML removes HTML formatting. Returns true if HTML formatting was present.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
packrelease
This is the main package of the packrelease tool which packs cross-compiled releases into the web/release folder, and also generates the HTML table in the format ready for the download.html.
|
This is the main package of the packrelease tool which packs cross-compiled releases into the web/release folder, and also generates the HTML table in the format ready for the download.html. |
srtgears
This is the main package of the Srtgears command line tool.
|
This is the main package of the Srtgears command line tool. |
Package exec is a parameter driven executor which parses the parameters and performs subtitle transformations.
|
Package exec is a parameter driven executor which parses the parameters and performs subtitle transformations. |