aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeny Kuznetsov <evgeny@kuznetsov.md>2020-01-28 22:48:55 +0300
committerEvgeny Kuznetsov <evgeny@kuznetsov.md>2020-01-28 22:48:55 +0300
commit0dfb7a7190b5039177627abc0cb8eed48313378b (patch)
tree06dcc4d71950b23c363e66af4d3664c3db84f481
parentba1af3d90e4b5d2a01cd42e558e0a53f342a2f75 (diff)
downloadradiorus-rss-0dfb7a7190b5039177627abc0cb8eed48313378b.tar.gz
radiorus-rss-0dfb7a7190b5039177627abc0cb8eed48313378b.zip
use HTTPS
-rw-r--r--main.go13
-rw-r--r--main_test.go20
2 files changed, 31 insertions, 2 deletions
diff --git a/main.go b/main.go
index c34dcf4..2d71e4d 100644
--- a/main.go
+++ b/main.go
@@ -62,7 +62,7 @@ func main() {
flag.StringVar(&programNumber, "brand", "57083", "brand number (defaults to Aerostat)")
flag.Parse()
- url := "http://www.radiorus.ru/brand/" + programNumber + "/episodes"
+ url := "https://www.radiorus.ru/brand/" + programNumber + "/episodes"
feed := processURL(url)
@@ -156,7 +156,7 @@ 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: episodeUrl,
+ Id: episodeID(episodeUrl),
Link: &feeds.Link{Href: episodeUrl},
Title: episodeTitle,
Enclosure: &feeds.Enclosure{
@@ -246,3 +246,12 @@ func cleanText(b []byte) []byte {
func episodeURLPrefix(url string) string {
return strings.Split(url, "/brand/")[0] + "/brand/"
}
+
+// episodeID generates episode ID from episode URL,
+// changes "https://" to "http://" for backwards compatibility purposes
+func episodeID(url string) string {
+ if strings.HasPrefix(url, "https://") {
+ return "http://" + strings.TrimPrefix(url, "https://")
+ }
+ return url
+}
diff --git a/main_test.go b/main_test.go
index 8aa272d..b3d1b7f 100644
--- a/main_test.go
+++ b/main_test.go
@@ -206,3 +206,23 @@ func TestEpisodeURLPrefix(t *testing.T) {
t.Fatalf("got %v, want %v", got, want)
}
}
+
+func TestEpisodeID(t *testing.T) {
+ type testval struct {
+ url string
+ id string
+ }
+
+ var tests = []testval{
+ {"http://www.radiorus.ru/brand/57083/episode/foo", "http://www.radiorus.ru/brand/57083/episode/foo"},
+ {"https://www.radiorus.ru/brand/57083/episode/foo", "http://www.radiorus.ru/brand/57083/episode/foo"},
+ }
+
+ for _, test := range tests {
+ got := episodeID(test.url)
+ want := test.id
+ if got != want {
+ t.Error("want:", want, "got:", got)
+ }
+ }
+}