Compare commits
No commits in common. "9989e5f4c87e11bba787fca4ad458fee0e9225e3" and "793b615278bf47c4539df1e7a741baddf0c3e40a" have entirely different histories.
9989e5f4c8
...
793b615278
|
@ -1,9 +1,3 @@
|
|||
# autoradio
|
||||
|
||||
Auto download of mp3s from podcast feeds using a little Python script.
|
||||
|
||||
## Installation
|
||||
|
||||
I haven't worked out how to intall pycurl with poetry, as it looks like it
|
||||
required a command-line flag to specify the SSL backend, and poetry doesn't
|
||||
seem to support that. So for my local install I pip installed it by hand
|
|
@ -2,11 +2,8 @@
|
|||
import feedparser
|
||||
import argparse
|
||||
import json
|
||||
import pycurl
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
import traceback
|
||||
|
||||
|
||||
def download_audio(link, destdir):
|
||||
|
@ -14,23 +11,11 @@ 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()
|
||||
curl.setopt(pycurl.URL, link)
|
||||
curl.setopt(pycurl.FOLLOWLOCATION, 1)
|
||||
curl.setopt(pycurl.MAXREDIRS, 5)
|
||||
curl.setopt(pycurl.CONNECTTIMEOUT, 30)
|
||||
curl.setopt(pycurl.TIMEOUT, 3000)
|
||||
curl.setopt(pycurl.NOSIGNAL, 1)
|
||||
curl.setopt(pycurl.WRITEDATA, fp)
|
||||
try:
|
||||
curl.perform()
|
||||
except:
|
||||
traceback.print_exc(file=sys.stderr)
|
||||
sys.stderr.flush()
|
||||
curl.close()
|
||||
args = [ "wget", link, "-o", str(target) ]
|
||||
print(f"downloading {link}")
|
||||
subprocess.run(args)
|
||||
|
||||
|
||||
|
||||
|
@ -40,14 +25,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 +40,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 +54,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
|
||||
}
|
|
@ -1,43 +1,30 @@
|
|||
# This file is automatically @generated by Poetry 1.5.0 and should not be changed by hand.
|
||||
|
||||
[[package]]
|
||||
name = "feedparser"
|
||||
version = "6.0.10"
|
||||
description = "Universal feed parser, handles RSS 0.9x, RSS 1.0, RSS 2.0, CDF, Atom 0.3, and Atom 1.0 feeds"
|
||||
category = "main"
|
||||
optional = false
|
||||
python-versions = ">=3.6"
|
||||
files = [
|
||||
{file = "feedparser-6.0.10-py3-none-any.whl", hash = "sha256:79c257d526d13b944e965f6095700587f27388e50ea16fd245babe4dfae7024f"},
|
||||
{file = "feedparser-6.0.10.tar.gz", hash = "sha256:27da485f4637ce7163cdeab13a80312b93b7d0c1b775bef4a47629a3110bca51"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
sgmllib3k = "*"
|
||||
|
||||
[[package]]
|
||||
name = "pycurl"
|
||||
version = "7.45.2"
|
||||
description = "PycURL -- A Python Interface To The cURL library"
|
||||
category = "main"
|
||||
optional = false
|
||||
python-versions = ">=3.5"
|
||||
|
||||
[[package]]
|
||||
name = "sgmllib3k"
|
||||
version = "1.0.0"
|
||||
description = "Py3k port of sgmllib."
|
||||
category = "main"
|
||||
optional = false
|
||||
python-versions = "*"
|
||||
|
||||
[metadata]
|
||||
lock-version = "1.1"
|
||||
python-versions = "^3.7"
|
||||
content-hash = "049581a37f61f8307815a597cf5decff839acd1d72a6dd0570ee65b006075794"
|
||||
|
||||
[metadata.files]
|
||||
feedparser = [
|
||||
{file = "feedparser-6.0.10-py3-none-any.whl", hash = "sha256:79c257d526d13b944e965f6095700587f27388e50ea16fd245babe4dfae7024f"},
|
||||
{file = "feedparser-6.0.10.tar.gz", hash = "sha256:27da485f4637ce7163cdeab13a80312b93b7d0c1b775bef4a47629a3110bca51"},
|
||||
]
|
||||
pycurl = [
|
||||
{file = "pycurl-7.45.2.tar.gz", hash = "sha256:5730590be0271364a5bddd9e245c9cc0fb710c4cbacbdd95264a3122d23224ca"},
|
||||
]
|
||||
sgmllib3k = [
|
||||
files = [
|
||||
{file = "sgmllib3k-1.0.0.tar.gz", hash = "sha256:7868fb1c8bfa764c1ac563d3cf369c381d1325d36124933a726f29fcdaa812e9"},
|
||||
]
|
||||
|
||||
[metadata]
|
||||
lock-version = "2.0"
|
||||
python-versions = "^3.9"
|
||||
content-hash = "b174a7eabcd92b902e7d7381cd453724319fb6563151d344f5011cc51efb3689"
|
||||
|
|
|
@ -6,9 +6,8 @@ authors = ["Mike Lynch <m.lynch@sydney.edu.au>"]
|
|||
readme = "README.md"
|
||||
|
||||
[tool.poetry.dependencies]
|
||||
python = "^3.7"
|
||||
python = "^3.9"
|
||||
feedparser = "^6.0.10"
|
||||
pycurl = "^7.45.2"
|
||||
|
||||
[tool.poetry.scripts]
|
||||
autoradio = "autoradio.autoradio:main"
|
||||
|
|
Loading…
Reference in New Issue