|
|
@ -56,14 +56,14 @@ func AddPodcast(url string) (db.Podcast, error) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func AddPodcastItems(podcast *db.Podcast) error {
|
|
|
|
func AddPodcastItems(podcast *db.Podcast) error {
|
|
|
|
fmt.Println("Creating: " + podcast.ID)
|
|
|
|
//fmt.Println("Creating: " + podcast.ID)
|
|
|
|
data, err := FetchURL(podcast.URL)
|
|
|
|
data, err := FetchURL(podcast.URL)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
//log.Fatal(err)
|
|
|
|
//log.Fatal(err)
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//p := bluemonday.StrictPolicy()
|
|
|
|
setting := db.GetOrCreateSetting()
|
|
|
|
limit := 5
|
|
|
|
limit := setting.InitialDownloadCount
|
|
|
|
if len(data.Channel.Item) < limit {
|
|
|
|
if len(data.Channel.Item) < limit {
|
|
|
|
limit = len(data.Channel.Item)
|
|
|
|
limit = len(data.Channel.Item)
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -91,20 +91,22 @@ func AddPodcastItems(podcast *db.Podcast) error {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func SetPodcastItemAsDownloaded(id string, location string) {
|
|
|
|
func SetPodcastItemAsDownloaded(id string, location string) error {
|
|
|
|
var podcastItem db.PodcastItem
|
|
|
|
var podcastItem db.PodcastItem
|
|
|
|
db.GetPodcastItemById(id, &podcastItem)
|
|
|
|
err := db.GetPodcastItemById(id, &podcastItem)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
podcastItem.DownloadDate = time.Now()
|
|
|
|
podcastItem.DownloadDate = time.Now()
|
|
|
|
podcastItem.DownloadPath = location
|
|
|
|
podcastItem.DownloadPath = location
|
|
|
|
|
|
|
|
|
|
|
|
db.UpdatePodcastItem(&podcastItem)
|
|
|
|
return db.UpdatePodcastItem(&podcastItem)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func DownloadMissingEpisodes() error {
|
|
|
|
func DownloadMissingEpisodes() error {
|
|
|
|
data, err := db.GetAllPodcastItemsToBeDownloaded()
|
|
|
|
data, err := db.GetAllPodcastItemsToBeDownloaded()
|
|
|
|
|
|
|
|
|
|
|
|
fmt.Println("Processing episodes: ", strconv.Itoa(len(*data)))
|
|
|
|
//fmt.Println("Processing episodes: ", strconv.Itoa(len(*data)))
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -115,6 +117,21 @@ func DownloadMissingEpisodes() error {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func DownloadSingleEpisode(podcastItemId string) error {
|
|
|
|
|
|
|
|
var podcastItem db.PodcastItem
|
|
|
|
|
|
|
|
err := db.GetPodcastItemById(podcastItemId, &podcastItem)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//fmt.Println("Processing episodes: ", strconv.Itoa(len(*data)))
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
url, err := Download(podcastItem.FileURL, podcastItem.Title, podcastItem.Podcast.Title)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return SetPodcastItemAsDownloaded(podcastItem.ID, url)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func RefreshEpisodes() error {
|
|
|
|
func RefreshEpisodes() error {
|
|
|
|
var data []db.Podcast
|
|
|
|
var data []db.Podcast
|
|
|
@ -127,7 +144,10 @@ func RefreshEpisodes() error {
|
|
|
|
AddPodcastItems(&item)
|
|
|
|
AddPodcastItems(&item)
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
go DownloadMissingEpisodes()
|
|
|
|
setting := db.GetOrCreateSetting()
|
|
|
|
|
|
|
|
if setting.AutoDownload {
|
|
|
|
|
|
|
|
go DownloadMissingEpisodes()
|
|
|
|
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|