Created
September 11, 2013 12:17
-
-
Save scturtle/6522746 to your computer and use it in GitHub Desktop.
download music from baidu music
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 re | |
import requests | |
URL = 'http://musicmini.baidu.com/app/link/getLinks.php?linkType=1&isLogin=1&isHq=1&songId={}' | |
ALBUM = 'http://music.baidu.com/album/{}' | |
def get_song(sid): | |
data = requests.get(URL.format(sid)).json()[0] | |
flac, mp3, mp3kbps = None, None, 0 | |
for f in data['file_list']: | |
if f['format'] == 'flac': | |
flac = f['display_url'] | |
elif f['kbps'] > mp3kbps: | |
mp3kbps = f['kbps'] | |
mp3 = f['display_url'] | |
return {'title': data['song_title'].encode('utf-8'), | |
'lyric': data['lyric_url'], | |
'flac': flac, 'mp3': mp3} | |
def get_album_sids(aid): | |
text = requests.get(ALBUM.format(aid)).text | |
return re.findall(r'sid\': \'(\d+)', text) | |
if __name__ == '__main__': | |
sids = get_album_sids(197096) | |
for t in map(get_song, sids): | |
print t |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment