From 2827390214a6382067d5cfd2dda71044744a462d Mon Sep 17 00:00:00 2001 From: Mike Lynch Date: Tue, 3 Oct 2023 10:16:39 +1100 Subject: [PATCH] Basic feed parsing for URLs to download works --- autoradio/autoradio.py | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/autoradio/autoradio.py b/autoradio/autoradio.py index 52f886f..817af8c 100644 --- a/autoradio/autoradio.py +++ b/autoradio/autoradio.py @@ -4,6 +4,29 @@ import argparse import json from pathlib import Path + +def looks_audio(link): + if 'type' in link: + return link['type'][:5] == 'audio' + return False + + +def get_latest(url, dir): + d = feedparser.parse(url) + title = d.feed.get('title', "[no title]") + entries = d.get('entries', []) + if entries: + latest = entries[0] + if 'links' in latest: + sounds = [ l for l in latest['links'] if looks_audio(l) ] + if len(sounds) < 0: + print("No audio links") + if len(sounds) > 1: + print("Multiple audio links") + for s in sounds: + audio_url = s.get('href', '') + print(audio_url) + def main(): ap = argparse.ArgumentParser("autoradio - download audio from RSS feeds") ap.add_argument( @@ -15,6 +38,8 @@ def main(): args = ap.parse_args() with open(args.config, 'r') as cfh: cf = json.load(cfh) - print(cf) + for name, config in cf.items(): + print(f"Checking {name}") + get_latest(config['url'], config['dir'])