From 83750510851b39ef94b90ecc8f82b6b45bb27bb9 Mon Sep 17 00:00:00 2001 From: Mike Lynch Date: Sat, 21 Oct 2023 09:51:52 +1100 Subject: [PATCH] Actually downloads things --- README.md | 3 +++ autoradio/autoradio.py | 23 +++++++++++++++++++---- config.json | 16 +++++++++------- 3 files changed, 31 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index e69de29..33d0ff0 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,3 @@ +# autoradio + +Auto download of mp3s from podcast feeds using a little Python script. \ No newline at end of file diff --git a/autoradio/autoradio.py b/autoradio/autoradio.py index 817af8c..3be9d37 100644 --- a/autoradio/autoradio.py +++ b/autoradio/autoradio.py @@ -2,9 +2,20 @@ import feedparser import argparse import json +import subprocess from pathlib import Path +def download_audio(link, destdir): + parts = link.split('/') + ptarget = Path(destdir) / Path(parts[-1]) + target = str(ptarget.resolve()) + args = [ "wget", link, "-o", target ] + print(f"downloading {link} to {target}") + subprocess.run(args) + + + def looks_audio(link): if 'type' in link: return link['type'][:5] == 'audio' @@ -25,7 +36,9 @@ def get_latest(url, dir): print("Multiple audio links") for s in sounds: audio_url = s.get('href', '') - print(audio_url) + if audio_url: + return audio_url + return None def main(): ap = argparse.ArgumentParser("autoradio - download audio from RSS feeds") @@ -38,8 +51,10 @@ def main(): args = ap.parse_args() with open(args.config, 'r') as cfh: cf = json.load(cfh) - for name, config in cf.items(): + for name, config in cf['feeds'].items(): print(f"Checking {name}") - get_latest(config['url'], config['dir']) - + url = get_latest(config['url'], config['dir']) + if url: + print(f"content = {url}") + download_audio(url, config['dir']) diff --git a/config.json b/config.json index f812459..4584929 100644 --- a/config.json +++ b/config.json @@ -1,10 +1,12 @@ { - "Utility Fog": { - "url": "https://www.frogworth.com/utilityfog/feed/", - "dir": "./Utility Fog" - }, - "RA Podcast": { - "url": "https://ra.co/xml/podcast.xml", - "dir": "./RA Podcast" + "feeds": { + "Utility Fog": { + "url": "https://www.frogworth.com/utilityfog/feed/", + "dir": "./output/UFog" + }, + "RA Podcast": { + "url": "https://ra.co/xml/podcast.xml", + "dir": "./output/RA" + } } } \ No newline at end of file