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.

main.go 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // yt-mango: YT video metadata archiving utility
  2. // Copyright (C) 2018 terorie
  3. package main
  4. import (
  5. "github.com/spf13/cobra"
  6. "fmt"
  7. "os"
  8. "github.com/terorie/yt-mango/cmd"
  9. "log"
  10. "github.com/terorie/yt-mango/api"
  11. "github.com/terorie/yt-mango/net"
  12. )
  13. const Version = "v0.1 -- dev"
  14. func main() {
  15. // All diagnostics (logging) should go to stderr
  16. log.SetOutput(os.Stderr)
  17. var printVersion bool
  18. var forceAPI string
  19. var concurrentRequests uint
  20. rootCmd := cobra.Command{
  21. Use: "yt-mango",
  22. Short: "YT-Mango is a scalable video metadata archiver",
  23. Long: "YT-Mango is a scalable video metadata archiving utility\n" +
  24. "written by terorie for https://the-eye.eu/",
  25. PreRun: func(cmd *cobra.Command, args []string) {
  26. if printVersion {
  27. fmt.Println(Version)
  28. os.Exit(0)
  29. }
  30. },
  31. PersistentPreRun: func(cmd *cobra.Command, args []string) {
  32. net.MaxWorkers = uint32(concurrentRequests)
  33. switch forceAPI {
  34. case "": api.Main = &api.TempAPI
  35. case "classic": api.Main = &api.ClassicAPI
  36. case "json": api.Main = &api.JsonAPI
  37. default:
  38. fmt.Fprintln(os.Stderr, "Invalid API specified.\n" +
  39. "Valid options are: \"classic\" and \"json\"")
  40. os.Exit(1)
  41. }
  42. },
  43. }
  44. rootCmd.Flags().BoolVar(&printVersion, "version", false,
  45. fmt.Sprintf("Print the version (" + Version +") and exit"))
  46. rootCmd.Flags().StringVarP(&forceAPI, "api", "a", "",
  47. "Use the specified API for all calls.\n" +
  48. "Possible options: \"classic\" and \"json\"")
  49. rootCmd.PersistentFlags().UintVarP(&concurrentRequests, "concurrency", "c", 4,
  50. "Number of maximum concurrent HTTP requests")
  51. rootCmd.AddCommand(&cmd.Channel)
  52. rootCmd.AddCommand(&cmd.Video)
  53. if err := rootCmd.Execute(); err != nil {
  54. fmt.Fprintln(os.Stderr, err)
  55. os.Exit(1)
  56. }
  57. }