Download Home Practice Program MP3 Files (and save them for later) with this Python Program

If you participate in Home Practice Programs with Shinzen Young (or other teachers), afterwards you will receive an email which usually looks something like that:

If you follow that link, you will be redirected to the corresponding recording on You can then start the recording from that webpage and listen to the program.

However, what if you want to download the recording, so you can save it for a future time and/or add to it your personal archive of Home Practice Programs?
I wrote a little Python Script with which you can do that.

import urllib
from bs4 import BeautifulSoup
from urllib.request import urlopen
import shutil
import re
from urllib.request import urlopen

link = input('Please paste link:')
html_page1 = urlopen(link)
soup_page1 = BeautifulSoup(html_page1, 'html.parser')

html_page2 = urlopen(soup_page1.find('meta', {'name':'twitter:player'})['content'])
soup_page2 = BeautifulSoup(html_page2, 'html.parser')

js_mess = soup_page2.find('script', {'type':'text/javascript'}).contents[0]#.lstrip('//<![CDATA[\n').rstrip('\n //]]>')

mp3_link = re.findall("https.*mp3", js_mess)[0]

file_name = input('Please name file (just the name; w/o .mp3):') + ".mp3"

with urllib.request.urlopen(mp3_link) as response, open(file_name, 'wb') as out_file:
    shutil.copyfileobj(response, out_file)

# Move the file from your python project folder to your HomePracticeProgram folder
old_path = "/Users/exampleuser/examplefolder1/examplefolder2/" + file_name
new_path = "/Users/exampleuser/examplefolder1/HomePracticeProgram/" + file_name

shutil.move(old_path, new_path)


Leave a Comment

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s