import json, requests
from pathlib import Path
from os.path import exists
URL = "https://madattheinternet.libsyn.com/website/page/{:d}/render-type/json"
# arbitrary range
for i in range(1, 99):
response = requests.get(URL.format(i))
j = response.json()
if j is None:
print("Nothing else found, exiting")
exit(0)
for x in j:
audio_url = x["primary_content"]["url_secure"]
image_url = x["image_url"]
# just use the url for the filename
audio_file = audio_url.split("/")[-1]
print("Downloading content for: " + x["item_title"] + " - " + x["release_date"])
if exists(audio_file) == True:
print("skipping")
else:
# Save audio
ra = requests.get(audio_url, allow_redirects=True)
with open(audio_file, 'wb') as file:
file.write(ra.content)
# Save thumbnail
ri = requests.get(image_url, allow_redirects=True)
# I don't know what I'm doing
with open(Path(audio_file).stem + Path(ri.url.split("/")[-1]).suffix, 'wb') as file:
file.write(ri.content)
# Save json object for episode
with open(Path(audio_file).stem + ".json", 'w') as file:
file.write(json.dumps(x, indent=4))