Skip to content

Instantly share code, notes, and snippets.

@HybridEidolon
Created August 15, 2014 06:06
Show Gist options
  • Save HybridEidolon/f19dcba60a601a94a18c to your computer and use it in GitHub Desktop.
Save HybridEidolon/f19dcba60a601a94a18c to your computer and use it in GitHub Desktop.
KH-Insider Music Album Downloader (Python 3)
#!/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)
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