diff --git a/rss/feed.go b/rss/feed.go index 144acfd..2c6b2ff 100755 --- a/rss/feed.go +++ b/rss/feed.go @@ -1,6 +1,7 @@ package rss import ( + "encoding/json" "errors" "local/rssmon3/config" "log" @@ -23,6 +24,7 @@ type Feed struct { ContentFilter string Tags []string Copyright string + Headers []byte } func SubmitFeed(f *Feed) error { @@ -61,7 +63,16 @@ func (f *Feed) Pull() error { return err } } - resp, err := http.Get(f.URL) + req, err := http.NewRequest(http.MethodGet, f.URL, nil) + if err != nil { + return err + } + var headers map[string]string + json.Unmarshal(f.Headers, &headers) + for k, v := range headers { + req.Header.Set(k, v) + } + resp, err := http.DefaultClient.Do(req) if err != nil { return err } diff --git a/server/routes.go b/server/routes.go index c6b83ad..75f963e 100755 --- a/server/routes.go +++ b/server/routes.go @@ -81,17 +81,22 @@ func (s *Server) feed(w http.ResponseWriter, r *http.Request) { return } var putFeed struct { - URL string `json:"url"` - Interval string `json:"refresh"` - TitleFilter string `json:"items"` - Copyright string `json:"copyright"` - ContentFilter string `json:"content"` - Tags []string `json:"tags"` + URL string `json:"url"` + Interval string `json:"refresh"` + TitleFilter string `json:"items"` + Copyright string `json:"copyright"` + ContentFilter string `json:"content"` + Tags []string `json:"tags"` + Headers map[string]string `json:"headers"` } if err := json.NewDecoder(r.Body).Decode(&putFeed); err != nil { s.userError(w, r, err) return } + if putFeed.Headers == nil { + putFeed.Headers = map[string]string{} + } + putFeedHeaders, _ := json.Marshal(putFeed.Headers) interval, err := time.ParseDuration(putFeed.Interval) if err != nil { s.userError(w, r, err) @@ -104,6 +109,7 @@ func (s *Server) feed(w http.ResponseWriter, r *http.Request) { ContentFilter: putFeed.ContentFilter, Tags: putFeed.Tags, Copyright: putFeed.Copyright, + Headers: putFeedHeaders, } if err := rss.SubmitFeed(f); err != nil { s.error(w, r, err) diff --git a/testdata/add b/testdata/add index f0e789c..e4ca5a1 100755 --- a/testdata/add +++ b/testdata/add @@ -33,18 +33,10 @@ https://www.youtube.com/feeds/videos.xml?channel_id=UC9YLd0REiXxLqQQH_CpJKZQ https://www.youtube.com/feeds/videos.xml?channel_id=UCsvn_Po0SmunchJYOWpOxMg youtube","videogamedunkey ".*" ".*" "6h" https://www.youtube.com/feeds/videos.xml?channel_id=UCs-w7E2HZWwXmjt9RTvBB_A youtube","settled ".*" ".*" "6h" https://roosterteeth.com/show/rt-podcast/feed/mp3 podcast ".*" ".*" "6h" -https://eztv.ag/ezrss.xml?c=c momma","torrent "^NOT(d.Rush.*720.*WEB|Gold.Rush.*S.*E.*720.*WEB)" "" "2h" GoldRush -https://eztv.ag/ezrss.xml?e=e momma","torrent "^(Archer|The.Handmaids.Tale.*720.*WEB|Australian.Ninja.Warrior.*HDTV)" "" "2h" -https://eztv.ag/ezrss.xml?b=b momma","torrent "^(Survivor.S.*720p|[Ss]urvivor.*[AaSs][UuAa])" "" "2h" Survivor http://lizclimo.tumblr.com/rss comic na na "24h" -https://eztv.ag/ezrss.xml?a=a momma","torrent "^abc123(Wheel.[oO]f.Fortune.[S2]|Jeopardy.20|[tT]he.[pP]rice.[iI]s.[rR]ight|[lL]et.*[mM]ake.[aA].[dD]eal)" "" "2h" GameShows -https://eztv.ag/ezrss.xml?d=d momma","torrent "([Mm]andalorian)" "" "2h" Mandalorian http://feeds.feedburner.com/blogspot/sBff cooking ".*" ".*" "24h" https://jaiminisbox.com/reader/feeds/rss manga "olo.*eveling" ".*" "6h" -https://eztv.ag/ezrss.xml?f=f momma","torrent "^([Vv]ikings.S)" "" "2h" Vikings https://xkcd.com/atom.xml comic na na "24h" -https://eztv.ag/ezrss.xml?g=g torrent","news "^([Ll]ast..eek..onight..ith..ohn..liver.*WEB)" "" "2h" LastWeekTonight -https://eztv.ag/ezrss.xml?h=h torrent "^([Rr]ick.[Aa]nd.[Mm]orty)" "" "2h" RickAndMorty https://matrix.org/blog/feed news ".*" ".*" "1h" https://nyaa.si/?page=rss&f=0&c=0_0&q=shingeki+no+kyojin+final+season+720p anime","torrent ".*" ".*" "1h" Anime-ShingekiNoKyojin https://workchronicles.com/feed/ comic na na "4h" @@ -52,11 +44,19 @@ https://nyaa.si/?page=rss&f=0&c=0_0&q=re+zero+2nd+part+erai+raws+720 https://www.webtoons.com/en/challenge/books-of-adam/rss?title_no=136637 comic na na "12h" https://www.webtoons.com/en/romance/the-makeup-remover/rss?title_no=2186 comic na na "12h" https://www.webtoons.com/en/romance/truebeauty/rss?title_no=1436 comic na na "12h" -https://eztv.ag/ezrss.xml?d=d cooking","torrent "^([Mm]aster[cC]hef.*720p.WEB|[Mm]aster[cC]hef.Aus.*)" "" "2h" MasterChef https://subsplease.org/rss/?r=720 anime","torrent "^jfkaldsjfkldsjafd;sa" "" "2h" Anime +https://eztv.ag/ezrss.xml?h=h torrent "^([Rr]ick.[Aa]nd.[Mm]orty)" "" "2h" RickAndMorty +https://eztv.ag/ezrss.xml?c=c momma","torrent "^NOT(d.Rush.*720.*WEB|Gold.Rush.*S.*E.*720.*WEB)" "" "2h" GoldRush +https://eztv.ag/ezrss.xml?e=e momma","torrent "^(Archer|The.Handmaids.Tale.*720.*WEB|Australian.Ninja.Warrior.*HDTV)" "" "2h" +https://eztv.ag/ezrss.xml?b=b momma","torrent "^(Survivor.S.*720p|[Ss]urvivor.*[AaSs][UuAa])" "" "2h" Survivor +https://eztv.ag/ezrss.xml?a=a momma","torrent "^abc123(Wheel.[oO]f.Fortune.[S2]|Jeopardy.20|[tT]he.[pP]rice.[iI]s.[rR]ight|[lL]et.*[mM]ake.[aA].[dD]eal)" "" "2h" GameShows +https://eztv.ag/ezrss.xml?d=d momma","torrent "([Mm]andalorian)" "" "2h" Mandalorian +https://eztv.ag/ezrss.xml?f=f momma","torrent "^([Vv]ikings.S)" "" "2h" Vikings +https://eztv.ag/ezrss.xml?g=g torrent","news "^([Ll]ast..eek..onight..ith..ohn..liver.*WEB)" "" "2h" LastWeekTonight +https://eztv.ag/ezrss.xml?d=d cooking","torrent "^([Mm]aster[cC]hef.*720p.WEB|[Mm]aster[cC]hef.Aus.*)" "" "2h" MasterChef ' #https://eztv.ag/ezrss.xml momma","torrent "^(Wheel.[oO]f.Fortune.[S2]|Jeopardy.20|Gold.Rush.*720.*WEB|Survivor.S.*720p|Gold.Rush.*S.*E.*720.*WEB|Archer|[Mm]aster[cC]hef.US.*720p.WEB|[Mm]aster[cC]hef.Aus.*|[tT]he.[pP]rice.[iI]s.[rR]ight|[lL]et.*[mM]ake.[aA].[dD]eal|The.Handmaids.Tale.*720.*WEB|[Ss]urvivor.*[AaSs][UuAa]|Australian.Ninja.Warrior.*HDTV)" "" "2h" -feedsB="$(printf "%s\n" "$feeds" | grep -v '^$' | tail -n 1)" +feedsB="$(printf "%s\n" "$feeds" | grep -v '^$' | tail -n 9)" feeds="$feedsB" defaultIF='""'