pull/114/head
Akhil Gupta 4 years ago
parent 509749e74e
commit 44671d3b07

@ -14,7 +14,7 @@
</a> --> </a> -->
<h1 align="center" style="margin-bottom:0px">Podgrab</h1> <h1 align="center" style="margin-bottom:0px">Podgrab</h1>
<p align="center">Current Version - 2021.05.06</p> <p align="center">Current Version - 2021.05.07</p>
<p align="center"> <p align="center">
A self-hosted podcast manager to download episodes as soon as they become live A self-hosted podcast manager to download episodes as soon as they become live

@ -86,6 +86,10 @@
<input type="checkbox" name="downloadEpisodeImages" v-model="downloadEpisodeImages"> <input type="checkbox" name="downloadEpisodeImages" v-model="downloadEpisodeImages">
<span class="label-body">Download Episode Images with files</span> <span class="label-body">Download Episode Images with files</span>
</label> </label>
<label for="generateNFOFile">
<input type="checkbox" name="generateNFOFile" v-model="generateNFOFile">
<span class="label-body">Generate NFO files for Podcasts</span>
</label>
<input type="submit" value="Save" class="button"> <input type="submit" value="Save" class="button">
@ -117,7 +121,7 @@
<table> <table>
<tr> <tr>
<td>Current Version</td> <td>Current Version</td>
<td>2021.05.06</td> <td>2021.05.07</td>
</tr> </tr>
<tr> <tr>
<td>Website</td> <td>Website</td>
@ -160,8 +164,8 @@ var app = new Vue({
appendDateToFileName:self.appendDateToFileName, appendDateToFileName:self.appendDateToFileName,
appendEpisodeNumberToFileName:self.appendEpisodeNumberToFileName, appendEpisodeNumberToFileName:self.appendEpisodeNumberToFileName,
darkMode:self.darkMode, darkMode:self.darkMode,
downloadEpisodeImages:self.downloadEpisodeImages downloadEpisodeImages:self.downloadEpisodeImages,
generateNFOFile:self.generateNFOFile
}) })
.then(function(response){ .then(function(response){
Vue.toasted.show('Settings saved successfully.' ,{ Vue.toasted.show('Settings saved successfully.' ,{
@ -203,6 +207,7 @@ var app = new Vue({
darkMode:{{ .setting.DarkMode }}, darkMode:{{ .setting.DarkMode }},
originalThemeSetting:{{ .setting.DarkMode }}, originalThemeSetting:{{ .setting.DarkMode }},
downloadEpisodeImages:{{.setting.DownloadEpisodeImages }}, downloadEpisodeImages:{{.setting.DownloadEpisodeImages }},
generateNFOFile:{{.setting.GenerateNFOFile }},
}, },
}) })

@ -28,6 +28,7 @@ type SettingModel struct {
AppendEpisodeNumberToFileName bool `form:"appendEpisodeNumberToFileName" json:"appendEpisodeNumberToFileName" query:"appendEpisodeNumberToFileName"` AppendEpisodeNumberToFileName bool `form:"appendEpisodeNumberToFileName" json:"appendEpisodeNumberToFileName" query:"appendEpisodeNumberToFileName"`
DarkMode bool `form:"darkMode" json:"darkMode" query:"darkMode"` DarkMode bool `form:"darkMode" json:"darkMode" query:"darkMode"`
DownloadEpisodeImages bool `form:"downloadEpisodeImages" json:"downloadEpisodeImages" query:"downloadEpisodeImages"` DownloadEpisodeImages bool `form:"downloadEpisodeImages" json:"downloadEpisodeImages" query:"downloadEpisodeImages"`
GenerateNFOFile bool `form:"generateNFOFile" json:"generateNFOFile" query:"generateNFOFile"`
} }
var searchOptions = map[string]string{ var searchOptions = map[string]string{

@ -465,7 +465,7 @@ func UpdateSetting(c *gin.Context) {
err = service.UpdateSettings(model.DownloadOnAdd, model.InitialDownloadCount, err = service.UpdateSettings(model.DownloadOnAdd, model.InitialDownloadCount,
model.AutoDownload, model.AppendDateToFileName, model.AppendEpisodeNumberToFileName, model.AutoDownload, model.AppendDateToFileName, model.AppendEpisodeNumberToFileName,
model.DarkMode, model.DownloadEpisodeImages) model.DarkMode, model.DownloadEpisodeImages, model.GenerateNFOFile)
if err == nil { if err == nil {
c.JSON(200, gin.H{"message": "Success"}) c.JSON(200, gin.H{"message": "Success"})

@ -82,6 +82,7 @@ type Setting struct {
AppendEpisodeNumberToFileName bool `gorm:"default:false"` AppendEpisodeNumberToFileName bool `gorm:"default:false"`
DarkMode bool `gorm:"default:false"` DarkMode bool `gorm:"default:false"`
DownloadEpisodeImages bool `gorm:"default:false"` DownloadEpisodeImages bool `gorm:"default:false"`
GenerateNFOFile bool `gorm:"default:false"`
} }
type Migration struct { type Migration struct {
Base Base

@ -3,9 +3,11 @@ package service
import ( import (
"archive/tar" "archive/tar"
"compress/gzip" "compress/gzip"
"encoding/xml"
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"net/url" "net/url"
"os" "os"
@ -15,6 +17,7 @@ import (
"strconv" "strconv"
"time" "time"
"github.com/akhilrex/podgrab/db"
"github.com/akhilrex/podgrab/internal/sanitize" "github.com/akhilrex/podgrab/internal/sanitize"
stringy "github.com/gobeam/stringy" stringy "github.com/gobeam/stringy"
) )
@ -68,6 +71,32 @@ func GetPodcastLocalImagePath(link string, podcastName string) string {
return finalPath 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) { func DownloadPodcastCoverImage(link string, podcastName string) (string, error) {
if link == "" { if link == "" {
return "", errors.New("Download path empty") return "", errors.New("Download path empty")

@ -198,7 +198,7 @@ func getItunesImageUrl(body []byte) string {
func AddPodcast(url string) (db.Podcast, error) { func AddPodcast(url string) (db.Podcast, error) {
var podcast db.Podcast var podcast db.Podcast
err := db.GetPodcastByURL(url, &podcast) err := db.GetPodcastByURL(url, &podcast)
setting := db.GetOrCreateSetting()
if errors.Is(err, gorm.ErrRecordNotFound) { if errors.Is(err, gorm.ErrRecordNotFound) {
data, body, err := FetchURL(url) data, body, err := FetchURL(url)
if err != nil { if err != nil {
@ -221,6 +221,9 @@ func AddPodcast(url string) (db.Podcast, error) {
err = db.CreatePodcast(&podcast) err = db.CreatePodcast(&podcast)
go DownloadPodcastCoverImage(podcast.Image, podcast.Title) go DownloadPodcastCoverImage(podcast.Image, podcast.Title)
if setting.GenerateNFOFile {
go CreateNfoFile(&podcast)
}
return podcast, err return podcast, err
} }
@ -617,6 +620,9 @@ func DeletePodcastEpisodes(id string) error {
} }
for _, item := range podcastItems { for _, item := range podcastItems {
DeleteFile(item.DownloadPath) DeleteFile(item.DownloadPath)
if item.LocalImage != "" {
DeleteFile(item.LocalImage)
}
SetPodcastItemAsNotDownloaded(item.ID, db.Deleted) SetPodcastItemAsNotDownloaded(item.ID, db.Deleted)
} }
@ -719,7 +725,7 @@ func GetSearchFromPodcastIndex(pod *podcastindex.Podcast) *model.CommonSearchRes
return p 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 := db.GetOrCreateSetting()
setting.AutoDownload = autoDownload setting.AutoDownload = autoDownload
@ -729,6 +735,7 @@ func UpdateSettings(downloadOnAdd bool, initialDownloadCount int, autoDownload b
setting.AppendEpisodeNumberToFileName = appendEpisodeNumberToFileName setting.AppendEpisodeNumberToFileName = appendEpisodeNumberToFileName
setting.DarkMode = darkMode setting.DarkMode = darkMode
setting.DownloadEpisodeImages = downloadEpisodeImages setting.DownloadEpisodeImages = downloadEpisodeImages
setting.GenerateNFOFile = generateNFOFile
return db.UpdateSettings(setting) return db.UpdateSettings(setting)
} }

Loading…
Cancel
Save