~asimpson/podcast-filter

e3a7896c064f64fd7751d6864ad6c44a259f7ec5 — Adam Simpson 4 years ago f35e687 master
feat: add negate query param
2 files changed, 18 insertions(+), 8 deletions(-)

M README.md
M main.go
M README.md => README.md +4 -2
@@ 1,3 1,5 @@
podcast-filter
https://podcastfilter.com

hosted at https://podcastfilter.com
If you've ever wanted a filtered podcast feed that only has certain episodes of a show based on criteria in the episode description podcast-filter is for you!

Basically it's [`strings.Contains`](https://golang.org/pkg/strings/#Contains) applied to every episode description of the feed you give it.

M main.go => main.go +14 -6
@@ 15,20 15,23 @@ const index = `
<html lang="en">
  <head>
    <meta charset="UTF-8"/>
		<meta name="viewport" content="width=device-width,initial-scale=1.0">
    <title>podcastfilter.com</title>
  </head>
  <body>
    <h1>Welcome to podcastfilter.com</h1>

    <p>To use podcastfilter you need to supply two query params:</p>
    <p>To use podcastfilter you need to supply two query params (plus an optional third):</p>

    <ul>
      <li><code>query=SOME TEXT</code></li>
      <li><code>feed=https://example.com/somefeed.xml</code></li>
      <li><code>negate=true</code></li>
    </ul>
    <p>The final URL should look like this: <code>https://podcastfilter.com/?feed=https://example.com/feed.xml&query=Hi&20Bye</code></p>
    <p>The final URL should look like this: <code>https://podcastfilter.com/?feed=https://example.com/feed.xml&query=Hi&20Bye&negate=true</code></p>

    <p>podcastfilter will then return a new RSS feed you can subscribe to that only includes items whose descriptions contain the query.</p>
    <p>podcastfilter will then return a new RSS feed you can subscribe to that only includes items whose descriptions contain the query
		(or if negate is true will return a feed of items that don't match the query).</p>
  </body>
</html>
`


@@ 70,8 73,9 @@ type enclosure struct {
	Type   string `xml:"type,attr"`
}

func downloadAndParse(feedURL string, query string) string {
func downloadAndParse(feedURL string, query string, negate string) string {
	resp, err := http.Get(feedURL)
	shouldNegate := negate == "true"

	if err != nil {
		fmt.Println("http err: ", err)


@@ 93,7 97,11 @@ func downloadAndParse(feedURL string, query string) string {
		var item = feed.Items[i]
		matches := strings.Contains(item.Description, query)

		if matches {
		if matches && !shouldNegate {
			matchedItems = append(matchedItems, item)
		}

		if !matches && shouldNegate {
			matchedItems = append(matchedItems, item)
		}
	}


@@ 127,7 135,7 @@ func main() {
			io.WriteString(w, index)
		} else {
			w.Header().Set("Content-Type", "application/rss+xml")
			feed := downloadAndParse(query.Get("feed"), query.Get("query"))
			feed := downloadAndParse(query.Get("feed"), query.Get("query"), query.Get("negate"))
			io.WriteString(w, string(feed))
		}
	}