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

View File

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

View File

@ -15,6 +15,20 @@ type StatusMessage struct {
ContentAvailable bool 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 { func StartReindex() bool {
fmt.Println("starting reindex..") fmt.Println("starting reindex..")
SendEvent("start") SendEvent("start")
@ -40,7 +54,7 @@ func StartReindex() bool {
return err return err
} }
if !info.IsDir() && strings.HasSuffix(info.Name(), ".mp4") { if !info.IsDir() && ValidVideoSuffix(info.Name()) {
files = append(files, info.Name()) files = append(files, info.Name())
} }
return nil return nil
@ -107,7 +121,7 @@ func StartTVShowReindex() {
} }
for _, epfile := range episodefiles { for _, epfile := range episodefiles {
if strings.HasSuffix(epfile.Name(), ".mp4") { if ValidVideoSuffix(epfile.Name()) {
elem.files = append(elem.files, epfile.Name()) elem.files = append(elem.files, epfile.Name())
} }
} }