aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorEvgeny Kuznetsov <evgeny@kuznetsov.md>2020-02-05 20:27:25 +0300
committerEvgeny Kuznetsov <evgeny@kuznetsov.md>2020-02-05 20:27:25 +0300
commit3cd999ac2ed914eb2d0c76e31261b4416a84d9ca (patch)
tree5723bec595e13678b15506f43cf33582aa9eea47 /main.go
parent789eb9f24ac72505ef8bd89d6c94a99ba9d7efad (diff)
downloadradiorus-rss-3cd999ac2ed914eb2d0c76e31261b4416a84d9ca.tar.gz
radiorus-rss-3cd999ac2ed914eb2d0c76e31261b4416a84d9ca.zip
don't panic when feed image can't be parsed
Diffstat (limited to 'main.go')
-rw-r--r--main.go18
1 files changed, 12 insertions, 6 deletions
diff --git a/main.go b/main.go
index 5f990bb..febb3e0 100644
--- a/main.go
+++ b/main.go
@@ -119,12 +119,7 @@ func populateFeed(feed *feeds.Feed, page []byte) (err error) {
}
feed.Title = stripLink(string(title))
- programImage := programImageRe.FindSubmatch(page)
- feed.Image = &feeds.Image{
- Link: feed.Link.Href,
- Url: string(programImage[2]),
- Title: string(programImage[4]),
- }
+ addFeedImage(page, feed)
episodes := findEpisodes(page)
urlPrefix := episodeURLPrefix(feed.Link.Href)
@@ -154,6 +149,17 @@ func populateFeed(feed *feeds.Feed, page []byte) (err error) {
return
}
+func addFeedImage(page []byte, feed *feeds.Feed) {
+ programImage, err := parse(page, programImageRe, 4)
+ if err == nil {
+ feed.Image = &feeds.Image{
+ Link: feed.Link.Href,
+ Url: string(programImage[1]),
+ Title: string(programImage[3]),
+ }
+ }
+}
+
func parse(src []byte, re *regexp.Regexp, n int) (out [][]byte, err error) {
match := re.FindSubmatch(src)
if len(match) != n+1 {