Created
March 18, 2019 00:55
-
-
Save maxcohn/45cee49211e101a406e2ddb18070c3ed to your computer and use it in GitHub Desktop.
Downloads episodes of PKN from the PKA Podbean account. Update 'numOfEps' when new episodes come out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# download all pkn episodes from podbean | |
from bs4 import BeautifulSoup | |
import requests | |
# download function (this is a super useful function in general) | |
def download(url, file_name): | |
# open in binary mode | |
with open(file_name, "wb") as file: | |
# get request | |
response = requests.get(url) | |
# write to file | |
file.write(response.content) | |
# number of episode of PKN | |
numOfEps = 227 | |
for i in range(1,numOfEps + 1): | |
# I know this looks weird, but the way podbean works is: | |
# There is a url that follows a template: https://painkilleralready.podbean.com/e/pkn-{i} | |
# where i = episode number | |
# | |
# There is a downlaod button on that page that redirects to the page with the real download button. | |
# | |
# This page has no standard, and neither do the direct urls, so we have to scrape two pages to get | |
# the actual download url, and then download it | |
# url of podbean page (there is a standard, so we can follow that) | |
url = f"https://painkilleralready.podbean.com/e/pkn-{i}/" | |
# download podbean page so we can get the download page url (stored in <a> with class 'post_toolbar_download') | |
url = BeautifulSoup(requests.get(url).content, "html.parser").find(class_="post_toolbar_download")["href"] | |
# get the actual download url (stored in <a> with class 'download-btn') | |
dl_url = BeautifulSoup(requests.get(url).content, "html.parser").find(class_="download-btn")["href"] | |
# create new file name | |
name = f"PKN {i:03}.mp3" | |
# download episode from dl_url | |
print(f"Downloading episode: {i}", flush=True) | |
download(dl_url, name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment