subsync

package
v0.0.0-...-1bad096 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 13, 2020 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cmd = &cobra.Command{
	Use:   "subsync",
	Short: "Synchronize subtitle using SubSync tool",
	Args:  cobra.MinimumNArgs(1),
	PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
		_, err := exec.LookPath(subsyncCommand)
		if err != nil {
			return fmt.Errorf("command not found: subsync")
		}

		media.WD, _ = filepath.Abs(args[0])
		stats, err := os.Stat(media.WD)
		if err != nil || !stats.IsDir() {
			return fmt.Errorf("%s is not a valid directory", media.WD)
		}
		return nil
	},
	RunE: func(cmd *cobra.Command, args []string) error {
		subtitleExtensions, _ := cmd.Flags().GetStringArray("sub-ext")
		subtitleLang, _ := cmd.Flags().GetString("sub-lang")
		videoExtensions, _ := cmd.Flags().GetStringArray("video-ext")
		videoLang, _ := cmd.Flags().GetString("video-lang")
		subtitleFiles := media.List(media.WD, subtitleExtensions, nil)
		sort.Strings(subtitleFiles)
		videoFiles := media.List(media.WD, videoExtensions, nil)
		sort.Strings(videoFiles)
		if len(subtitleFiles) == 0 {
			console.Success("No subtitle file to process")
		} else if len(videoFiles) == 0 {
			console.Success("No video file to process")
		} else {
			printAll(videoFiles, subtitleFiles)
			prompt := promptui.Prompt{
				Label:     "Process",
				IsConfirm: true,
				Default:   "y",
			}
			_, err := prompt.Run()
			if err != nil {
				if err.Error() == "^C" {
					return nil
				}
			} else {
				for index, videoFile := range videoFiles {
					videoFileExtension := path.Ext(videoFile)
					outFile := strings.Replace(videoFile, videoFileExtension, fmt.Sprintf(".%s.srt", subtitleLang), 1)
					subtitleFile := subtitleFiles[index]
					videoFilePath := path.Join(media.WD, videoFile)
					subtitleFilePath := path.Join(media.WD, subtitleFile)
					outFilePath := path.Join(media.WD, outFile)
					err := process(videoFilePath, videoLang, subtitleFilePath, subtitleLang, outFilePath)
					if err != nil {
						return err
					}
				}
			}
		}
		return nil
	},
}

Cmd formats given media type according to personal conventions

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL