seperate component for file drop and upload

correct save position of uploaded files
then parse video file
This commit is contained in:
2021-09-23 17:38:20 +02:00
parent d3bd810a1a
commit a92ce73806
6 changed files with 173 additions and 77 deletions

View File

@@ -4,6 +4,8 @@ import (
"fmt"
"io"
"openmediacenter/apiGo/api/api"
"openmediacenter/apiGo/database"
"openmediacenter/apiGo/videoparser"
"os"
)
@@ -12,45 +14,49 @@ func addUploadHandler() {
fmt.Println("we are in file upload handler")
fmt.Printf("permission: %s\n", ctx.PermID().String())
// get path where to store videos to
mSettings, PathPrefix, _ := database.GetSettings()
req := ctx.GetRequest()
mr, err := req.MultipartReader()
if err != nil {
return
}
length := req.ContentLength
fmt.Println(length)
//length := req.ContentLength
for {
part, err := mr.NextPart()
if err == io.EOF {
fmt.Println("part is eof")
break
}
fmt.Println(part.FormName())
var read int64
var p float32
//var read int64
//var p float32
// todo check where we want to place this file
dst, err := os.OpenFile(part.FileName(), os.O_WRONLY|os.O_CREATE, 0644)
vidpath := PathPrefix + mSettings.VideoPath + part.FileName()
dst, err := os.OpenFile(vidpath, os.O_WRONLY|os.O_CREATE, 0644)
if err != nil {
return
}
fmt.Printf("Uploading file %s\n", part.FileName())
// so now loop through every appended file and upload
buffer := make([]byte, 100000)
for {
cBytes, err := part.Read(buffer)
if cBytes > 0 {
read = read + int64(cBytes)
p = float32(read) / float32(length) * 100
fmt.Printf("progress: %v \n", p)
//read = read + int64(cBytes)
//p = float32(read) / float32(length) * 100
//fmt.Printf("progress: %v \n", p)
dst.Write(buffer[0:cBytes])
}
if err == io.EOF {
fmt.Println(cBytes)
fmt.Println("eof this file")
fmt.Printf("Finished uploading file %s\n", part.FileName())
videoparser.InitDeps(&mSettings)
videoparser.ProcessVideo(part.FileName())
break
}
}
@@ -58,6 +64,6 @@ func addUploadHandler() {
_ = dst.Close()
}
ctx.Text("finished")
ctx.Text("finished all files")
})
}

View File

@@ -11,7 +11,7 @@ import (
"strings"
)
var mSettings types.SettingsType
var mSettings *types.SettingsType
var mExtDepsAvailable *ExtDependencySupport
// default Tag ids
@@ -32,20 +32,22 @@ type VideoAttributes struct {
Width uint
}
func ReIndexVideos(path []string, sett types.SettingsType) {
func InitDeps(sett *types.SettingsType) {
mSettings = sett
// check if the extern dependencies are available
mExtDepsAvailable = checkExtDependencySupport()
fmt.Printf("FFMPEG support: %t\n", mExtDepsAvailable.FFMpeg)
fmt.Printf("MediaInfo support: %t\n", mExtDepsAvailable.MediaInfo)
}
func ReIndexVideos(path []string) {
// filter out those urls which are already existing in db
nonExisting := filterExisting(path)
fmt.Printf("There are %d videos not existing in db.\n", len(*nonExisting))
for _, s := range *nonExisting {
processVideo(s)
ProcessVideo(s)
}
AppendMessage("reindex finished successfully!")
@@ -92,8 +94,8 @@ func filterExisting(paths []string) *[]string {
return &resultarr
}
func processVideo(fileNameOrig string) {
fmt.Printf("Processing %s video-", fileNameOrig)
func ProcessVideo(fileNameOrig string) {
fmt.Printf("Processing %s video\n", fileNameOrig)
// match the file extension
r := regexp.MustCompile(`\.[a-zA-Z0-9]+$`)

View File

@@ -49,7 +49,8 @@ func StartReindex() bool {
}
// start reindex process
AppendMessage("Starting Reindexing!")
go ReIndexVideos(files, mSettings)
InitDeps(&mSettings)
go ReIndexVideos(files)
return true
}