Skip to content

Instantly share code, notes, and snippets.

@zachreizner
Created October 15, 2015 19:58
Show Gist options
  • Save zachreizner/4e0a26bd44e8a658e40b to your computer and use it in GitHub Desktop.
Save zachreizner/4e0a26bd44e8a658e40b to your computer and use it in GitHub Desktop.
Plays all MP3 files linked on a page
from subprocess import Popen, DEVNULL
from urllib.request import urlopen
from bs4 import BeautifulSoup
BASE_URL = 'http://example.com/Album%20Name/'
html_doc = urlopen(BASE_URL)
soup = BeautifulSoup(html_doc, 'html.parser')
urls = []
for link in soup.find_all('a'):
href = link.get('href')
if href.endswith('.mp3'):
urls.append(BASE_URL + href)
for url in urls:
print(url)
cmd = ['/usr/bin/mpv']
cmd.extend(urls)
Popen(cmd, stdin=DEVNULL, stdout=DEVNULL, stderr=DEVNULL)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment