Created
November 23, 2015 13:40
-
-
Save liuyu81/869b77f4b72333424634 to your computer and use it in GitHub Desktop.
QQ Music Downloader
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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import os | |
import requests | |
import sys | |
import time | |
from lxml import etree | |
def main(args): | |
PREFIX = "music" | |
tree = etree.parse(sys.stdin, etree.HTMLParser()) | |
for i, music in enumerate(tree.xpath("//qqmusic"), 1): | |
name = music.get("music_name") | |
singer, sep, album = music.get("singer").partition(" - ") | |
uri = music.get("audiourl") | |
print(i, name, singer, uri) | |
response = requests.get(uri) | |
filename = "{0}({1}).m4a".format(name, singer) | |
with open(os.path.join(PREFIX, filename), "wb") as f: | |
f.write(response.content) | |
f.flush() | |
time.sleep(0.5) | |
return os.EX_OK | |
if __name__ == '__main__': | |
sys.exit(main(sys.argv[:])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how to install and how to use this can you write me?