Merge pull request #214 from djluck/set-max-dl-concurrency

Add settings for Max DL concurrency + `User-Agent`
master
Akhil Gupta 2 years ago committed by GitHub
commit 44e2b1c207
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -104,7 +104,14 @@
<span class="label-body">Base URL (if accessing Podgrab using a URL. Without trailing /. Leave empty if not using or unsure.)</span>
<input type="url" class="u-full-width" name="baseUrl" v-model="baseUrl">
</label>
<label for="maxDownloadConcurrency" style="display: inline-block;" >
<span class="label-body">Limit the number of podcasts that can be downloaded simultaneously</span>
<input type="number" name="maxDownloadConcurrency" v-model.number="maxDownloadConcurrency" min="1">
</label>
<label for="userAgent" style="display: inline-block;" >
<span class="label-body">The <code>User-Agent</code> header used when downloading podcasts</span>
<input type="text" class="u-full-width" name="userAgent" v-model="userAgent">
</label>
<input type="submit" value="Save" class="button">
</form>
@ -182,6 +189,8 @@ var app = new Vue({
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 @@ var app = new Vue({
generateNFOFile:{{ .setting.GenerateNFOFile }},
dontDownloadDeletedFromDisk:{{ .setting.DontDownloadDeletedFromDisk }},
baseUrl: {{ .setting.BaseUrl }},
maxDownloadConcurrency:{{ .setting.MaxDownloadConcurrency }},
userAgent:{{ .setting.UserAgent}},
},
})

@ -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{

@ -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"})

@ -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

@ -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)

@ -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)
}

Loading…
Cancel
Save