From 800cfaab7a7e94ae659ce03425d833e46cd9482f Mon Sep 17 00:00:00 2001 From: Akhil Gupta Date: Wed, 21 Jul 2021 14:46:49 +0530 Subject: [PATCH] setting to not redownload deleted content --- client/settings.html | 10 ++++++++-- controllers/pages.go | 1 + controllers/podcast.go | 2 +- db/podcast.go | 1 + service/podcastService.go | 10 ++++++++-- 5 files changed, 19 insertions(+), 5 deletions(-) diff --git a/client/settings.html b/client/settings.html index f6d929f..851190b 100644 --- a/client/settings.html +++ b/client/settings.html @@ -93,6 +93,10 @@ Generate NFO files for Podcasts + @@ -168,7 +172,8 @@ var app = new Vue({ appendEpisodeNumberToFileName:self.appendEpisodeNumberToFileName, darkMode:self.darkMode, downloadEpisodeImages:self.downloadEpisodeImages, - generateNFOFile:self.generateNFOFile + generateNFOFile:self.generateNFOFile, + dontDownloadDeletedFromDisk:self.dontDownloadDeletedFromDisk }) .then(function(response){ Vue.toasted.show('Settings saved successfully.' ,{ @@ -210,7 +215,8 @@ var app = new Vue({ darkMode:{{ .setting.DarkMode }}, originalThemeSetting:{{ .setting.DarkMode }}, downloadEpisodeImages:{{.setting.DownloadEpisodeImages }}, - generateNFOFile:{{.setting.GenerateNFOFile }}, + generateNFOFile:{{ .setting.GenerateNFOFile }}, + dontDownloadDeletedFromDisk:{{ .setting.DontDownloadDeletedFromDisk }}, }, }) diff --git a/controllers/pages.go b/controllers/pages.go index 2d2476d..4bffa41 100644 --- a/controllers/pages.go +++ b/controllers/pages.go @@ -29,6 +29,7 @@ type SettingModel struct { DarkMode bool `form:"darkMode" json:"darkMode" query:"darkMode"` DownloadEpisodeImages bool `form:"downloadEpisodeImages" json:"downloadEpisodeImages" query:"downloadEpisodeImages"` GenerateNFOFile bool `form:"generateNFOFile" json:"generateNFOFile" query:"generateNFOFile"` + DontDownloadDeletedFromDisk bool `form:"dontDownloadDeletedFromDisk" json:"dontDownloadDeletedFromDisk" query:"dontDownloadDeletedFromDisk"` } var searchOptions = map[string]string{ diff --git a/controllers/podcast.go b/controllers/podcast.go index af04c2d..04713d6 100644 --- a/controllers/podcast.go +++ b/controllers/podcast.go @@ -547,7 +547,7 @@ func UpdateSetting(c *gin.Context) { err = service.UpdateSettings(model.DownloadOnAdd, model.InitialDownloadCount, model.AutoDownload, model.AppendDateToFileName, model.AppendEpisodeNumberToFileName, - model.DarkMode, model.DownloadEpisodeImages, model.GenerateNFOFile) + model.DarkMode, model.DownloadEpisodeImages, model.GenerateNFOFile, model.DontDownloadDeletedFromDisk) if err == nil { c.JSON(200, gin.H{"message": "Success"}) diff --git a/db/podcast.go b/db/podcast.go index 854d3f5..fa9abdb 100644 --- a/db/podcast.go +++ b/db/podcast.go @@ -83,6 +83,7 @@ type Setting struct { DarkMode bool `gorm:"default:false"` DownloadEpisodeImages bool `gorm:"default:false"` GenerateNFOFile bool `gorm:"default:false"` + DontDownloadDeletedFromDisk bool `gorm:"default:false"` } type Migration struct { Base diff --git a/service/podcastService.go b/service/podcastService.go index f92870e..0ff9ce2 100644 --- a/service/podcastService.go +++ b/service/podcastService.go @@ -532,6 +532,7 @@ func DownloadMissingEpisodes() error { } func CheckMissingFiles() error { data, err := db.GetAllPodcastItemsAlreadyDownloaded() + setting := db.GetOrCreateSetting() //fmt.Println("Processing episodes: ", strconv.Itoa(len(*data))) if err != nil { @@ -540,7 +541,11 @@ func CheckMissingFiles() error { for _, item := range *data { fileExists := FileExists(item.DownloadPath) if !fileExists { - SetPodcastItemAsNotDownloaded(item.ID, db.NotDownloaded) + if setting.DontDownloadDeletedFromDisk { + SetPodcastItemAsNotDownloaded(item.ID, db.Deleted) + } else { + SetPodcastItemAsNotDownloaded(item.ID, db.NotDownloaded) + } } } return nil @@ -736,7 +741,7 @@ func GetSearchFromPodcastIndex(pod *podcastindex.Podcast) *model.CommonSearchRes return p } -func UpdateSettings(downloadOnAdd bool, initialDownloadCount int, autoDownload bool, appendDateToFileName bool, appendEpisodeNumberToFileName bool, darkMode bool, downloadEpisodeImages bool, generateNFOFile bool) error { +func UpdateSettings(downloadOnAdd bool, initialDownloadCount int, autoDownload bool, appendDateToFileName bool, appendEpisodeNumberToFileName bool, darkMode bool, downloadEpisodeImages bool, generateNFOFile bool, dontDownloadDeletedFromDisk bool) error { setting := db.GetOrCreateSetting() setting.AutoDownload = autoDownload @@ -747,6 +752,7 @@ func UpdateSettings(downloadOnAdd bool, initialDownloadCount int, autoDownload b setting.DarkMode = darkMode setting.DownloadEpisodeImages = downloadEpisodeImages setting.GenerateNFOFile = generateNFOFile + setting.DontDownloadDeletedFromDisk = dontDownloadDeletedFromDisk return db.UpdateSettings(setting) }