diff --git a/autoradio/autoradio.py b/autoradio/autoradio.py index a187692..b27d234 100644 --- a/autoradio/autoradio.py +++ b/autoradio/autoradio.py @@ -2,8 +2,10 @@ import feedparser import argparse import json +import pycurl import subprocess from pathlib import Path +import traceback def download_audio(link, destdir): @@ -13,9 +15,21 @@ def download_audio(link, destdir): if target.exists(): print("File already exists, skipping") else: - args = [ "wget", link, "-o", str(target) ] - print(f"downloading {link}") - subprocess.run(args) + 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, 300) + 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() diff --git a/poetry.lock b/poetry.lock index 0425be6..0296bbf 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,30 +1,43 @@ -# 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 = "*" -files = [ - {file = "sgmllib3k-1.0.0.tar.gz", hash = "sha256:7868fb1c8bfa764c1ac563d3cf369c381d1325d36124933a726f29fcdaa812e9"}, -] [metadata] -lock-version = "2.0" +lock-version = "1.1" python-versions = "^3.9" -content-hash = "b174a7eabcd92b902e7d7381cd453724319fb6563151d344f5011cc51efb3689" +content-hash = "2048ee9508f876635bc68e651540b23101da7469317226a7e86353c432292db6" + +[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 = [ + {file = "sgmllib3k-1.0.0.tar.gz", hash = "sha256:7868fb1c8bfa764c1ac563d3cf369c381d1325d36124933a726f29fcdaa812e9"}, +]