unarr/internal/cmd/watch.go
Deivid Soto 719429b06e docs: improve CLI help, shell completion, and README
- Add command groups (Getting Started, Search, Downloads, Daemon, System)
- Add shell completion command (bash, zsh, fish, powershell)
- Add flag completions for --type, --quality, --sort, --lang, --genre,
  --country, --method, --player
- Improve Long descriptions and Examples for all commands
- Split doctor disk check into platform-specific files (Unix/Windows)
- Validate infoHash length before truncating (prevent panic)
- Fix references to non-existent 'unarr daemon start' command
- Move stats command to System & Diagnostics group
- Rewrite README with complete documentation, correct config format
  (toml not yaml), all commands, shell completion section
2026-03-28 21:36:27 +01:00

81 lines
2 KiB
Go

package cmd
import (
"context"
"encoding/json"
"fmt"
"os"
"strings"
"github.com/spf13/cobra"
tc "github.com/torrentclaw/go-client"
"github.com/torrentclaw/torrentclaw-cli/internal/ui"
)
func newWatchCmd() *cobra.Command {
var country string
cmd := &cobra.Command{
Use: "watch <query>",
Short: "Find where to watch — streaming + torrents",
Long: `Search for content and show streaming availability alongside torrent options.
Shows legal streaming options first (subscription, free, rent, buy),
then torrent alternatives below. Helps you decide the best way to watch.`,
Example: ` unarr watch "oppenheimer"
unarr watch "breaking bad" --country ES
unarr watch "inception" --json`,
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
client := getClient()
ctx := context.Background()
if country == "" {
country = loadConfig().General.Country
}
// Search for the content with country for streaming info
resp, err := client.Search(ctx, tc.SearchParams{
Query: strings.Join(args, " "),
Limit: 1,
Country: country,
})
if err != nil {
return fmt.Errorf("search failed: %w", err)
}
if len(resp.Results) == 0 {
fmt.Println("No results found.")
return nil
}
result := resp.Results[0]
// Fetch watch providers
providers, err := client.WatchProviders(ctx, result.ID, country)
if err != nil {
// Non-fatal: we can still show torrent results
providers = nil
}
if jsonOut {
enc := json.NewEncoder(os.Stdout)
enc.SetIndent("", " ")
return enc.Encode(map[string]any{
"content": result,
"providers": providers,
})
}
year := ui.FormatYear(result.Year)
ui.PrintWatchProviders(result.Title, year, providers, result.Torrents)
return nil
},
}
cmd.Flags().StringVar(&country, "country", "", "country code for streaming availability (e.g. US, ES)")
cmd.RegisterFlagCompletionFunc("country", completionCountryCodes)
return cmd
}