Basic feed parsing for URLs to download works
parent
a2414cb3a3
commit
2827390214
|
@ -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'])
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue