feat: handle subtitles for video streaming (format code)
This commit is contained in:
parent
d82bce8e33
commit
4b2f3feca1
@ -1,24 +1,24 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
"os"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"bytes"
|
||||
fb "github.com/filebrowser/filebrowser"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
func subtitlesHandler(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) {
|
||||
files, err := ReadDir(filepath.Dir(c.File.Path))
|
||||
if(err != nil) {
|
||||
if err != nil {
|
||||
return http.StatusInternalServerError, err
|
||||
}
|
||||
var subtitles = make([]map[string]string, 0)
|
||||
for _, file := range files {
|
||||
ext := filepath.Ext(file.Name())
|
||||
if(ext == ".vtt" || ext == ".srt") {
|
||||
if ext == ".vtt" || ext == ".srt" {
|
||||
var sub map[string]string = make(map[string]string)
|
||||
sub["src"] = filepath.Dir(c.File.Path) + "/" + file.Name()
|
||||
sub["kind"] = "subtitles"
|
||||
@ -57,12 +57,12 @@ func subtitleHandler(c *fb.Context, w http.ResponseWriter, r *http.Request) (int
|
||||
|
||||
func CleanSubtitle(filename string) (string, error) {
|
||||
b, err := ioutil.ReadFile(filename)
|
||||
if(err != nil) {
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
str := string(b) // convert content to a 'string'
|
||||
ext := filepath.Ext(filename)
|
||||
if(ext == ".srt") {
|
||||
if ext == ".srt" {
|
||||
re := regexp.MustCompile("([0-9]{2}:[0-9]{2}:[0-9]{2}),([0-9]{3})")
|
||||
str = "WEBVTT\n\n" + re.ReplaceAllString(str, "$1.$2")
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user