Created
August 15, 2014 06:06
-
-
Save HybridEidolon/f19dcba60a601a94a18c to your computer and use it in GitHub Desktop.
KH-Insider Music Album Downloader (Python 3)
This file contains hidden or 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
#!/usr/bin/env python2 | |
import requests as req | |
import sys | |
import lxml.html as html | |
import lxml.etree as etree | |
import re | |
# grab page from args | |
doc = html.parse('http://downloads.khinsider.com/game-soundtracks/album/' + sys.argv[1]) | |
doc = doc.getroot() | |
links = doc.xpath('//a') | |
urls = [] | |
for l in links: | |
if l.get('href').endswith('.mp3') and l.text == 'Download': | |
urls.append(l.get('href')) | |
for u in urls: | |
doc = html.parse(u) | |
links = doc.xpath('//a') | |
for l in links: | |
if l.text == 'Click here to download': | |
f = req.get(l.get('href'), stream=True) | |
fname = re.match(r'.*/(.*\.mp3)', u).group(1) | |
with open(fname, 'wb') as h: | |
for b in f.iter_content(1024): | |
if not b: | |
break | |
h.write(b) | |
This file contains hidden or 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
argparse==1.2.1 | |
requests==2.3.0 | |
wsgiref==0.1.2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment