From e6ca46e5a562c7f6a66f9a16184add1e39a0c734 Mon Sep 17 00:00:00 2001 From: Akhil Gupta Date: Tue, 3 Nov 2020 17:43:45 +0530 Subject: [PATCH] download all episodes on add --- service/podcastService.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/service/podcastService.go b/service/podcastService.go index 6ae921b..fac4d3f 100644 --- a/service/podcastService.go +++ b/service/podcastService.go @@ -65,16 +65,22 @@ func AddPodcastItems(podcast *db.Podcast) error { } setting := db.GetOrCreateSetting() limit := setting.InitialDownloadCount - if len(data.Channel.Item) < limit { - limit = len(data.Channel.Item) - } - for i := 0; i < limit; i++ { + // if len(data.Channel.Item) < limit { + // limit = len(data.Channel.Item) + // } + for i := 0; i < len(data.Channel.Item); i++ { obj := data.Channel.Item[i] var podcastItem db.PodcastItem err := db.GetPodcastItemByPodcastIdAndGUID(podcast.ID, obj.Guid.Text, &podcastItem) if errors.Is(err, gorm.ErrRecordNotFound) { duration, _ := strconv.Atoi(obj.Duration) pubDate, _ := time.Parse(time.RFC1123Z, obj.PubDate) + var downloadStatus db.DownloadStatus + if i < limit { + downloadStatus = db.NotDownloaded + } else { + downloadStatus = db.Deleted + } podcastItem = db.PodcastItem{ PodcastID: podcast.ID, Title: obj.Title, @@ -85,7 +91,7 @@ func AddPodcastItems(podcast *db.Podcast) error { FileURL: obj.Enclosure.URL, GUID: obj.Guid.Text, Image: obj.Image.Href, - DownloadStatus: db.NotDownloaded, + DownloadStatus: downloadStatus, } db.CreatePodcastItem(&podcastItem) }