Support yt-dlp shows

This commit is contained in:
Dan Jones 2025-07-02 14:15:32 -05:00
commit dc9e6f59db
2 changed files with 45 additions and 7 deletions

View file

@ -1,6 +1,7 @@
package convids package convids
import ( import (
"bufio"
"cmp" "cmp"
"context" "context"
"errors" "errors"
@ -165,16 +166,51 @@ func GetShow(ctx context.Context) ShowWalker {
func GetShowWithIO(ctx context.Context, stdin io.Reader, stdout, stderr io.Writer) ShowWalker { func GetShowWithIO(ctx context.Context, stdin io.Reader, stdout, stderr io.Writer) ShowWalker {
return func(s *Show, path string) error { return func(s *Show, path string) error {
if !s.Url {
return runGetShowsCmd(ctx, s.Folder, path, stdin, stdout, stderr)
}
orig := path
//nolint:gosec // I don't care if this is user input
readFile, err := os.Open(orig)
if err != nil {
return err
}
//nolint:errcheck // I don't care
defer readFile.Close()
fileScan := bufio.NewScanner(readFile)
fileScan.Split(bufio.ScanLines)
for fileScan.Scan() {
path = fileScan.Text()
err := runGetShowsCmd(ctx, s.Folder, path, stdin, stdout, stderr)
if err != nil {
return err
}
}
if s.Backup != "" {
err = os.Rename(orig, fp.Join(s.Backup, fp.Base(orig)))
if err != nil {
_, _ = fmt.Fprintf(stdout, "Moved %s to %s\n", orig, s.Backup)
}
} else {
err = os.Remove(orig)
}
return err
}
}
func runGetShowsCmd(ctx context.Context, folder, path string, stdin io.Reader, stdout, stderr io.Writer) error {
//nolint:gosec // I don't care if this is using user input //nolint:gosec // I don't care if this is using user input
cmd := exec.CommandContext(ctx, "get-shows", s.Folder, path) cmd := exec.CommandContext(ctx, "get-shows", folder, path)
cmd.Stdin = stdin cmd.Stdin = stdin
cmd.Stdout = stdout cmd.Stdout = stdout
cmd.Stderr = stderr cmd.Stderr = stderr
return cmd.Run() return cmd.Run()
} }
}
func PrintGroupName(out io.Writer) GroupPrinter { func PrintGroupName(out io.Writer) GroupPrinter {
return func(name string, group Shows) { return func(name string, group Shows) {
_, _ = fmt.Fprintf(out, "Checking %s shows\n\n", name) _, _ = fmt.Fprintf(out, "Checking %s shows\n\n", name)

View file

@ -25,6 +25,8 @@ type Show struct {
Pattern string Pattern string
Name string Name string
Anime bool Anime bool
Url bool
Backup string
Sources []string Sources []string
re *regexp.Regexp re *regexp.Regexp