2021-02-23 16:01:29 +00:00
|
|
|
package videoparser
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2021-04-18 19:16:38 +00:00
|
|
|
"io/ioutil"
|
2021-09-23 17:45:58 +00:00
|
|
|
"openmediacenter/apiGo/config"
|
2021-02-23 16:01:29 +00:00
|
|
|
"openmediacenter/apiGo/database"
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
type StatusMessage struct {
|
|
|
|
Messages []string
|
|
|
|
ContentAvailable bool
|
|
|
|
}
|
|
|
|
|
2021-09-27 15:33:05 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2021-02-23 16:01:29 +00:00
|
|
|
func StartReindex() bool {
|
|
|
|
fmt.Println("starting reindex..")
|
2021-04-18 19:16:38 +00:00
|
|
|
SendEvent("start")
|
|
|
|
AppendMessage("starting reindex..")
|
2021-02-23 16:01:29 +00:00
|
|
|
|
2021-09-23 17:45:58 +00:00
|
|
|
mSettings, _, _ := database.GetSettings()
|
|
|
|
|
2021-02-23 16:01:29 +00:00
|
|
|
// add the path prefix to videopath
|
2021-09-23 17:45:58 +00:00
|
|
|
vidFolder := config.GetConfig().General.ReindexPrefix + mSettings.VideoPath
|
2021-02-23 16:01:29 +00:00
|
|
|
|
|
|
|
// check if path even exists
|
2021-09-23 17:45:58 +00:00
|
|
|
if _, err := os.Stat(vidFolder); os.IsNotExist(err) {
|
2021-02-23 16:01:29 +00:00
|
|
|
fmt.Println("Reindex path doesn't exist!")
|
2021-09-23 17:45:58 +00:00
|
|
|
AppendMessage(fmt.Sprintf("Reindex path doesn't exist! :%s", vidFolder))
|
2021-04-18 19:16:38 +00:00
|
|
|
SendEvent("stop")
|
2021-02-23 16:01:29 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2022-05-22 18:48:04 +00:00
|
|
|
filelist, err := ioutil.ReadDir(vidFolder)
|
2021-02-23 16:01:29 +00:00
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err.Error())
|
2022-05-22 18:48:04 +00:00
|
|
|
return false
|
2021-02-23 16:01:29 +00:00
|
|
|
}
|
2022-05-22 18:48:04 +00:00
|
|
|
|
|
|
|
var files []string
|
|
|
|
for _, file := range filelist {
|
2022-09-21 11:23:51 +00:00
|
|
|
if !file.IsDir() && ValidVideoSuffix(file.Name()) {
|
2022-05-22 18:48:04 +00:00
|
|
|
files = append(files, file.Name())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-23 16:01:29 +00:00
|
|
|
// start reindex process
|
2021-04-18 19:16:38 +00:00
|
|
|
AppendMessage("Starting Reindexing!")
|
2021-09-23 15:38:20 +00:00
|
|
|
InitDeps(&mSettings)
|
|
|
|
go ReIndexVideos(files)
|
2021-02-23 16:01:29 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2021-04-18 19:16:38 +00:00
|
|
|
type Show struct {
|
|
|
|
Name string
|
|
|
|
files []string
|
|
|
|
}
|
|
|
|
|
2021-04-16 20:44:56 +00:00
|
|
|
// StartTVShowReindex reindex dir walks for TVShow reindex
|
|
|
|
func StartTVShowReindex() {
|
2021-04-18 19:16:38 +00:00
|
|
|
fmt.Println("starting tvshow reindex..")
|
|
|
|
SendEvent("start")
|
|
|
|
AppendMessage("starting tvshow reindex...")
|
|
|
|
|
2021-07-11 12:26:10 +00:00
|
|
|
mSettings, PathPrefix, _ := database.GetSettings()
|
2021-04-18 19:16:38 +00:00
|
|
|
// add the path prefix to videopath
|
2021-07-11 12:26:10 +00:00
|
|
|
mSettings.EpisodePath = PathPrefix + mSettings.EpisodePath
|
2021-04-18 19:16:38 +00:00
|
|
|
|
|
|
|
// add slash suffix if not existing
|
|
|
|
if !strings.HasSuffix(mSettings.EpisodePath, "/") {
|
|
|
|
mSettings.EpisodePath += "/"
|
|
|
|
}
|
2021-04-16 20:44:56 +00:00
|
|
|
|
2021-04-18 19:16:38 +00:00
|
|
|
// check if path even exists
|
|
|
|
if _, err := os.Stat(mSettings.EpisodePath); os.IsNotExist(err) {
|
|
|
|
msg := fmt.Sprintf("Reindex path doesn't exist! :%s", mSettings.EpisodePath)
|
|
|
|
fmt.Println(msg)
|
|
|
|
AppendMessage(msg)
|
|
|
|
SendEvent("stop")
|
|
|
|
return
|
2021-02-23 16:01:29 +00:00
|
|
|
}
|
|
|
|
|
2021-04-18 19:16:38 +00:00
|
|
|
var files []Show
|
2021-02-23 16:01:29 +00:00
|
|
|
|
2021-04-18 19:16:38 +00:00
|
|
|
filess, err := ioutil.ReadDir(mSettings.EpisodePath)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, file := range filess {
|
|
|
|
if file.IsDir() {
|
|
|
|
elem := Show{
|
|
|
|
Name: file.Name(),
|
|
|
|
files: nil,
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println(file.Name())
|
|
|
|
|
|
|
|
episodefiles, err := ioutil.ReadDir(mSettings.EpisodePath + file.Name())
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, epfile := range episodefiles {
|
2021-09-27 15:33:05 +00:00
|
|
|
if ValidVideoSuffix(epfile.Name()) {
|
2021-04-18 19:16:38 +00:00
|
|
|
elem.files = append(elem.files, epfile.Name())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
files = append(files, elem)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
// start reindex process
|
|
|
|
AppendMessage("Starting Reindexing!")
|
2021-05-01 14:25:32 +00:00
|
|
|
go startTVShowReindex(files)
|
2021-02-23 16:01:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func StartCleanup() {
|
|
|
|
// todo start cleanup
|
|
|
|
}
|