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.

videodetail.go 776B

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