fixd podcast

master
Bel LaPointe 2019-03-16 09:32:27 -06:00
parent 7fb3ffda5d
commit ccc9ea86f3
1 changed files with 10 additions and 3 deletions

View File

@ -224,6 +224,8 @@ func (ex *Exchange) handlerByTag(tags []string, items []*rss.Item) {
}
func (ex *Exchange) handlerPodcast(item *rss.Item) {
os.MkdirAll(ex.savepath, os.ModePerm)
if len(item.Enclosures) < 1 {
return
}
@ -232,6 +234,12 @@ func (ex *Exchange) handlerPodcast(item *rss.Item) {
if !strings.Contains(link, ".mp3") {
continue
}
savePath := path.Join(ex.savepath, path.Base(link))
if _, err := os.Stat(savePath); !os.IsNotExist(err) {
log.Printf("err: %v already exists", savePath)
continue
}
resp, err := http.Get(link)
if err != nil {
log.Printf("cannot get podcast %q: %v", link, err)
@ -239,10 +247,9 @@ func (ex *Exchange) handlerPodcast(item *rss.Item) {
}
defer resp.Body.Close()
os.MkdirAll(ex.savepath, os.ModePerm)
out, err := os.Create(path.Join(ex.savepath, path.Base(link)))
out, err := os.Create(savePath)
if err != nil {
log.Printf("cannot create file %q for saving: %v", path.Join(ex.savepath, path.Base(link)), err)
log.Printf("cannot create file %q for saving: %v", savePath, err)
continue
}
if _, err := io.Copy(out, resp.Body); err != nil {