You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

channeldetail.go 810B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package cmd
  2. import (
  3. "github.com/spf13/cobra"
  4. "github.com/terorie/yt-mango/api"
  5. "os"
  6. "log"
  7. "github.com/terorie/yt-mango/net"
  8. "github.com/terorie/yt-mango/data"
  9. "fmt"
  10. "encoding/json"
  11. )
  12. var channelDetailCmd = cobra.Command{
  13. Use: "detail <channel ID>",
  14. Short: "Get detail about a channel",
  15. Args: cobra.ExactArgs(1),
  16. Run: doChannelDetail,
  17. }
  18. func doChannelDetail(_ *cobra.Command, args []string) {
  19. channelID := args[0]
  20. channelID = api.GetChannelID(channelID)
  21. if channelID == "" {
  22. os.Exit(1)
  23. }
  24. channelReq := api.Main.GrabChannel(channelID)
  25. res, err := net.Client.Do(channelReq)
  26. if err != nil {
  27. log.Fatal(err)
  28. os.Exit(1)
  29. }
  30. var c data.Channel
  31. api.Main.ParseChannel(&c, res)
  32. bytes, err := json.MarshalIndent(&c, "", "\t")
  33. if err != nil { panic(err) }
  34. fmt.Println(string(bytes))
  35. }