get flac
#!/usr/bin/env python # coding=utf-8 import sys import json import os def curl(url): c = '\'' command = 'curl ' + c + url +c output = os.popen(command) output = output.read() return output def download(url, music_name): c = '\'' command = 'aria2c ' + c + url + c + ' -o ' + c + music_name + c + ' -d ~/Music' os.system(command) def get_value(str, substr): index = str.find(substr) str = str[index+len(substr)+1:] index = str.find('\n') value = str[0:index] return value def get_musics_info(music_name): url = "http://search.kuwo.cn/r.s?client=kt&all={name}&pn=0&rn=10&uid=221260053&ver=kwplayer_ar_99.99.99.99&vipver=1&ft=music&cluster=0&strategy=2012&encoding=utf8&rformat=json&vermerge=1&mobi=1".format(name=music_name) output = curl(url) return output def get_music_info(music_id): url = "http://api.ly93.cc/kw.php?id={id}&ext=flac&rate=2000".format(id=music_id) output = curl(url) result = json.loads(output) url = result.get("url") return url def get_music_link(url): output = curl(url) url = get_value(output, "url") return url def download_music(music_name): output_s = get_musics_info(music_name) output_d = json.loads(output_s) musics = output_d.get("abslist") print("Number Name ARTIST ALBUM ") for i in range(len(musics)): music = musics[i] print("%d %s %s %s" % (i+1, music.get("SONGNAME"), music.get("ARTIST"), music.get("ALBUM"))) index = input("Please select the serial number of the song you want to download\n") music = musics[int(index) -1] music_id = music.get("MUSICRID")[6:] url = get_music_info(music_id) music_link = get_music_link(url) type = music_link.split('.')[-1] music_name = music.get("ARTIST") + '-' + music.get("SONGNAME") + '.' + type download(music_link, music_name) if __name__ == "__main__": if(len(sys.argv) <2): print("Usage: %s Music_Name" % (sys.argv[0])) exit(1) for i in range(1, len(sys.argv)): download_music(sys.argv[i])