wesbos / Wes-Bos-Captions

Captions for my video courses
477 stars 320 forks source link

SRT subtitles #49

Closed medovarsky closed 6 years ago

medovarsky commented 6 years ago

Hi, I've created SRT subtitle types for wider media player compatibility (namely VLC 2). The conversion was made using shell, find and sed using the following script:

!/bin/bash

cd JS3 for f in .vtt; do cp "$f" "$(basename "$f" .vtt).srt"; done find . -type f -exec sed -e 's/(.\:)([0-9][0-9]).([0-9][0-9][0-9].)/\1\2,\3/g' -i {} \; find . -type f -name \.srt -exec sed -e 's/^WEBVTT//g' -i {} \;

Feel free to merge. Thanks!

wesbos commented 6 years ago

Thanks - I would like to make something to convert these on demand rather than managing two different sets of files - can you explain the regex? What is the difference?

medovarsky commented 6 years ago

The regex simply replaces decimal points with commas in "HH:MM:SS.sss" time format by capturing the time information with decimal point between "SS" and "sss" parts and rewriting it with comma instead. I'd rather suggest the improved capture format to avoid ambiguence:

find . -type f -exec sed -e 's/\([0-9][0-9]:[0-9][0-9]:[0-9][0-9]\)\.\([0-9][0-9][0-9]\)\ -->\ \([0-9][0-9]:[0-9][0-9]:[0-9][0-9]\)\.\([0-9][0-9][0-9].*\)/\1,\2\ -->\ \3,\4/g' -i {} ;

The second regex line removes "WEBVTT" at the beginning of the line.

wesbos commented 6 years ago

thank you - I think what I'll do is translate these on the fly or on commit - having separate files will cause eveything to get out of sync pretty quickyl