subtitle

package module
v0.0.0-...-d44f19e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 15, 2017 License: BSD-2-Clause Imports: 10 Imported by: 2

README

subtitle: Go package for handing movie subtitle

Package subtitle reads subtitle book from srt and smi file. And, provide fuctions to display each script on time.

Usage

import "github.com/suapapa/go_subtitle"

Functions

Fmt Read Export
srt O O
smi O X

Checkout following projects for example

  • github.com/suapapa/tools/smi2srt
  • github.com/suapapa/subtitle-raider

Documentation

Overview

Package subtitle reads subtitle book from srt and smi file. And, provide fuctions to display each script on time.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExportToSrtFile

func ExportToSrtFile(b Book, w io.Writer) error

ExportToSrtFile export script book in SRT format

Types

type Book

type Book []Script

Book is collection of scripts

func ReadSmi

func ReadSmi(r io.Reader) (book Book, err error)

ReadSmi read smi scripts from data stream

func ReadSrt

func ReadSrt(r io.Reader) (Book, error)

ReadSrt read srt format subtitle from data slice

func (Book) Find

func (b Book) Find(ts time.Duration) *Script

Find a script on given timestamp. If not hit, it returns next script. So, caller should re-check the script is hit on the timestamp.

type HitStatus

type HitStatus uint8

HitStatus is type for timestamp check

const (
	ScrINVALID HitStatus = iota
	ScrEARLY             // Not yet
	ScrHIT               // Now
	ScrLATE              // Gone
)

type Script

type Script struct {
	Idx        int
	Start, End time.Duration
	Text       string
}

Script represents a script with index and start/end time

func (*Script) CheckHit

func (s *Script) CheckHit(ts time.Duration) HitStatus

CheckHit checks the script with given timestamp

func (*Script) Duration

func (s *Script) Duration() time.Duration

Duration returns how long the script should be shown

func (*Script) String

func (s *Script) String() string

func (*Script) TextWithoutMarkup

func (s *Script) TextWithoutMarkup() string

TextWithoutMarkup strips HTML markup from script

type State

type State uint8

State represents current parsing state

const (
	StateFindTag State = iota
	StateIdle
	StateSync
	StateText
	StateBr
)

StateMachine to parse SAMI subtitle

func (State) String

func (s State) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL