Skip to content

Commit 5dc9f9e

Browse files
author
zhengkeyan
committed
增加-cprt来自动识别同名文件
1 parent b06d0d8 commit 5dc9f9e

File tree

4 files changed

+21
-5
lines changed

4 files changed

+21
-5
lines changed

build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
version="1.5.1"
2+
version="1.5.2"
33
sourceVer=$(git log --date=iso --pretty=format:"%h @%cd" -1)
44
buildTime="$(date '+%Y-%m-%d %H:%M:%S') by $(go version|sed 's/go version //')"
55
cat <<EOF | gofmt >common/version.go

common/synthesis.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/sirupsen/logrus"
88
"m4s-converter/conver"
99
"os"
10+
"os/exec"
1011
"path/filepath"
1112
"strconv"
1213
"strings"
@@ -83,6 +84,8 @@ func (c *Config) Synthesis() {
8384
if itemId == 0 || e != nil {
8485
itemId, _ = js.Get("owner_id").Int()
8586
}
87+
c.ItemId = strconv.Itoa(itemId)
88+
8689
if status != "completed" && status != "视频已缓存完成" {
8790
skipFilePaths = append(skipFilePaths, v)
8891
logrus.Warn("未缓存完成,跳过合成", v, title+"-"+uname)
@@ -102,12 +105,12 @@ func (c *Config) Synthesis() {
102105
mp4Name := title + conver.Mp4Suffix
103106
outputFile := filepath.Join(groupDir, mp4Name)
104107
newFile := filepath.Join(groupPath, mp4Name)
105-
if Exist(outputFile) && c.Skip {
108+
if c.Skip || Exist(outputFile) && c.findMp4Info(outputFile, c.ItemId) {
106109
logrus.Warn("跳过已合成的文件:", newFile)
107110
continue
108111
}
109112
if Exist(outputFile) && !c.Overlay {
110-
outputFile = filepath.Join(groupDir, title+strconv.Itoa(itemId)+conver.Mp4Suffix)
113+
outputFile = filepath.Join(groupDir, title+c.ItemId+conver.Mp4Suffix)
111114
}
112115

113116
if er := c.Composition(video, audio, outputFile); er != nil {
@@ -135,6 +138,17 @@ func (c *Config) Synthesis() {
135138
c.wait()
136139
}
137140

141+
func (c *Config) findMp4Info(fp, sub string) bool {
142+
if !Exist(c.GPACPath) {
143+
return false
144+
}
145+
ret, err := exec.Command(c.GPACPath, "-info", fp).CombinedOutput()
146+
if err != nil {
147+
return false
148+
}
149+
return strings.Contains(string(ret), sub)
150+
}
151+
138152
func null2Str(s string, value string) string {
139153
if s != "" {
140154
return s

common/util.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ type Config struct {
2828
GPACPath string
2929
video string
3030
audio string
31+
ItemId string
3132
}
3233

3334
func (c *Config) overlay() string {
@@ -41,6 +42,7 @@ func (c *Config) Composition(videoFile, audioFile, outputFile string) error {
4142
if c.GPACPath != "" {
4243
cmd = exec.Command(c.GPACPath,
4344
//"-quiet", // 仅打印异常日志
45+
"-cprt", c.ItemId,
4446
"-add", videoFile,
4547
"-add", audioFile,
4648
"-new", outputFile)

common/version.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ package common
22

33
var (
44
version = "1.5.1"
5-
sourceVer = "1413d94 @2024-11-25 18:02:58 +0800"
6-
buildTime = "2024-11-25 18:03:28 by go1.23.1 linux/amd64"
5+
sourceVer = "b06d0d8 @2024-11-25 18:12:09 +0800"
6+
buildTime = "2024-11-26 07:33:37 by go1.23.1 linux/amd64"
77
)

0 commit comments

Comments
 (0)