Skip to content

Commit

Permalink
release ignore window 32
Browse files Browse the repository at this point in the history
  • Loading branch information
gsxhnd committed Apr 29, 2024
1 parent cd0af36 commit b1f2270
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 41 deletions.
9 changes: 8 additions & 1 deletion .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ before:

builds:
- id: cli
main: ./src
main: ./garage_cmd
env:
- CGO_ENABLED=0
flags:
Expand All @@ -37,6 +37,13 @@ builds:
goarm:
- "6"
- "7"
ignore:
- goos: windows
goarm: "6"
- goos: windows
goarm: "7"
- goos: windows
goarch: "386"

archives:
- format: tar.gz
Expand Down
54 changes: 26 additions & 28 deletions garage_cmd/ffmpeg.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"fmt"
"os"

"github.com/gsxhnd/garage/garage_ffmpeg"
Expand Down Expand Up @@ -107,9 +106,11 @@ var ffmpegBatchConvertCmd = &cli.Command{

if !opt.Exec {
for _, cmd := range cmds {
var cmdStr = "ffmpeg "
for _, c := range cmd {
logger.Infof("Cmd batch not execute,cmd: " + c)
cmdStr += c + " "
}
logger.Infof("Cmd batch not execute,cmd: " + cmdStr)
}
return nil
}
Expand All @@ -131,10 +132,6 @@ var ffmpegBatchAddSubCmd = &cli.Command{
advance,
inputFontsPath,
exec,
&cli.StringFlag{
Name: "input_fonts_path",
Usage: "添加的字体文件夹",
},
&cli.StringFlag{
Name: "input_sub_suffix",
Value: ".ass",
Expand All @@ -158,13 +155,16 @@ var ffmpegBatchAddSubCmd = &cli.Command{
},
Action: func(ctx *cli.Context) error {
var opt = garage_ffmpeg.VideoBatchOption{
InputPath: ctx.String("input_path"),
InputFormat: ctx.String("input_format"),
OutputPath: ctx.String("output_path"),
OutputFormat: ctx.String("output_format"),
Advance: ctx.String("advance"),
Exec: ctx.Bool("exec"),
FontsPath: ctx.String("input_fonts_path"),
InputPath: ctx.String("input_path"),
InputFormat: ctx.String("input_format"),
OutputPath: ctx.String("output_path"),
OutputFormat: ctx.String("output_format"),
InputSubSuffix: ctx.String("input_sub_suffix"),
InputSubNo: ctx.Int("input_sub_no"),
InputSubTitle: ctx.String("input_sub_title"),
InputSubLang: ctx.String("input_sub_lang"),
FontsPath: ctx.String("input_fonts_path"),
Exec: ctx.Bool("exec"),
}

vb, err := garage_ffmpeg.NewVideoBatch(&opt)
Expand All @@ -173,28 +173,23 @@ var ffmpegBatchAddSubCmd = &cli.Command{
return err
}

// vb.logger.Debug("Get matching video count: " + strconv.Itoa(len(vb.videosList)))
// vb.logger.Debug("Target video's subtitle stream number: " + strconv.Itoa(vb.option.InputSubNo))
// vb.logger.Debug("Target video's subtitle language: " + vb.option.InputSubLang)
// vb.logger.Debug("Target video's subtitle title: " + vb.option.InputSubTitle)
// vb.logger.Info("Target video's font paths not set, skip.")
logger.Infof("Target video's font paths: " + opt.FontsPath)

cmds, err := vb.GetAddSubtittleBatch()
if err != nil {
return err
}

if !opt.Exec {
for _, cmd := range cmds {
fmt.Println(cmd)
// logger.Infof(cmd)
var cmdStr = "ffmpeg "
for _, c := range cmd {
cmdStr += c + " "
}
logger.Infof("Cmd batch not execute,cmd: " + cmdStr)
}
return nil
}
return nil

// return vb.ExecuteBatch(os.Stdout, os.Stderr, cmds)
return vb.ExecuteBatch(os.Stdout, os.Stderr, cmds)
},
}

Expand Down Expand Up @@ -228,20 +223,23 @@ var ffmpegBatchAddFontCmd = &cli.Command{
logger.Panicf("Create dest path error", zap.Error(err))
return err
}

cmds, err := vb.GetAddFontsBatch()
if err != nil {
return err
}

if !opt.Exec {
for _, cmd := range cmds {
// logger.Infow(cmd)
fmt.Println(cmd)
var cmdStr = "ffmpeg "
for _, c := range cmd {
cmdStr += c + " "
}
logger.Infof("Cmd batch not execute,cmd: " + cmdStr)
}
return nil
}
return nil

// return vb.ExecuteBatch(os.Stdout, os.Stderr, cmds)
return vb.ExecuteBatch(os.Stdout, os.Stderr, cmds)
},
}
2 changes: 1 addition & 1 deletion garage_cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var (

var versionCmd = &cli.Command{
Name: "version",
Usage: "显示版本号",
Usage: "show version information",
Action: func(context *cli.Context) error {
fmt.Println("Version: ", tag)
fmt.Println("BuildDate:", buildDate)
Expand Down
12 changes: 9 additions & 3 deletions garage_ffmpeg/ffmpeg.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ type VideoBatcher interface {
GetAddFontsBatch() ([][]string, error) // 获取添加字体命令
GetAddSubtittleBatch() ([][]string, error) // 获取添加字幕命令
ExecuteBatch(wOut, wError io.Writer, batchCmd [][]string) error
// GetExecBatch() rxgo.Observable
}

type videoBatch struct {
Expand Down Expand Up @@ -112,6 +111,10 @@ func (vb *videoBatch) GetFontsList() ([]string, error) {
}

func (vb *videoBatch) GetFontsParams() ([]string, error) {
if vb.option.FontsPath == "" {
return nil, nil
}

var fontsCmdList = []string{}
fontsList, err := vb.GetFontsList()
if err != nil {
Expand Down Expand Up @@ -192,7 +195,8 @@ func (vb *videoBatch) GetAddSubtittleBatch() ([][]string, error) {
for _, v := range videosList {
var cmd = []string{}
// TODO: sub title error
sourceSubtitle := filepath.Join(vb.option.InputPath, v+vb.option.InputSubSuffix)
filename, _ := strings.CutSuffix(filepath.Base(v), filepath.Ext(v))
sourceSubtitle := filepath.Join(vb.option.InputPath, filename+"."+vb.option.InputSubSuffix)
cmd = append(cmd, "-i", fmt.Sprintf(`"%v"`, v))
cmd = append(cmd, "-sub_charenc", "UTF-8")
cmd = append(cmd, "-i", fmt.Sprintf(`"%v"`, sourceSubtitle), "-map", "0", "-map", "1")
Expand All @@ -201,7 +205,9 @@ func (vb *videoBatch) GetAddSubtittleBatch() ([][]string, error) {
cmd = append(cmd, fmt.Sprintf("-metadata:s:s:%v", vb.option.InputSubNo))
cmd = append(cmd, fmt.Sprintf(`title="%v"`, vb.option.InputSubTitle))
cmd = append(cmd, "-c", "copy")
cmd = append(cmd, fontsParams...)
if fontsParams != nil {
cmd = append(cmd, fontsParams...)
}
cmd = append(cmd, fmt.Sprintf(`"%v"`, outputVideosMap[v]))
vb.cmdBatchs = append(vb.cmdBatchs, cmd)
}
Expand Down
63 changes: 56 additions & 7 deletions garage_server/handler/ffmpeg_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,32 @@ func NewFFmpegHandler(l utils.Logger, v *validator.Validate, t task.TaskMgr, svc
}

type model struct {
InputPath string `json:"inputPath" validate:"required"`
InputFormat string `json:"inputFormat" validate:"required"`
OutputPath string `json:"outputPath" validate:"required"`
InputPath string `json:"inputPath" validate:"required"`
InputFormat string `json:"inputFormat" validate:"required"`
OutputPath string `json:"outputPath" validate:"required"`
Exec bool `json:"exec"`
}

type convertModel struct {
model
OutputFormat string `json:"outputFormat" validate:"required"`
Advance string `json:"advance"`
Exec bool `json:"exec"`
}

type addFontsModel struct {
model
FontsPath string `json:"fontsPath" validate:"required"`
}

type addSubtitleModel struct {
model
FontsPath string `json:"fontsPath"`
InputSubSuffix string `json:"inputSubSuffix" validate:"required"`
InputSubNo int `json:"inputSubNo"`
InputSubTitle string `json:"inputSubTitle" validate:"required"`
InputSubLang string `json:"inputSublang" validate:"required"`
}

func (h *ffmpegHander) Convert(ctx *fiber.Ctx) error {
body := new(model)

Expand Down Expand Up @@ -98,9 +111,8 @@ func (h *ffmpegHander) AddFonts(ctx *fiber.Ctx) error {
InputPath: body.InputPath,
InputFormat: body.InputFormat,
OutputPath: body.OutputPath,
OutputFormat: body.OutputFormat,
OutputFormat: body.InputFormat,
FontsPath: body.FontsPath,
Advance: body.Advance,
Exec: body.Exec,
}, "add_fonts")
if err != nil {
Expand All @@ -120,5 +132,42 @@ func (h *ffmpegHander) AddFonts(ctx *fiber.Ctx) error {
}

func (h *ffmpegHander) AddSubtitle(ctx *fiber.Ctx) error {
return nil
body := new(addSubtitleModel)

if err := ctx.BodyParser(body); err != nil {
h.logger.Errorf("boyd parser error: %s", err.Error())
return nil
}

if err := h.validator.Struct(body); err != nil {
h.logger.Errorf("body validation error: %s", err.Error())
return nil
}

task, err := task.NewFFmpegTask(&garage_ffmpeg.VideoBatchOption{
InputPath: body.InputPath,
InputFormat: body.InputFormat,
OutputPath: body.OutputPath,
OutputFormat: body.InputFormat,
FontsPath: body.FontsPath,
InputSubSuffix: body.InputSubSuffix,
InputSubNo: body.InputSubNo,
InputSubTitle: body.InputSubTitle,
InputSubLang: body.InputSubLang,
Exec: body.Exec,
}, "add_subtitle")
if err != nil {
h.logger.Errorf("init task error: %s", err.Error())
return nil
}

h.taskManager.AddTask(task)
h.logger.Debugf("Task id: %s", task.GetId())

var data = map[string]interface{}{
"id": task.GetId(),
"cmds": task.GetCmds(),
}

return ctx.JSON(data)
}
2 changes: 1 addition & 1 deletion garage_server/routes/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ func (r *router) ApiInit() {
ffmpegGroup := api.Group("/ffmpeg")
ffmpegGroup.Post("/convert", r.h.FFmpegHander.Convert)
ffmpegGroup.Post("/add_fonts", r.h.FFmpegHander.AddFonts)
ffmpegGroup.Post("/add_subtitle", r.h.FFmpegHander.Convert)
ffmpegGroup.Post("/add_subtitle", r.h.FFmpegHander.AddSubtitle)

javGroup := api.Group("/jav")
javGroup.Post("/code", r.h.JavHandler.CrawlJavByCode)
Expand Down
7 changes: 7 additions & 0 deletions garage_server/task/task_ffmpeg.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ func NewFFmpegTask(opt *garage_ffmpeg.VideoBatchOption, cmd string) (Task, error
return nil, err
}
task.cmds = cmds

case "add_subtitle":
cmds, err := batcher.GetAddSubtittleBatch()
if err != nil {
return nil, err
}
task.cmds = cmds
default:
}

Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26 h1:Xim43kblpZXfIBQsbuBVKCudVG457BR2GZFIz3uw3hQ=
github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26/go.mod h1:dDKJzRmX4S37WGHujM7tX//fmj1uioxKzKxz3lo4HJo=
github.com/google/subcommands v1.2.0 h1:vWQspBTo2nEqTUFita5/KeEWlUL8kQObDFbub/EN9oE=
github.com/google/subcommands v1.2.0/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
Expand Down Expand Up @@ -218,6 +219,7 @@ golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0=
golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand Down Expand Up @@ -309,6 +311,7 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58=
golang.org/x/tools v0.17.0 h1:FvmRgNOcs3kOa+T20R1uhfP9F6HgG2mfxDv1vrx1Htc=
golang.org/x/tools v0.17.0/go.mod h1:xsh6VxdV005rRVaS6SSAf9oiAqljS7UZUacMZ8Bnsps=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down

0 comments on commit b1f2270

Please sign in to comment.