From 44671d3b072f3cc0212c3870176d33c8f13d358e Mon Sep 17 00:00:00 2001 From: Akhil Gupta Date: Fri, 7 May 2021 06:28:12 +0530 Subject: [PATCH] Closing #90 --- Readme.md | 2 +- client/settings.html | 11 ++++++++--- controllers/pages.go | 1 + controllers/podcast.go | 2 +- db/podcast.go | 1 + service/fileService.go | 29 +++++++++++++++++++++++++++++ service/podcastService.go | 11 +++++++++-- 7 files changed, 50 insertions(+), 7 deletions(-) diff --git a/Readme.md b/Readme.md index c92cebe..7a20a36 100644 --- a/Readme.md +++ b/Readme.md @@ -14,7 +14,7 @@ -->

Podgrab

-

Current Version - 2021.05.06

+

Current Version - 2021.05.07

A self-hosted podcast manager to download episodes as soon as they become live diff --git a/client/settings.html b/client/settings.html index dc044b0..cff9adc 100644 --- a/client/settings.html +++ b/client/settings.html @@ -86,6 +86,10 @@ Download Episode Images with files + @@ -117,7 +121,7 @@ - + @@ -160,8 +164,8 @@ var app = new Vue({ appendDateToFileName:self.appendDateToFileName, appendEpisodeNumberToFileName:self.appendEpisodeNumberToFileName, darkMode:self.darkMode, - downloadEpisodeImages:self.downloadEpisodeImages - + downloadEpisodeImages:self.downloadEpisodeImages, + generateNFOFile:self.generateNFOFile }) .then(function(response){ Vue.toasted.show('Settings saved successfully.' ,{ @@ -203,6 +207,7 @@ var app = new Vue({ darkMode:{{ .setting.DarkMode }}, originalThemeSetting:{{ .setting.DarkMode }}, downloadEpisodeImages:{{.setting.DownloadEpisodeImages }}, + generateNFOFile:{{.setting.GenerateNFOFile }}, }, }) diff --git a/controllers/pages.go b/controllers/pages.go index e34242b..2d2476d 100644 --- a/controllers/pages.go +++ b/controllers/pages.go @@ -28,6 +28,7 @@ type SettingModel struct { AppendEpisodeNumberToFileName bool `form:"appendEpisodeNumberToFileName" json:"appendEpisodeNumberToFileName" query:"appendEpisodeNumberToFileName"` DarkMode bool `form:"darkMode" json:"darkMode" query:"darkMode"` DownloadEpisodeImages bool `form:"downloadEpisodeImages" json:"downloadEpisodeImages" query:"downloadEpisodeImages"` + GenerateNFOFile bool `form:"generateNFOFile" json:"generateNFOFile" query:"generateNFOFile"` } var searchOptions = map[string]string{ diff --git a/controllers/podcast.go b/controllers/podcast.go index 9355936..a71ab81 100644 --- a/controllers/podcast.go +++ b/controllers/podcast.go @@ -465,7 +465,7 @@ func UpdateSetting(c *gin.Context) { err = service.UpdateSettings(model.DownloadOnAdd, model.InitialDownloadCount, model.AutoDownload, model.AppendDateToFileName, model.AppendEpisodeNumberToFileName, - model.DarkMode, model.DownloadEpisodeImages) + model.DarkMode, model.DownloadEpisodeImages, model.GenerateNFOFile) if err == nil { c.JSON(200, gin.H{"message": "Success"}) diff --git a/db/podcast.go b/db/podcast.go index ef84f15..854d3f5 100644 --- a/db/podcast.go +++ b/db/podcast.go @@ -82,6 +82,7 @@ type Setting struct { AppendEpisodeNumberToFileName bool `gorm:"default:false"` DarkMode bool `gorm:"default:false"` DownloadEpisodeImages bool `gorm:"default:false"` + GenerateNFOFile bool `gorm:"default:false"` } type Migration struct { Base diff --git a/service/fileService.go b/service/fileService.go index cdce810..c9857de 100644 --- a/service/fileService.go +++ b/service/fileService.go @@ -3,9 +3,11 @@ package service import ( "archive/tar" "compress/gzip" + "encoding/xml" "errors" "fmt" "io" + "io/ioutil" "net/http" "net/url" "os" @@ -15,6 +17,7 @@ import ( "strconv" "time" + "github.com/akhilrex/podgrab/db" "github.com/akhilrex/podgrab/internal/sanitize" stringy "github.com/gobeam/stringy" ) @@ -68,6 +71,32 @@ func GetPodcastLocalImagePath(link string, podcastName string) string { return finalPath } +func CreateNfoFile(podcast *db.Podcast) error { + fileName := "album.nfo" + folder := createDataFolderIfNotExists(podcast.Title) + + finalPath := path.Join(folder, fileName) + + type NFO struct { + XMLName xml.Name `xml:"album"` + Title string `xml:"title"` + Type string `xml:"type"` + Thumb string `xml:"thumb"` + } + + toSave := NFO{ + Title: podcast.Title, + Type: "Broadcast", + Thumb: podcast.Image, + } + out, err := xml.MarshalIndent(toSave, " ", " ") + if err != nil { + return err + } + toPersist := xml.Header + string(out) + return ioutil.WriteFile(finalPath, []byte(toPersist), 0644) +} + func DownloadPodcastCoverImage(link string, podcastName string) (string, error) { if link == "" { return "", errors.New("Download path empty") diff --git a/service/podcastService.go b/service/podcastService.go index 1ac0b03..f8f8395 100644 --- a/service/podcastService.go +++ b/service/podcastService.go @@ -198,7 +198,7 @@ func getItunesImageUrl(body []byte) string { func AddPodcast(url string) (db.Podcast, error) { var podcast db.Podcast err := db.GetPodcastByURL(url, &podcast) - + setting := db.GetOrCreateSetting() if errors.Is(err, gorm.ErrRecordNotFound) { data, body, err := FetchURL(url) if err != nil { @@ -221,6 +221,9 @@ func AddPodcast(url string) (db.Podcast, error) { err = db.CreatePodcast(&podcast) go DownloadPodcastCoverImage(podcast.Image, podcast.Title) + if setting.GenerateNFOFile { + go CreateNfoFile(&podcast) + } return podcast, err } @@ -617,6 +620,9 @@ func DeletePodcastEpisodes(id string) error { } for _, item := range podcastItems { DeleteFile(item.DownloadPath) + if item.LocalImage != "" { + DeleteFile(item.LocalImage) + } SetPodcastItemAsNotDownloaded(item.ID, db.Deleted) } @@ -719,7 +725,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) error { +func UpdateSettings(downloadOnAdd bool, initialDownloadCount int, autoDownload bool, appendDateToFileName bool, appendEpisodeNumberToFileName bool, darkMode bool, downloadEpisodeImages bool, generateNFOFile bool) error { setting := db.GetOrCreateSetting() setting.AutoDownload = autoDownload @@ -729,6 +735,7 @@ func UpdateSettings(downloadOnAdd bool, initialDownloadCount int, autoDownload b setting.AppendEpisodeNumberToFileName = appendEpisodeNumberToFileName setting.DarkMode = darkMode setting.DownloadEpisodeImages = downloadEpisodeImages + setting.GenerateNFOFile = generateNFOFile return db.UpdateSettings(setting) }
Current Version2021.05.062021.05.07
Website