Compare commits
2 Commits
b88427f05a
...
793b615278
Author | SHA1 | Date |
---|---|---|
Mike Lynch | 793b615278 | |
Mike Lynch | 8375051085 |
|
@ -0,0 +1,3 @@
|
||||||
|
# autoradio
|
||||||
|
|
||||||
|
Auto download of mp3s from podcast feeds using a little Python script.
|
|
@ -2,9 +2,23 @@
|
||||||
import feedparser
|
import feedparser
|
||||||
import argparse
|
import argparse
|
||||||
import json
|
import json
|
||||||
|
import subprocess
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
|
def download_audio(link, destdir):
|
||||||
|
parts = link.split('/')
|
||||||
|
ptarget = Path(destdir) / Path(parts[-1])
|
||||||
|
target = ptarget.resolve()
|
||||||
|
if target.exists():
|
||||||
|
print("File already exists, skipping")
|
||||||
|
else:
|
||||||
|
args = [ "wget", link, "-o", str(target) ]
|
||||||
|
print(f"downloading {link}")
|
||||||
|
subprocess.run(args)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def looks_audio(link):
|
def looks_audio(link):
|
||||||
if 'type' in link:
|
if 'type' in link:
|
||||||
return link['type'][:5] == 'audio'
|
return link['type'][:5] == 'audio'
|
||||||
|
@ -25,7 +39,9 @@ def get_latest(url, dir):
|
||||||
print("Multiple audio links")
|
print("Multiple audio links")
|
||||||
for s in sounds:
|
for s in sounds:
|
||||||
audio_url = s.get('href', '')
|
audio_url = s.get('href', '')
|
||||||
print(audio_url)
|
if audio_url:
|
||||||
|
return audio_url
|
||||||
|
return None
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
ap = argparse.ArgumentParser("autoradio - download audio from RSS feeds")
|
ap = argparse.ArgumentParser("autoradio - download audio from RSS feeds")
|
||||||
|
@ -38,8 +54,10 @@ def main():
|
||||||
args = ap.parse_args()
|
args = ap.parse_args()
|
||||||
with open(args.config, 'r') as cfh:
|
with open(args.config, 'r') as cfh:
|
||||||
cf = json.load(cfh)
|
cf = json.load(cfh)
|
||||||
for name, config in cf.items():
|
for name, config in cf['feeds'].items():
|
||||||
print(f"Checking {name}")
|
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'])
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
{
|
{
|
||||||
|
"feeds": {
|
||||||
"Utility Fog": {
|
"Utility Fog": {
|
||||||
"url": "https://www.frogworth.com/utilityfog/feed/",
|
"url": "https://www.frogworth.com/utilityfog/feed/",
|
||||||
"dir": "./Utility Fog"
|
"dir": "./output/UFog"
|
||||||
},
|
},
|
||||||
"RA Podcast": {
|
"RA Podcast": {
|
||||||
"url": "https://ra.co/xml/podcast.xml",
|
"url": "https://ra.co/xml/podcast.xml",
|
||||||
"dir": "./RA Podcast"
|
"dir": "./output/RA"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue