diff options
author | Evgeny Kuznetsov <evgeny@kuznetsov.md> | 2020-02-04 17:19:36 +0300 |
---|---|---|
committer | Evgeny Kuznetsov <evgeny@kuznetsov.md> | 2020-02-04 17:19:36 +0300 |
commit | 8f44886d0114de8a4a432e28de930eae0928f709 (patch) | |
tree | f397a76f4fbb2f15a26c2d9d1ab9200da2c6de82 /main.go | |
parent | 587088fc7d93c4e3bb918b97ec2a27f54d6f6db8 (diff) | |
download | radiorus-rss-8f44886d0114de8a4a432e28de930eae0928f709.tar.gz radiorus-rss-8f44886d0114de8a4a432e28de930eae0928f709.zip |
decouple enclosure finding
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 27 |
1 files changed, 16 insertions, 11 deletions
@@ -44,7 +44,6 @@ var ( programNameRe = regexp.MustCompile(`<h2>(.+?)?</h2>`) programAboutRe = regexp.MustCompile(`(?s)<div class="brand__content_text__anons">(.+?)?</div>`) programImageRe = regexp.MustCompile(`(?s)<div class="brand\-promo__header">(.+?)?<img src="(.+?)?"(.+?)?alt='(.+?)?'>`) - episodeAudioRe = regexp.MustCompile(`data\-id="(.+?)?">`) episodeDateRe = regexp.MustCompile(`brand\-time brand\-menu\-link">(.+?)?\.(.+?)?\.(.+?)? в (.+?)?:(.+?)?</a>`) episodeDescRe = regexp.MustCompile(`<p class="anons">(.+?)?</p>`) episodeTitleRe = regexp.MustCompile(`title brand\-menu\-link">(.+?)?</a>`) @@ -141,7 +140,7 @@ func populateFeed(feed *feeds.Feed, page []byte) (err error) { } 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]) + enclosure := findEnclosure(episode) dateBytes := episodeDateRe.FindSubmatch(episode) var date [5]int for i, b := range dateBytes[1:] { @@ -155,20 +154,26 @@ func populateFeed(feed *feeds.Feed, page []byte) (err error) { episodeDate := time.Date(date[2], time.Month(date[1]), date[0], date[3], date[4], 0, 0, moscow) feed.Add(&feeds.Item{ - Id: episodeID(episodeUrl), - Link: &feeds.Link{Href: episodeUrl}, - Title: episodeTitle, - Enclosure: &feeds.Enclosure{ - Url: episodeAudioUrl, - Length: "1024", - Type: "audio/mpeg", - }, - Created: episodeDate, + Id: episodeID(episodeUrl), + Link: &feeds.Link{Href: episodeUrl}, + Title: episodeTitle, + Enclosure: enclosure, + Created: episodeDate, }) } return nil } +func findEnclosure(ep []byte) *feeds.Enclosure { + episodeAudioRe := regexp.MustCompile(`data\-id="(.+?)?">`) + episodeAudioUrl := "https://audio.vgtrk.com/download?id=" + string(episodeAudioRe.FindSubmatch(ep)[1]) + return &feeds.Enclosure{ + Url: episodeAudioUrl, + Length: "1024", + Type: "audio/mpeg", + } +} + func findEpisodes(page []byte) [][]byte { episodeRe := regexp.MustCompile(`(?s)<div class="brand__list\-\-wrap\-\-item">(.+?)?data-id="(.+?)"></div>`) episodes := episodeRe.FindAll(page, -1) |