From fe7279ab47a25d5bb8a6c4aea6e55397c74a6c31 Mon Sep 17 00:00:00 2001 From: GuanFoxyier <1372851437@qq.com> Date: Mon, 17 Jun 2019 10:16:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=85=B7=E7=8B=97=E9=9F=B3?= =?UTF-8?q?=E4=B9=90=E6=97=A0=E6=B3=95=E4=B8=8B=E8=BD=BD=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/you_get/extractors/kugou.py | 77 ++++++++++++++++++--------------- 1 file changed, 41 insertions(+), 36 deletions(-) diff --git a/src/you_get/extractors/kugou.py b/src/you_get/extractors/kugou.py index a98daac6..192bd809 100644 --- a/src/you_get/extractors/kugou.py +++ b/src/you_get/extractors/kugou.py @@ -8,66 +8,72 @@ from base64 import b64decode import re import hashlib + def kugou_download(url, output_dir=".", merge=True, info_only=False, **kwargs): - if url.lower().find("5sing")!=-1: - #for 5sing.kugou.com - html=get_html(url) - ticket=r1(r'"ticket":\s*"(.*)"',html) - j=loads(str(b64decode(ticket),encoding="utf-8")) - url=j['file'] - title=j['songName'] + if url.lower().find("5sing") != -1: + # for 5sing.kugou.com + html = get_html(url) + ticket = r1(r'"ticket":\s*"(.*)"', html) + j = loads(str(b64decode(ticket), encoding="utf-8")) + url = j['file'] + title = j['songName'] songtype, ext, size = url_info(url) print_info(site_info, title, songtype, size) if not info_only: download_urls([url], title, ext, size, output_dir, merge=merge) - elif url.lower().find("hash")!=-1: - return kugou_download_by_hash(url,output_dir,merge,info_only) + elif url.lower().find("hash") != -1: + return kugou_download_by_hash(url, output_dir, merge, info_only) else: - #for the www.kugou.com/ + # for the www.kugou.com/ return kugou_download_playlist(url, output_dir=output_dir, merge=merge, info_only=info_only) # raise NotImplementedError(url) -def kugou_download_by_hash(url,output_dir = '.', merge = True, info_only = False): - #sample - #url_sample:http://www.kugou.com/song/#hash=93F7D2FC6E95424739448218B591AEAF&album_id=9019462 - hash_val = match1(url,'hash=(\w+)') - album_id = match1(url,'album_id=(\d+)') - html = get_html("http://www.kugou.com/yy/index.php?r=play/getdata&hash={}&album_id={}".format(hash_val,album_id)) - j =loads(html) +def kugou_download_by_hash(url, output_dir='.', merge=True, info_only=False): + # sample + # url_sample:http://www.kugou.com/song/#hash=93F7D2FC6E95424739448218B591AEAF&album_id=9019462 + hash_val = match1(url, 'hash=(\w+)') + album_id = match1(url, 'album_id=(\d+)') + if not album_id: + album_id = 123 + html = get_html("http://www.kugou.com/yy/index.php?r=play/getdata&hash={}&album_id={}&mid=123".format(hash_val, album_id)) + j = loads(html) url = j['data']['play_url'] title = j['data']['audio_name'] # some songs cann't play because of copyright protection - if(url == ''): + if (url == ''): return songtype, ext, size = url_info(url) print_info(site_info, title, songtype, size) if not info_only: download_urls([url], title, ext, size, output_dir, merge=merge) -def kugou_download_playlist(url, output_dir = '.', merge = True, info_only = False, **kwargs): - urls=[] - - #download music leaderboard - #sample: http://www.kugou.com/yy/html/rank.html - if url.lower().find('rank') !=-1: - html=get_html(url) + +def kugou_download_playlist(url, output_dir='.', merge=True, info_only=False, **kwargs): + urls = [] + + # download music leaderboard + # sample: http://www.kugou.com/yy/html/rank.html + if url.lower().find('rank') != -1: + html = get_html(url) pattern = re.compile('