diff --git a/client/settings.html b/client/settings.html
index fb88c3e..4ce42bb 100644
--- a/client/settings.html
+++ b/client/settings.html
@@ -104,7 +104,14 @@
Settings
Base URL (if accessing Podgrab using a URL. Without trailing /. Leave empty if not using or unsure.)
-
+
+
@@ -182,6 +189,8 @@ More Info
generateNFOFile:self.generateNFOFile,
dontDownloadDeletedFromDisk:self.dontDownloadDeletedFromDisk,
baseUrl:self.baseUrl,
+ maxDownloadConcurrency:self.maxDownloadConcurrency,
+ userAgent:self.userAgent,
})
.then(function(response){
Vue.toasted.show('Settings saved successfully.' ,{
@@ -226,6 +235,8 @@ More Info
generateNFOFile:{{ .setting.GenerateNFOFile }},
dontDownloadDeletedFromDisk:{{ .setting.DontDownloadDeletedFromDisk }},
baseUrl: {{ .setting.BaseUrl }},
+ maxDownloadConcurrency:{{ .setting.MaxDownloadConcurrency }},
+ userAgent:{{ .setting.UserAgent}},
},
})
diff --git a/controllers/pages.go b/controllers/pages.go
index 2034e22..2b13de3 100644
--- a/controllers/pages.go
+++ b/controllers/pages.go
@@ -31,6 +31,8 @@ type SettingModel struct {
GenerateNFOFile bool `form:"generateNFOFile" json:"generateNFOFile" query:"generateNFOFile"`
DontDownloadDeletedFromDisk bool `form:"dontDownloadDeletedFromDisk" json:"dontDownloadDeletedFromDisk" query:"dontDownloadDeletedFromDisk"`
BaseUrl string `form:"baseUrl" json:"baseUrl" query:"baseUrl"`
+ MaxDownloadConcurrency int `form:"maxDownloadConcurrency" json:"maxDownloadConcurrency" query:"maxDownloadConcurrency"`
+ UserAgent string `form:"userAgent" json:"userAgent" query:"userAgent"`
}
var searchOptions = map[string]string{
diff --git a/controllers/podcast.go b/controllers/podcast.go
index de692e8..199f4a3 100644
--- a/controllers/podcast.go
+++ b/controllers/podcast.go
@@ -628,7 +628,9 @@ 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.DontDownloadDeletedFromDisk, model.BaseUrl)
+ model.DarkMode, model.DownloadEpisodeImages, model.GenerateNFOFile, model.DontDownloadDeletedFromDisk, model.BaseUrl,
+ model.MaxDownloadConcurrency, model.UserAgent,
+ )
if err == nil {
c.JSON(200, gin.H{"message": "Success"})
diff --git a/db/podcast.go b/db/podcast.go
index 0962dd1..8a33823 100644
--- a/db/podcast.go
+++ b/db/podcast.go
@@ -87,6 +87,8 @@ type Setting struct {
GenerateNFOFile bool `gorm:"default:false"`
DontDownloadDeletedFromDisk bool `gorm:"default:false"`
BaseUrl string
+ MaxDownloadConcurrency int `gorm:"default:5"`
+ UserAgent string
}
type Migration struct {
Base
diff --git a/service/fileService.go b/service/fileService.go
index 4c9fc56..6f9c921 100644
--- a/service/fileService.go
+++ b/service/fileService.go
@@ -27,7 +27,13 @@ func Download(link string, episodeTitle string, podcastName string, prefix strin
return "", errors.New("Download path empty")
}
client := httpClient()
- resp, err := client.Get(link)
+
+ req, err := getRequest(link)
+ if err != nil {
+ Logger.Errorw("Error creating request: "+link, err)
+ }
+
+ resp, err := client.Do(req)
if err != nil {
Logger.Errorw("Error getting response: "+link, err)
return "", err
@@ -102,7 +108,13 @@ func DownloadPodcastCoverImage(link string, podcastName string) (string, error)
return "", errors.New("Download path empty")
}
client := httpClient()
- resp, err := client.Get(link)
+ req, err := getRequest(link)
+ if err != nil {
+ Logger.Errorw("Error creating request: "+link, err)
+ return "", err
+ }
+
+ resp, err := client.Do(req)
if err != nil {
Logger.Errorw("Error getting response: "+link, err)
return "", err
@@ -139,7 +151,13 @@ func DownloadImage(link string, episodeId string, podcastName string) (string, e
return "", errors.New("Download path empty")
}
client := httpClient()
- resp, err := client.Get(link)
+ req, err := getRequest(link)
+ if err != nil {
+ Logger.Errorw("Error creating request: "+link, err)
+ return "", err
+ }
+
+ resp, err := client.Do(req)
if err != nil {
Logger.Errorw("Error getting response: "+link, err)
return "", err
@@ -326,6 +344,20 @@ func httpClient() *http.Client {
return &client
}
+func getRequest(url string) (*http.Request, error) {
+ req, err := http.NewRequest("GET", url, nil)
+ if err != nil {
+ return nil, err
+ }
+
+ setting := db.GetOrCreateSetting()
+ if len(setting.UserAgent) > 0 {
+ req.Header.Add("User-Agent", setting.UserAgent)
+ }
+
+ return req, nil
+}
+
func createFolder(folder string, parent string) string {
folder = cleanFileName(folder)
//str := stringy.New(folder)
diff --git a/service/podcastService.go b/service/podcastService.go
index 345d2a2..ac91a5e 100644
--- a/service/podcastService.go
+++ b/service/podcastService.go
@@ -537,7 +537,7 @@ func DownloadMissingEpisodes() error {
SetPodcastItemAsDownloaded(item.ID, url)
}(item, *setting)
- if index%5 == 0 {
+ if index%setting.MaxDownloadConcurrency == 0 {
wg.Wait()
}
}
@@ -764,7 +764,7 @@ func GetSearchFromPodcastIndex(pod *podcastindex.Podcast) *model.CommonSearchRes
func UpdateSettings(downloadOnAdd bool, initialDownloadCount int, autoDownload bool,
appendDateToFileName bool, appendEpisodeNumberToFileName bool, darkMode bool, downloadEpisodeImages bool,
- generateNFOFile bool, dontDownloadDeletedFromDisk bool, baseUrl string) error {
+ generateNFOFile bool, dontDownloadDeletedFromDisk bool, baseUrl string, maxDownloadConcurrency int, userAgent string) error {
setting := db.GetOrCreateSetting()
setting.AutoDownload = autoDownload
@@ -777,6 +777,8 @@ func UpdateSettings(downloadOnAdd bool, initialDownloadCount int, autoDownload b
setting.GenerateNFOFile = generateNFOFile
setting.DontDownloadDeletedFromDisk = dontDownloadDeletedFromDisk
setting.BaseUrl = baseUrl
+ setting.MaxDownloadConcurrency = maxDownloadConcurrency
+ setting.UserAgent = userAgent
return db.UpdateSettings(setting)
}