commit c782d7505d2481993f034dc8c80060f1ae176698
parent 2be3531b0dcadd5c29adc1fff94844876de00afe
Author: Oliver Lowe <o@olowe.co>
Date: Wed, 23 Apr 2025 09:07:04 +1000
m3u8: parse media sequence in one hit
Since we're just parsing an integer we can just try to parse the next
token from the lexer, like how we parse the playlist version.
Diffstat:
1 file changed, 3 insertions(+), 14 deletions(-)
diff --git a/m3u8/parse.go b/m3u8/parse.go
@@ -4,7 +4,6 @@ import (
"errors"
"fmt"
"io"
- "regexp"
"strconv"
"strings"
"time"
@@ -87,11 +86,12 @@ func Decode(rd io.Reader) (*Playlist, error) {
case tagEndList:
p.End = true
case tagMediaSequence:
- val, err := parseSequence(lex)
+ it = <-lex.items
+ seq, err := strconv.Atoi(it.val)
if err != nil {
return p, fmt.Errorf("parse media sequence: %w", err)
}
- p.Sequence = val
+ p.Sequence = seq
}
}
}
@@ -388,14 +388,3 @@ func parseByteRange(s string) (ByteRange, error) {
}
return ByteRange{n, nn}, nil
}
-
-func parseSequence(lex *lexer) (int, error) {
- re := regexp.MustCompile(`#EXT-X-MEDIA-SEQUENCE:(\d+)`)
-
- match := re.FindStringSubmatch(lex.input)
- if len(match) > 1 {
- return strconv.Atoi(match[1])
- }
-
- return 0, fmt.Errorf("invalid sequence number")
-}