2026-03-28 11:29:42 +01:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"fmt"
|
|
|
|
|
"os"
|
|
|
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
tc "github.com/torrentclaw/go-client"
|
|
|
|
|
|
2026-03-30 13:06:07 +02:00
|
|
|
"github.com/torrentclaw/unarr/internal/ui"
|
2026-03-28 11:29:42 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func newPopularCmd() *cobra.Command {
|
|
|
|
|
var (
|
|
|
|
|
limit int
|
|
|
|
|
page int
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
cmd := &cobra.Command{
|
|
|
|
|
Use: "popular",
|
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
|
|
|
Short: "Show popular movies and TV shows",
|
|
|
|
|
Long: `Display the most popular movies and TV shows, ranked by community engagement.
|
|
|
|
|
|
|
|
|
|
Results are ordered by trending score. Use --limit to control how many
|
|
|
|
|
results to show and --page for pagination.`,
|
2026-03-28 11:29:42 +01:00
|
|
|
Example: ` unarr popular
|
|
|
|
|
unarr popular --limit 20
|
|
|
|
|
unarr popular --page 2 --json`,
|
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
|
client := getClient()
|
|
|
|
|
|
|
|
|
|
resp, err := client.Popular(context.Background(), tc.PopularParams{Limit: limit, Page: page})
|
|
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("failed to fetch popular content: %w", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if jsonOut {
|
|
|
|
|
enc := json.NewEncoder(os.Stdout)
|
|
|
|
|
enc.SetIndent("", " ")
|
|
|
|
|
return enc.Encode(resp)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ui.PrintPopularItems(resp.Items)
|
|
|
|
|
return nil
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cmd.Flags().IntVar(&limit, "limit", 10, "number of results")
|
|
|
|
|
cmd.Flags().IntVar(&page, "page", 0, "page number")
|
|
|
|
|
|
|
|
|
|
return cmd
|
|
|
|
|
}
|