diff --git a/apiGo/api/FileUpload.go b/apiGo/api/FileUpload.go index 3f5c148..70ca94b 100644 --- a/apiGo/api/FileUpload.go +++ b/apiGo/api/FileUpload.go @@ -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 { diff --git a/apiGo/videoparser/ReIndexTVShows.go b/apiGo/videoparser/ReIndexTVShows.go index f496add..d138c17 100644 --- a/apiGo/videoparser/ReIndexTVShows.go +++ b/apiGo/videoparser/ReIndexTVShows.go @@ -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)) } diff --git a/apiGo/videoparser/VideoParser.go b/apiGo/videoparser/VideoParser.go index d64a01e..3c3e67d 100644 --- a/apiGo/videoparser/VideoParser.go +++ b/apiGo/videoparser/VideoParser.go @@ -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()) } }