Created
April 12, 2013 13:34
-
-
Save LuRsT/5372033 to your computer and use it in GitHub Desktop.
Script to save .cue and .mp3 files from webpages, receives the url as first argument.
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
import sys | |
from bs4 import BeautifulSoup | |
import requests | |
import urllib | |
try: | |
r = requests.get(sys.argv[1]) | |
if r.status_code != 200: | |
exit('Page not found') | |
except: | |
raise | |
soup = BeautifulSoup(r.text) | |
links = soup.find_all('a') | |
for a in links: | |
href = a.get('href') | |
if href.endswith(('.mp3', '.cue')): | |
url = a.get('href') | |
print "Downloading: %s" % url | |
print "File output: %s\n" % urllib.unquote(url.split('/')[-1]) | |
print "Saving..." | |
file = requests.get(url) | |
output = open(urllib.unquote(url.split('/')[-1]), 'wb') | |
output.write(file.content) | |
output.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Requirements: