allow more videotypes than mp4

This commit is contained in:
lukas 2021-09-27 17:33:05 +02:00
parent e4f09eddac
commit 61ea42ef01
3 changed files with 19 additions and 5 deletions

View File

@ -7,7 +7,6 @@ import (
"openmediacenter/apiGo/database"
"openmediacenter/apiGo/videoparser"
"os"
"path/filepath"
)
func addUploadHandler() {
@ -31,11 +30,11 @@ func addUploadHandler() {
break
}
// todo allow more video formats than mp4
// only allow valid extensions
if filepath.Ext(part.FileName()) != ".mp4" {
if !videoparser.ValidVideoSuffix(part.FileName()) {
continue
}
vidpath := PathPrefix + mSettings.VideoPath + part.FileName()
dst, err := os.OpenFile(vidpath, os.O_WRONLY|os.O_CREATE, 0644)
if err != nil {

View File

@ -38,6 +38,7 @@ func insertEpisodesIfNotExisting(show Show) {
fmt.Println(err.Error())
}
// todo no fixed mp4 extension here!
dbepisodes = append(dbepisodes, fmt.Sprintf("%s S%02dE%02d.mp4", epname, season, episode))
}

View File

@ -15,6 +15,20 @@ type StatusMessage struct {
ContentAvailable bool
}
func getVideoTypes() []string {
return []string{".mp4", ".mov", ".mkv", ".flv", ".avi", ".mpeg", ".m4v"}
}
func ValidVideoSuffix(filename string) bool {
validExts := getVideoTypes()
for _, validExt := range validExts {
if strings.HasSuffix(filename, validExt) {
return true
}
}
return false
}
func StartReindex() bool {
fmt.Println("starting reindex..")
SendEvent("start")
@ -40,7 +54,7 @@ func StartReindex() bool {
return err
}
if !info.IsDir() && strings.HasSuffix(info.Name(), ".mp4") {
if !info.IsDir() && ValidVideoSuffix(info.Name()) {
files = append(files, info.Name())
}
return nil
@ -107,7 +121,7 @@ func StartTVShowReindex() {
}
for _, epfile := range episodefiles {
if strings.HasSuffix(epfile.Name(), ".mp4") {
if ValidVideoSuffix(epfile.Name()) {
elem.files = append(elem.files, epfile.Name())
}
}