Documentation
¶
Overview ¶
Package subtitle finds a video's subtitle tracks, embedded or in files next to it, and serves the text ones as WebVTT for the web player.
Index ¶
- Variables
- func APILanguage(code string) string
- func APILanguageInfo(code string) (iso, variant, name string)
- func FileHash(path string) (string, error)
- func FoundLabel(name string, forced, sdh bool) (string, string)
- type Converter
- type Found
- type OpenSubtitles
- type OpenSubtitlesKey
- type Query
- type Track
Constants ¶
This section is empty.
Variables ¶
var ( // ErrBadKey means OpenSubtitles turned the API key down. ErrBadKey = errors.New("OpenSubtitles didn't accept the API key") // ErrBadLogin means OpenSubtitles turned the username or password down. ErrBadLogin = errors.New("OpenSubtitles didn't accept the username or password") // ErrQuota means today's downloads are used up. ErrQuota = errors.New("today's OpenSubtitles downloads are used up") )
var OpenSubtitlesBase = "https://api.opensubtitles.com/api/v1"
OpenSubtitlesBase is the API. The docs' screenshot server points it at a stand-in at build time.
Functions ¶
func APILanguage ¶ added in v0.1.10
APILanguage turns a language code into the API's own: pt-BR is pt-br, Simplified Chinese is zh-cn, Norwegian Bokmål is no. Unknown ones give "".
func APILanguageInfo ¶ added in v0.1.10
APILanguageInfo is fromAPILanguage for a code from a client, which may be the API's own (pt-br) or ISO 639-1 (pt).
Types ¶
type Converter ¶
Converter turns subtitle tracks into WebVTT and caches the results, so each track is converted once per version of its file.
func NewConverter ¶
func (*Converter) Serve ¶
func (c *Converter) Serve(w http.ResponseWriter, r *http.Request, videoPath string, t Track, all []Track)
Serve writes track t of the video at videoPath as WebVTT. all lists the video's tracks: the first request for an embedded track extracts every embedded text track in one pass, since that costs one read of the file.
type Found ¶ added in v0.1.10
type Found struct {
// ID is the API's file id, passed back to add it.
ID int64 `json:"id"`
Language string `json:"language,omitempty"` // ISO 639-1, such as en
// Variant is the API's own language code where it says more, such as
// pt-br or zh-tw.
Variant string `json:"variant,omitempty"`
Label string `json:"label"` // in English, such as "Portuguese (Brazil)"
Release string `json:"release,omitempty"`
SDH bool `json:"sdh,omitempty"`
Forced bool `json:"forced,omitempty"`
// Machine is true for files a machine translated.
Machine bool `json:"machine,omitempty"`
Downloads int `json:"downloads"`
// MatchesFile is true when the file was made for this very video file,
// so its timing fits.
MatchesFile bool `json:"matchesFile,omitempty"`
// Trusted is true when a trusted member uploaded it.
Trusted bool `json:"trusted,omitempty"`
}
Found is a subtitle file the search turned up.
type OpenSubtitles ¶ added in v0.1.10
type OpenSubtitles struct {
Key OpenSubtitlesKey
Base string // OpenSubtitlesBase, or a test server
UserAgent string // "Matinee v1.2.3": the API asks every app to name itself
HTTP *http.Client
// contains filtered or unexported fields
}
OpenSubtitles searches opensubtitles.com and fetches its files.
func (*OpenSubtitles) Check ¶ added in v0.1.10
func (o *OpenSubtitles) Check(ctx context.Context) error
Check makes sure the API key works, and the username and password when they're given.
type OpenSubtitlesKey ¶ added in v0.1.10
type OpenSubtitlesKey struct {
APIKey string `json:"apiKey"`
Username string `json:"username,omitempty"`
Password string `json:"password,omitempty"`
}
OpenSubtitlesKey is what an admin entered. It stays on the server.
type Query ¶ added in v0.1.10
type Query struct {
// TMDBID is a movie's TMDB id; ShowTMDBID with Season and Episode
// find an episode.
TMDBID int64
ShowTMDBID int64
Season int
Episode int
// Title and Year find a video with no TMDB id: an episode's show title.
Title string
Year int
// Hash is the file's OpenSubtitles hash (see FileHash): subtitles made
// for this very file are marked.
Hash string
// Languages are ISO 639-1 codes, or the API's own, such as pt-br.
Languages []string
}
Query is what's known about a video.
type Track ¶
type Track struct {
ID string `json:"id"` // "e<N>" for embedded stream N, "x<hash>" for a sidecar file
Label string `json:"label"` // in English, such as "English (SDH)"
// Note is the track's own title, where it says more than its language
// and flags, such as "Commentary", so apps can build a label in their
// own language.
Note string `json:"note,omitempty"`
Language string `json:"language,omitempty"` // ISO 639-1 where known, e.g. "en"
Codec string `json:"codec"`
Forced bool `json:"forced,omitempty"`
Default bool `json:"default,omitempty"`
SDH bool `json:"sdh,omitempty"`
External bool `json:"external,omitempty"`
// BurnIn marks picture-based subtitles (PGS, VobSub, DVB), which browsers
// can't render: the server draws them into the video during a transcode.
BurnIn bool `json:"burnIn,omitempty"`
// Found marks subtitles someone found online for the video (see
// OpenSubtitles); Removable says the person asking may remove them.
Found bool `json:"found,omitempty"`
Removable bool `json:"removable,omitempty"`
Stream int `json:"-"` // embedded: index among the file's subtitle streams
Path string `json:"-"` // external: the sidecar file
}
Track is one subtitle track a player can offer.