automatically upload nearby thumbnail.png

This commit is contained in:
ari melody 2026-06-23 18:28:50 +01:00
parent fc1d6b20c1
commit 2fcbc31f77
Signed by: ari
GPG key ID: 60B5F0386E3DDB7E
4 changed files with 75 additions and 19 deletions

View file

@ -7,6 +7,7 @@ import (
"os"
"path"
"strconv"
"strings"
"arimelody.space/vodular/youtube"
ffmpeg "github.com/u2takey/ffmpeg-go"
@ -23,15 +24,15 @@ type (
func ConcatVideo(video *youtube.Video, vodFiles []string, verbose bool) (int64, error) {
fileListPath := path.Join(
path.Dir(video.Filename),
path.Dir(video.Filepath),
"files.txt",
)
totalDuration := float64(0.0)
fileListString := ""
fileListString := strings.Builder{}
for _, file := range vodFiles {
fileListString += fmt.Sprintf("file '%s'\n", file)
jsonProbe, err := ffmpeg.Probe(path.Join(path.Dir(video.Filename), file))
fmt.Fprintf(&fileListString, "file '%s'\n", file)
jsonProbe, err := ffmpeg.Probe(path.Join(path.Dir(video.Filepath), file))
if err != nil {
return 0, fmt.Errorf("failed to probe file `%s`: %v", file, err)
}
@ -45,7 +46,7 @@ func ConcatVideo(video *youtube.Video, vodFiles []string, verbose bool) (int64,
}
err := os.WriteFile(
fileListPath,
[]byte(fileListString),
[]byte(fileListString.String()),
0644,
)
if err != nil {
@ -55,7 +56,7 @@ func ConcatVideo(video *youtube.Video, vodFiles []string, verbose bool) (int64,
stream := ffmpeg.Input(fileListPath, ffmpeg.KwArgs{
"f": "concat",
"safe": "0",
}).Output(video.Filename, ffmpeg.KwArgs{
}).Output(video.Filepath, ffmpeg.KwArgs{
"c": "copy",
}).OverWriteOutput()
if verbose { stream = stream.ErrorToStdOut() }
@ -70,7 +71,7 @@ func ConcatVideo(video *youtube.Video, vodFiles []string, verbose bool) (int64,
// not the end of the world; move along
}
fileInfo, err := os.Stat(video.Filename)
fileInfo, err := os.Stat(video.Filepath)
if err != nil { return 0, fmt.Errorf("failed to read output file: %v", err) }
return fileInfo.Size(), nil