subtitle formats: comments are specs only
This commit is contained in:
1 parent
5d4addfc01
commit
6f8456246f
3 files changed
+19
-47
No files matched your search
@@ -1,10 +1,7 @@
|
||||
--!strict
|
||||
-- subtitle/vtt: WebVTT (W3C WebVTT, 2019 CR). Supports: the WEBVTT header (its trailing text and header lines kept in
|
||||
-- meta.header), cue identifiers, `[hh:]mm:ss.ttt` timings, cue settings (cue.settings, as written), NOTE comments
|
||||
-- (meta.notes), STYLE blocks (meta.css) and REGION blocks (meta.regions); BOM, CRLF / CR line ends. Cue text is kept
|
||||
-- as written (<i> / <b> / <c.class> / <v Name> spans, timestamps, entities).
|
||||
-- Encode: the header, STYLE / REGION blocks, then the cues (times to the millisecond); blank lines inside cue text
|
||||
-- are dropped and `-->` escaped (WebVTT cue text cannot hold them).
|
||||
-- subtitle/vtt: WebVTT (W3C WebVTT, 2019 CR). Supports: the header (meta.header), cue ids, `[hh:]mm:ss.ttt` timings,
|
||||
-- cue settings, NOTE (meta.notes), STYLE (meta.css) and REGION (meta.regions) blocks, BOM, CRLF / CR; cue text as
|
||||
-- written. Encode drops blank lines in cue text and escapes `-->` (cue text cannot hold them).
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ requires
|
||||
local Err = require("@rosetta/core/Err")
|
||||
@@ -23,7 +20,7 @@ local Vtt = {
|
||||
}
|
||||
|
||||
export type DecodeOptions = {
|
||||
maxBytes: number?, -- refuse larger files (default 64 MB)
|
||||
maxBytes: number?, -- default 64 MB
|
||||
}
|
||||
export type EncodeOptions = {}
|
||||
|
||||
@@ -32,7 +29,6 @@ local function frac(digits: string): number
|
||||
return (tonumber(digits) :: number) / 10 ^ #digits
|
||||
end
|
||||
|
||||
-- one timestamp at the start of s: seconds, the rest | nil
|
||||
local function timestamp(s: string): (number?, string)
|
||||
local h, m, sec, f, rest = string.match(s, "^(%d+):(%d%d):(%d%d)%.(%d+)(.*)$")
|
||||
if h then
|
||||
@@ -45,7 +41,6 @@ local function timestamp(s: string): (number?, string)
|
||||
return nil, s
|
||||
end
|
||||
|
||||
-- timing(line) -> start, stop, settings | nil
|
||||
local function timing(line: string): (number?, number?, string?)
|
||||
local a, rest = timestamp((string.gsub(line, "^%s+", "")))
|
||||
if not a then
|
||||
@@ -110,7 +105,6 @@ function Vtt.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Subtitles?, E
|
||||
i += 1
|
||||
continue
|
||||
end
|
||||
-- a block: lines up to the next blank
|
||||
local first = i
|
||||
while i <= n and lines[i] ~= "" do
|
||||
i += 1
|
||||
@@ -160,7 +154,6 @@ local function stamp(t: number): string
|
||||
return string.format("%02d:%02d:%02d.%03d", ms // 3600000, ms // 60000 % 60, ms // 1000 % 60, ms % 1000)
|
||||
end
|
||||
|
||||
-- one block's text: no blank lines (they end a block), no `-->`
|
||||
local function clean(s: string): string
|
||||
s = string.gsub(s, "\r\n?", "\n")
|
||||
s = string.gsub(s, "\n[ \t]*\n", "\n")
|
||||
|
||||
Reference in new issue
Block a user