Browse Source

Added code

master
Patrick G 2 years ago
commit
9fd176d5ac
Signed by: geek1011 GPG Key ID: A2FD79F68A2AB707
3 changed files with 51 additions and 0 deletions
  1. +20
    -0
      main.go
  2. +25
    -0
      srt2vtt/srt2vtt.go
  3. +6
    -0
      vendor/vendor.json

+ 20
- 0
main.go View File

@ -0,0 +1,20 @@
package main
import (
"fmt"
"io/ioutil"
"os"
"git.geek1011.net/geek1011/srt2vtt/srt2vtt"
)
func main() {
bytes, err := ioutil.ReadAll(os.Stdin)
if err != nil {
fmt.Fprintf(os.Stderr, "Error reading stdin: %v\n", err)
}
str := string(bytes)
print(srt2vtt.Convert(str))
}

+ 25
- 0
srt2vtt/srt2vtt.go View File

@ -0,0 +1,25 @@
package srt2vtt
import (
"fmt"
"regexp"
)
// Convert converts a string from SRT to WebVTT
func Convert(srt string) string {
vtt := srt
regexps := map[string]string{
`\{\\([ibu])\}`: `</$1>`,
`\{\\([ibu])1\}`: `<$1>`,
`\{([ibu])\}`: `<$1>`,
`\{\/([ibu])\}`: `</$1>`,
`(\d\d:\d\d:\d\d),(\d\d\d)`: `$1.$2`,
}
for find, replace := range regexps {
vtt = regexp.MustCompile(find).ReplaceAllString(vtt, replace)
}
return fmt.Sprintf("WEBVTT FILE\n\n%s", vtt)
}

+ 6
- 0
vendor/vendor.json View File

@ -0,0 +1,6 @@
{
"comment": "",
"ignore": "test",
"package": [],
"rootPath": "git.geek1011.net/geek1011/srt2vtt"
}