site2rss

command module
v0.0.0-...-ee161bb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 17 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

site2rss

Turns web pages that have no feed into RSS, Atom and JSON feeds. You describe where the items sit on the page with CSS selectors, site2rss polls the page and serves the result.

Quick start

go build -o site2rss .
./site2rss

Then point your reader at http://localhost:8080/ard/rss.

The first update runs immediately at startup; until it finishes the endpoints answer 503.

Configuration

Sites are defined in config.yaml:

sites:
  - name: "ARD"
    url: "https://www.ardmediathek.de/filme"
    title: "Die besten Filme in der ARD"
    description: "Die Filme der ARD im Überblick."
    selector:
      item: "div[itemType='https://schema.org/Movie']"
      link: "a[itemProp='url']::attr(href)"
      title: "h3::text"
      description: ""
      pagination: "a[href^='/filme-']::attr(href)"

name decides the URL path (lowercased), title and description become the feed metadata. Unknown fields are rejected, so a typo fails at startup instead of silently doing nothing.

Selectors

item selects one element per entry; link, title and description are evaluated inside each item. An empty selector leaves the field empty.

Selectors are CSS plus a pseudo element that says what to read from a match, borrowed from scrapy:

Selector Yields
h3::text the text of the match
h3 the same — text is what you get when nothing is said
a::attr(href) an attribute of the match
::attr(data-url) an attribute of the item element itself
div.card::attr(data-url) a link that is not an <a href>
time::attr(datetime) a date sitting in an attribute

title and description take the first match, link and pagination take all of them. Nothing is implied about which attribute a field wants: a link says ::attr(href) like everything else. An item whose link selector matches nothing is skipped; there is nothing for a reader to open.

Whitespace in extracted text is collapsed, HTML entities are decoded, and links are resolved against the page URL, so relative paths work. :has() and :not() are supported.

Pagination

pagination selects links to further pages of the same listing — typically what sits behind a "show more" button. Those pages are fetched too and their items appended.

The links are followed one level deep only, at most 10 pages, with 10 seconds between requests. Duplicates and links back to the start page are skipped.

      # follow ?page=2 … ?page=10, but not ?page=1, which repeats the start page
      pagination: "a[href*='?page=']:not([href$='page=1'])::attr(href)"
Pages built by JavaScript

site2rss does not run JavaScript. A page whose list is rendered in the browser has nothing for a css selector to match, but two other ways often work.

format: "json-ld" reads the schema.org ItemList that many pages embed for search engines, and which is usually in the initial html even when the visible list is not. Its field names are fixed by the standard (item.name, item.url, item.description), so it takes no selectors:

  - name: "Tele5"
    url: "https://tele5.de/filme"
    title: "Filme bei TELE 5"
    format: "json-ld"

format: "json" reads the JSON API the page loads its list from (find it in the browser's developer tools, network tab). The selectors become dotted paths: item leads to the array of entries, title and description are paths inside one entry, and link is a URL template filled from the entry:

  - name: "Rakuten"
    url: "https://gizmo.rakuten.tv/v3/lists/free-recently-added-…&contents%5Bper_page%5D=48"
    title: "Rakuten TV: Neue kostenlose Filme"
    format: "json"
    selector:
      item: "data.contents.data"
      link: "https://www.rakuten.tv/de/movies/{id}"
      title: "title"

An entry missing a template value is skipped. A response that is not JSON or lacks the list fails the update, so the previous feed stays. How many entries a JSON feed holds is up to the API; Rakuten takes it as per_page in the URL. Pagination is only supported for html pages.

Endpoints

Path Content
/<name>/rss RSS 2.0
/<name>/atom Atom
/<name>/json JSON Feed
/metrics Prometheus, incl. item_size{name="…"} per site

Options

Each flag has an environment variable; the flag wins.

Flag Env Default Meaning
-config CONFIG config.yaml config file
-cache CACHE cache cache directory
-cache-retention CACHE_RETENTION 2160h (90 days) how long items a site stopped listing are remembered
-interval INTERVAL 1h time between updates
-listen LISTEN :8080 listen address
-log-level LOG_LEVEL info debug logs every extracted item
-source-ip SOURCE_IP (kernel picks) address the requests go out from
Geoblocking

Some sites serve a different catalogue depending on where the request comes from. arte.tv is the clear case: films licensed for Germany and France only are missing from the page entirely when it is fetched from elsewhere, so there is nothing for a selector to match.

-source-ip picks which of the host's addresses the requests leave from. On a server with an additional address in the right country, that address is all it takes:

./site2rss -source-ip 203.0.113.10

The address has to exist on the host (ip -brief a); binding to one it does not hold fails every request. In Kubernetes the pod needs hostNetwork: true, since a pod's own namespace does not see the node's addresses.

How items get their date

Pages rarely say when an entry appeared, so site2rss remembers it. Every site has a cache/<Name>.json holding each item with the timestamp it was first seen and the time it was last listed. On the next run, anything whose link is already known keeps its original timestamp; everything else counts as new and sorts to the top.

Items the site stops listing leave the feed but stay in the cache for -cache-retention. Some sites, Joyn for example, drop entries from the page for a while and list them again later; within the retention such an item comes back with its old timestamp instead of being announced as new.

Two consequences worth knowing:

  • Delete the cache and every item looks new to your reader. Keep the directory across restarts.
  • Change a selector so links come out differently and the affected items are re-announced once.

Within one run, items are deduplicated by link and by title — some sites list the same entry under several URLs.

Being a good citizen

Sites are polled once per interval, pages of one site 10 seconds apart.

A page gets up to 5 attempts when the failure is one a retry can fix: a timeout, a refused connection, a 5xx, or a 429. Rate limits honour Retry-After plus a second of slack (arte.tv asks for a minute and is not exact about it), everything else waits 5 seconds. A 404 or a page that does not parse is not repeated — that would only cost time.

If a page still fails after that, the whole update for that site is abandoned and the previous feed stays served — better a feed that is an hour stale than one that silently lost half its entries and re-announces them later. The next attempt is the next regular cycle, one interval later.

Development

go test ./...

The tests run the selectors from config.yaml against stored copies of the sites in testdata/, so a site changing its markup shows up as a failing test rather than as an empty feed. No network needed.

When a site legitimately changes, refresh its fixture and update the expected counts in main_test.go:

curl -s https://www.ardmediathek.de/filme | gzip -9 > testdata/ARD.html.gz

A JSON source is stored as the API response, as testdata/<Name>.json.gz.

Docker

docker build -t site2rss .
docker run -p 8080:8080 \
  -v "$PWD/config.yaml:/config.yaml" \
  -v "$PWD/cache:/cache" \
  site2rss

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
internal
cache
Package cache keeps the items of a site between runs.
Package cache keeps the items of a site between runs.
config
Package config holds the site definitions site2rss works from.
Package config holds the site definitions site2rss works from.
feed
Package feed renders the items of a site and serves them.
Package feed renders the items of a site and serves them.
scrape
Package scrape turns a configured site into the items of its feed.
Package scrape turns a configured site into the items of its feed.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址