Exemplo n.º 1
0
func Test(t *testing.T) {
	cfg, err := areena.NewConfig()
	if err != nil {
		t.Fatal(err)
	}

	apiClient, err := areena.NewClient(cfg)
	if err != nil {
		t.Fatal(err)
	}

	pd, err := apiClient.ProgramDetails("1-2371565")
	if err != nil {
		t.Fatal(err)
	}

	dl := download.NewDownloader()
	err = dl.DownloadVideo(pd.HLSURL, fmt.Sprintf("%s.mp4", pd.Slug))
	if err != nil {
		t.Fatal(err)
	}

	err = dl.DownloadToFile(pd.SubtitleURL, fmt.Sprintf("%s.srt", pd.Slug))
	if err != nil {
		t.Fatal(err)
	}
}
Exemplo n.º 2
0
// Run the command
func (c *DownloadCommand) Run(args []string) int {
	flags := c.Meta.FlagSet("download")
	flags.Usage = func() { c.Meta.UI.Output(c.Help()) }
	if err := flags.Parse(args); err != nil {
		return 1
	}
	parsedArgs := flags.Args()
	if len(parsedArgs) != 1 {
		msg := fmt.Sprintf("Invalid arguments: usage download PROGRAM_ID")
		c.UI.Error(msg)
		return 1
	}
	programIDs := strings.Split(parsedArgs[0], ",")
	log.Printf("Downloading %v...", programIDs)

	cfg, err := areena.NewConfig()
	if err != nil {
		c.UI.Error(err.Error())
		return 1
	}

	apiClient, err := areena.NewClient(cfg)
	if err != nil {
		c.UI.Error(err.Error())
		return 1
	}

	dl := download.NewDownloader()

	for _, programID := range programIDs {
		programID = strings.TrimSpace(programID)
		log.Printf("Downloading video for program %s", programID)
		pd, err := apiClient.ProgramDetails(programID)
		if err != nil {
			c.UI.Error(err.Error())
			return 1
		}
		err = dl.DownloadVideo(pd.HLSURL, fmt.Sprintf("%s.mp4", pd.Slug))
		if err != nil {
			c.UI.Error(err.Error())
			return 1
		}

		if pd.SubtitleURL != "" {
			err = dl.DownloadToFile(pd.SubtitleURL, fmt.Sprintf("%s.srt", pd.Slug))
			if err != nil {
				c.UI.Error(err.Error())
				return 1
			}
		}
	}

	return 0
}