1
0

main.go 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package main
  2. import (
  3. "log"
  4. "os"
  5. "strings"
  6. "time"
  7. "github.com/ChineseSubFinder/ChineseSubFinder/pkg"
  8. "github.com/ChineseSubFinder/ChineseSubFinder/pkg/logic/sub_timeline_fixer"
  9. "github.com/ChineseSubFinder/ChineseSubFinder/pkg/log_helper"
  10. "github.com/ChineseSubFinder/ChineseSubFinder/pkg/settings"
  11. "github.com/sirupsen/logrus"
  12. "github.com/urfave/cli/v2"
  13. )
  14. /*
  15. 字幕时间轴修复命令行
  16. 使用方法:
  17. go run main.go -vp ${videoPath} -sp ${subtitlePath}
  18. ${videPath} -> 视频文件路径,需要指定对应的视频文件
  19. ${subtitlePath} -> 字幕文件路径,需要指定对应的字幕文件
  20. 逻辑:
  21. 1. 执行 SubTimelineFixerHelperEx 检查 - 确认已经安装了ffmpeg 和 ffprobe
  22. 2. 执行 SubTimelineFixerHelperEx 的 process操作
  23. 编译:
  24. 通过`go build -o fixer`编译出可直接执行的文件。
  25. */
  26. var loggerBase *logrus.Logger
  27. func newLog() *logrus.Logger {
  28. logger := log_helper.NewLogHelper(log_helper.LogNameCliSubTimelineFixer,
  29. pkg.ConfigRootDirFPath(),
  30. logrus.InfoLevel, time.Duration(7*24)*time.Hour, time.Duration(24)*time.Hour)
  31. return logger
  32. }
  33. func main() {
  34. var videoPath string
  35. var subtitlesPath string
  36. loggerBase = newLog()
  37. app := &cli.App{
  38. Name: "Subtitle Timeline Fixer",
  39. Usage: "Fix the subtitle timeline according to the video",
  40. Flags: []cli.Flag{
  41. &cli.StringFlag{
  42. Name: "videoPath",
  43. Aliases: []string{"vp"},
  44. Usage: "Specify `video file path`",
  45. Destination: &videoPath,
  46. Required: true,
  47. },
  48. &cli.StringFlag{
  49. Name: "subtitlesPath",
  50. Aliases: []string{"sp"},
  51. Usage: "Specify `subtitles file path`",
  52. Destination: &subtitlesPath,
  53. Required: true,
  54. },
  55. },
  56. Action: func(c *cli.Context) error {
  57. videoPath = strings.TrimSpace(videoPath)
  58. subtitlesPath = strings.TrimSpace(subtitlesPath)
  59. if videoPath != "" && subtitlesPath != "" {
  60. var fixerSetting = settings.NewTimelineFixerSettings()
  61. var subTimelineFixerHelper = sub_timeline_fixer.NewSubTimelineFixerHelperEx(loggerBase, *fixerSetting)
  62. if subTimelineFixerHelper.Check() {
  63. subTimelineFixerHelper.Process(videoPath, subtitlesPath)
  64. } else {
  65. println("check subtitles timeline fixer helper failed.")
  66. }
  67. } else {
  68. println("need provide video path (-vp) and subtitle path (-sp)")
  69. }
  70. return nil
  71. },
  72. }
  73. err := app.Run(os.Args)
  74. if err != nil {
  75. log.Fatal(err)
  76. }
  77. }