aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeny Kuznetsov <evgeny@kuznetsov.md>2020-02-04 17:19:36 +0300
committerEvgeny Kuznetsov <evgeny@kuznetsov.md>2020-02-04 17:19:36 +0300
commit8f44886d0114de8a4a432e28de930eae0928f709 (patch)
treef397a76f4fbb2f15a26c2d9d1ab9200da2c6de82
parent587088fc7d93c4e3bb918b97ec2a27f54d6f6db8 (diff)
downloadradiorus-rss-8f44886d0114de8a4a432e28de930eae0928f709.tar.gz
radiorus-rss-8f44886d0114de8a4a432e28de930eae0928f709.zip
decouple enclosure finding
-rw-r--r--main.go27
1 files changed, 16 insertions, 11 deletions
diff --git a/main.go b/main.go
index 5d7115b..a105576 100644
--- a/main.go
+++ b/main.go
@@ -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)