Files
lisael-box/tower/lisael_refresh.py
Clément Saillant ec2dd3f24f feat(tower): cap shows at latest N per feed
The additive refresh accumulated episodes without bound (Oli reached 13).
Tag each manifest episode with a source (auto/pick/upload); the refresh now
prunes "auto" episodes that aged out of the feed's latest N while keeping
hand-picked and uploaded ones. Feeds default to N=5.
2026-06-15 08:40:43 +02:00

41 lines
1.5 KiB
Python

#!/usr/bin/env python3
"""Weekly refresh: for each configured feed, keep the latest N episodes staged.
Adds the new ones (src=auto) and prunes auto episodes that aged out of the feed's
latest N. Hand-picked ('pick') and uploaded ('upload') episodes are never touched."""
import lisael_content as C
def main():
added = removed = 0
for fd in C.load_feeds():
key, show, rss, n = fd["key"], fd["name"], fd["rss"], int(fd.get("n", 5))
try:
eps, cov = C.fetch_episodes(rss, limit=n)
except Exception as e:
print("RSS fail", key, e, flush=True); continue
cover_bytes = None
if cov:
try:
cover_bytes = C.fetch(cov)
except Exception:
cover_bytes = None
staged = set(C.staging_files())
want = set()
for ep in eps:
fn = C.episode_fname(key, ep["url"])
want.add(fn)
if fn in staged:
continue
try:
C.add_episode(key, show, cover_bytes, ep["url"], ep["title"])
cover_bytes = None # cover only needs writing once per show
added += 1
print("added", fn, flush=True)
except Exception as e:
print("add fail", key, e, flush=True)
# Cap: drop auto episodes that are no longer in the feed's latest N.
removed += C.prune_show(show, want)
print(f"refresh done: +{added} -{removed}, {len(C.staging_files())} files", flush=True)
if __name__ == "__main__":
main()