From f1c749597bcf5588618eccbd2fbb7797b42eb713 Mon Sep 17 00:00:00 2001 From: Evgeny Kuznetsov Date: Tue, 28 Jan 2020 15:04:03 +0300 Subject: fix episode addressing for tests --- main.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'main.go') diff --git a/main.go b/main.go index f29fae3..749ba1a 100644 --- a/main.go +++ b/main.go @@ -133,12 +133,13 @@ func populateFeed(feed *feeds.Feed, page []byte) (err error) { } episodes := episodeRe.FindAll(page, -1) + urlPrefix := episodeURLPrefix(feed.Link.Href) for _, episode := range episodes { if len(episodeUrlRe.FindAllSubmatch(episode, -1)) > 1 { return errBadEpisode } - episodeUrl := "http://www.radiorus.ru/brand/" + string(episodeUrlRe.FindSubmatch(episode)[1]) + episodeUrl := urlPrefix + string(episodeUrlRe.FindSubmatch(episode)[1]) episodeTitle := string(episodeTitleRe.FindSubmatch(episode)[1]) episodeAudioUrl := "https://audio.vgtrk.com/download?id=" + string(episodeAudioRe.FindSubmatch(episode)[1]) dateBytes := episodeDateRe.FindSubmatch(episode) @@ -224,3 +225,8 @@ func cleanText(b []byte) []byte { } return b } + +// episodeURLPrefix derives common episode URL prefix from programme page URL +func episodeURLPrefix(url string) string { + return strings.Split(url, "/brand/")[0] + "/brand/" +} -- cgit v1.2.3