Compare commits
No commits in common. "cd37766dc2ea3b83e8e588c4112121221209ac77" and "d5a570295d3297b4a4cb877c13d774419730f09b" have entirely different histories.
cd37766dc2
...
d5a570295d
|
@ -4,7 +4,6 @@ import argparse
|
|||
import json
|
||||
import pycurl
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
import traceback
|
||||
|
||||
|
@ -14,7 +13,7 @@ def download_audio(link, destdir):
|
|||
ptarget = Path(destdir) / Path(parts[-1])
|
||||
target = ptarget.resolve()
|
||||
if target.exists():
|
||||
print(f"File {target} already downloaded, skipping")
|
||||
print("File already exists, skipping")
|
||||
else:
|
||||
with open(target, "wb") as fp:
|
||||
curl = pycurl.Curl()
|
||||
|
@ -22,7 +21,7 @@ def download_audio(link, destdir):
|
|||
curl.setopt(pycurl.FOLLOWLOCATION, 1)
|
||||
curl.setopt(pycurl.MAXREDIRS, 5)
|
||||
curl.setopt(pycurl.CONNECTTIMEOUT, 30)
|
||||
curl.setopt(pycurl.TIMEOUT, 3000)
|
||||
curl.setopt(pycurl.TIMEOUT, 300)
|
||||
curl.setopt(pycurl.NOSIGNAL, 1)
|
||||
curl.setopt(pycurl.WRITEDATA, fp)
|
||||
try:
|
||||
|
@ -40,14 +39,14 @@ def looks_audio(link):
|
|||
return False
|
||||
|
||||
|
||||
def get_latest(url, dir, max):
|
||||
def get_latest(url, dir):
|
||||
d = feedparser.parse(url)
|
||||
title = d.feed.get('title', "[no title]")
|
||||
entries = d.get('entries', [])
|
||||
urls = []
|
||||
for entry in entries[:max]:
|
||||
if 'links' in entry:
|
||||
sounds = [ l for l in entry['links'] if looks_audio(l) ]
|
||||
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:
|
||||
|
@ -55,8 +54,8 @@ def get_latest(url, dir, max):
|
|||
for s in sounds:
|
||||
audio_url = s.get('href', '')
|
||||
if audio_url:
|
||||
urls.append(audio_url)
|
||||
return urls
|
||||
return audio_url
|
||||
return None
|
||||
|
||||
def main():
|
||||
ap = argparse.ArgumentParser("autoradio - download audio from RSS feeds")
|
||||
|
@ -69,11 +68,10 @@ def main():
|
|||
args = ap.parse_args()
|
||||
with open(args.config, 'r') as cfh:
|
||||
cf = json.load(cfh)
|
||||
m = int(cf.get("max", "5"))
|
||||
for name, config in cf['feeds'].items():
|
||||
print(f"Checking {name}")
|
||||
urls = get_latest(config['url'], config['dir'], m)
|
||||
for url in urls:
|
||||
url = get_latest(config['url'], config['dir'])
|
||||
if url:
|
||||
print(f"content = {url}")
|
||||
download_audio(url, config['dir'])
|
||||
|
||||
|
|
|
@ -2,12 +2,11 @@
|
|||
"feeds": {
|
||||
"Utility Fog": {
|
||||
"url": "https://www.frogworth.com/utilityfog/feed/",
|
||||
"dir": "/media/pi/Storage/Music/Utility Fog"
|
||||
"dir": "./output/UFog"
|
||||
},
|
||||
"RA Podcast": {
|
||||
"url": "https://ra.co/xml/podcast.xml",
|
||||
"dir": "/media/pi/Storage/Music/RA_Podcast"
|
||||
"dir": "./output/RA"
|
||||
}
|
||||
},
|
||||
"max": 10
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,7 +6,7 @@ authors = ["Mike Lynch <m.lynch@sydney.edu.au>"]
|
|||
readme = "README.md"
|
||||
|
||||
[tool.poetry.dependencies]
|
||||
python = "^3.7"
|
||||
python = "^3.9"
|
||||
feedparser = "^6.0.10"
|
||||
|
||||
[tool.poetry.scripts]
|
||||
|
|
Loading…
Reference in New Issue