radio/scripts/test_feed.py
profit 3d635b742c Initial commit: self-hosted personal radio station
Flask + React web UI with audio player, podcast queue, feed management,
episode browser, music library, schedule viewer, and log tail.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 19:01:33 -07:00

57 lines
1.8 KiB
Python

#!/usr/bin/env python3
"""Test downloading from a specific RSS feed without affecting the database."""
import sys
import feedparser
def test_feed(url: str) -> None:
print(f"Fetching: {url}\n")
feed = feedparser.parse(url)
if feed.bozo and not feed.entries:
print(f"ERROR: Feed parse error: {feed.bozo_exception}")
sys.exit(1)
print(f"Feed title: {feed.feed.get('title', 'N/A')}")
print(f"Entries found: {len(feed.entries)}")
print()
for i, entry in enumerate(feed.entries[:5]):
print(f"--- Entry {i + 1} ---")
print(f" Title: {getattr(entry, 'title', 'N/A')}")
print(f" Published: {getattr(entry, 'published', 'N/A')}")
print(f" ID: {getattr(entry, 'id', 'N/A')}")
# Find audio
audio_url = None
for enc in getattr(entry, "enclosures", []):
etype = enc.get("type", "")
if etype.startswith("audio/"):
audio_url = enc.get("url") or enc.get("href")
print(f" Audio: {audio_url}")
print(f" Type: {etype}")
print(f" Length: {enc.get('length', 'N/A')} bytes")
break
if not audio_url:
for media in getattr(entry, "media_content", []):
if media.get("type", "").startswith("audio/"):
audio_url = media.get("url")
print(f" Audio: {audio_url}")
break
if not audio_url:
print(" Audio: (none found)")
print()
if __name__ == "__main__":
if len(sys.argv) < 2:
print(f"Usage: {sys.argv[0]} <rss-feed-url>")
print(f"Example: {sys.argv[0]} https://feeds.example.com/podcast.xml")
sys.exit(1)
test_feed(sys.argv[1])