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