X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=srt2vtt%2Fsubrip.scm;h=0031db363eafd1a2b5b70774a0f73a4fc757a7f9;hb=HEAD;hp=167aff804a4b1d8c8b24f3902ce425c1e4f2f350;hpb=b965a6d6326e67df0b0909065119c59563da8db2;p=srt2vtt.git diff --git a/srt2vtt/subrip.scm b/srt2vtt/subrip.scm index 167aff8..0031db3 100644 --- a/srt2vtt/subrip.scm +++ b/srt2vtt/subrip.scm @@ -26,22 +26,27 @@ read-subrips)) (define parse-time - (let ((regexp (make-regexp "([0-9]+):([0-9]+):([0-9]+),([0-9]+)"))) + (let ((regexp (make-regexp "^([0-9]+):([0-9]+):([0-9]+),([0-9]+)$"))) (lambda (s) "Parse the SubRip formatted timestamp in the string S into a 4 element list. Valid input looks like '00:00:03.417'." (let ((match (regexp-exec regexp s))) - (map (cut match:substring match <>) '(1 2 3 4)))))) + (if match + (map (compose string->number (cut match:substring match <>)) + '(1 2 3 4)) + (error "Invalid SubRip timestamp: " s)))))) (define parse-time-span - (let ((regexp (make-regexp "([0-9:,]+) --> ([0-9:,]+)"))) + (let ((regexp (make-regexp "^([0-9:,]+) --> ([0-9:,]+)$"))) (lambda (s) "Parse the SubRip formatted time span in the string S and return two values: the start time and the end time. Valid input looks like '00:00:03.417 --> 00:00:04.936'." (let ((match (regexp-exec regexp s))) - (values (parse-time (match:substring match 1)) - (parse-time (match:substring match 2))))))) + (if match + (values (parse-time (match:substring match 1)) + (parse-time (match:substring match 2))) + (error "Invalid SubRip time range: " s)))))) (define (read-subrip port) "Read a SubRip formatted subtitle from PORT." @@ -53,7 +58,7 @@ two values: the start time and the end time. Valid input looks like (and (string-null? line) ;; A subtitle may be a blank line! (not (null? lines)))) - lines + (reverse lines) (loop (cons line lines))))))) (make-subtitle id start end lines)))