Skip to content

Add redo logic for re-encoding titles from run history - #12

Open
timharek wants to merge 1 commit into
dmars8047:releasefrom
timharek:upstream
Open

timharek wants to merge 1 commit into
dmars8047:releasefrom
timharek:upstream

Conversation

@timharek

@timharek timharek commented Apr 1, 2026

Copy link
Copy Markdown
  • Extract per-title encoding from Exec into reusable encodeTitle() function (encode.go)
  • Add Redo() function that re-encodes titles from a previous run using the current config's encoding settings (redo.go)
  • Extract listManifestFiles() from PrintHistory for reuse across history and redo flows

Details

Redo reads a manifest from run history, verifies the original ripped MKV files still exist on disk, then re-encodes selected titles with the current config. If raw files were deleted, it exits with a message suggesting the user re-rip. Output goes to a new timestamped directory. Results are recorded in a new manifest entry.

The command is not included, but here is my version:

Code from https://git.sr.ht/~timharek/handymkv/tree/main/item/cmd/handymkv/redo.go
package main

import (
	"fmt"
	"strconv"

	"github.com/dmars8047/handymkv/internal/hmkv"
	"github.com/spf13/cobra"
)

func init() {
	rootCmd.AddCommand(redoCmd())
}

func redoCmd() *cobra.Command {
	var titles []int
	var all bool

	cmd := &cobra.Command{
		Use:   "redo [run-number]",
		Short: "Re-encode titles from a previous run using current config settings",
		Args:  cobra.RangeArgs(0, 1),
		RunE: func(cmd *cobra.Command, args []string) error {
			runIndex := -1
			if len(args) > 0 {
				var err error
				runIndex, err = strconv.Atoi(args[0])
				if err != nil {
					return fmt.Errorf("invalid run number: %s", args[0])
				}
			}
			return hmkv.Redo(hb, runIndex, titles, all, getVersion())
		},
		PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
			cfg, cfgErr := hmkv.ReadConfig()
			if cfgErr == hmkv.ErrConfigNotFound {
				return fmt.Errorf("no configuration found, run `handymkv config setup`")
			}
			if cfgErr != nil {
				return fmt.Errorf("error reading config: %w", cfgErr)
			}
			if cfg.DisableManifests {
				return fmt.Errorf("redo requires run history (manifests) to be enabled")
			}
			return nil
		},
	}

	cmd.Flags().IntSliceVarP(&titles, "titles", "t", nil, "Title indices to re-encode (e.g., -t 0,2,5)")
	cmd.Flags().BoolVar(&all, "all", false, "Re-encode all titles from the selected run")

	return cmd
}

Extract encoding logic from Exec into reusable encodeTitle function.
@dmars8047

dmars8047 commented Apr 2, 2026

Copy link
Copy Markdown
Owner

I am still looking at this but so far it looks okay.

I am still thinking through the side effects. Is the idea that this is just a way to repeat encoding against files ripped on a previous run? What about automations? Are you envisioning those to run again?

@timharek

timharek commented Apr 3, 2026

Copy link
Copy Markdown
Author

Is the idea that this is just a way to repeat encoding against files ripped on a previous run?

Yes. The use case is that you discovered that your config was bad, and you changed it, and then deceide to do a redo of the same rip.

What about automations? Are you envisioning those to run again?

Yes, those could run again. But feels out of scope for the main feature, because it could be configurable with a flag for the redo command itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants