More foundations for clips
This commit is contained in:
@@ -32,8 +32,8 @@ var ytdlpVideoOptions = []string{"-f", "bestaudio"}
|
||||
type DisplayVideoClip struct {
|
||||
TempURL
|
||||
ID uint // VideoClip.ID
|
||||
Start float64
|
||||
Stop float64
|
||||
Start string
|
||||
Stop string
|
||||
}
|
||||
|
||||
func registerHandler(c echo.Context) error {
|
||||
@@ -882,8 +882,8 @@ func videoHandler(c echo.Context) error {
|
||||
clipDisplays = append(clipDisplays, DisplayVideoClip{
|
||||
TempURL: tempURL,
|
||||
ID: clip.ID,
|
||||
Start: float64(1000 * clip.StartMS),
|
||||
Stop: float64(1000 * clip.StopMS),
|
||||
Start: fmt.Sprintf("%.2f", float64(1000*clip.StartMS)),
|
||||
Stop: fmt.Sprintf("%.2f", float64(1000*clip.StopMS)),
|
||||
})
|
||||
}
|
||||
|
||||
|
58
handlers/clip.go
Normal file
58
handlers/clip.go
Normal file
@@ -0,0 +1,58 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"ytdlp-site/config"
|
||||
"ytdlp-site/database"
|
||||
"ytdlp-site/ffmpeg"
|
||||
"ytdlp-site/media"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
func ClipPost(c echo.Context) error {
|
||||
|
||||
videoID := c.FormValue("video_id")
|
||||
|
||||
fromSecs, err := strconv.ParseFloat(c.FormValue("from_secs"), 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if fromSecs < 0 {
|
||||
fromSecs = 0
|
||||
}
|
||||
toSecs, err := strconv.ParseFloat(c.FormValue("to_secs"), 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var video media.Video
|
||||
err = database.Get().Where("id = ?", videoID).First(&video).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
dstBase := uuid.Must(uuid.NewV7()).String()
|
||||
dstName := dstBase + filepath.Ext(video.Filename)
|
||||
dstPath := filepath.Join(config.GetDataDir(), dstName)
|
||||
|
||||
srcPath := filepath.Join(config.GetDataDir(), video.Filename)
|
||||
log.Debugf("Clip from %s [%f-%f]", srcPath, fromSecs, toSecs)
|
||||
err = ffmpeg.Clip(srcPath, dstPath, fromSecs, toSecs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
clip := media.VideoClip{
|
||||
VideoFile: video.VideoFile,
|
||||
OriginalID: video.OriginalID,
|
||||
VideoID: video.ID,
|
||||
StartMS: uint(fromSecs*1000 + 0.5),
|
||||
StopMS: uint(toSecs*1000 + 0.5),
|
||||
}
|
||||
clip.Filename = dstName
|
||||
|
||||
return database.Get().Create(&clip).Error
|
||||
}
|
@@ -47,6 +47,7 @@ type VideoClip struct {
|
||||
gorm.Model
|
||||
VideoFile
|
||||
OriginalID uint // Original.ID
|
||||
VideoID uint // Video.ID that this clip was made from
|
||||
StartMS uint
|
||||
StopMS uint
|
||||
}
|
||||
|
Reference in New Issue
Block a user