func DownloadPodcast(c *cli.Context) error { if len(c.Args()) < 1 { return fmt.Errorf("Please specify a podcast to download") } podcast := findPodcast(c.Args().First()) number := 1 if len(c.Args()) > 1 { var err error number, err = strconv.Atoi(c.Args()[1]) if number > len(feedparser.ListEpisodes(*podcast)) { return fmt.Errorf("There's not that many episodes") } if err != nil { fmt.Printf("Cannot find podcast %s", c.Args()[1]) return err } } feedparser.Download(*podcast, number) return nil }
func printPodcastInfo(podcast configuration.Podcast) { fmt.Printf("ID: %d\n", podcast.ID) fmt.Printf("Name: %s\n", podcast.Name) fmt.Printf("Feed: %s\n", podcast.Feed) fmt.Printf("Path: %s\n", podcast.Path) fmt.Printf("Episodes: \n") table := tablewriter.NewWriter(os.Stdout) table.SetHeader([]string{"ID", "Name", "Size", "Published Date", "Downloaded"}) table.SetBorder(false) items := feedparser.ListEpisodes(podcast) for id, item := range items { var length uint64 = uint64(item.Enclosure.Length) var downloaded string if item.Downloaded { downloaded = "true" } else { downloaded = "false" } table.Append([]string{fmt.Sprintf("%d", id+1), item.Title.Title, humanize.Bytes(length), item.Date.Date, downloaded}) } table.Render() }