mirror of
https://github.com/soimort/you-get.git
synced 2025-01-24 05:55:02 +03:00
修复酷狗音乐无法下载问题
This commit is contained in:
parent
c3ef3740f3
commit
fe7279ab47
@ -8,66 +8,72 @@ from base64 import b64decode
|
|||||||
import re
|
import re
|
||||||
import hashlib
|
import hashlib
|
||||||
|
|
||||||
|
|
||||||
def kugou_download(url, output_dir=".", merge=True, info_only=False, **kwargs):
|
def kugou_download(url, output_dir=".", merge=True, info_only=False, **kwargs):
|
||||||
if url.lower().find("5sing")!=-1:
|
if url.lower().find("5sing") != -1:
|
||||||
#for 5sing.kugou.com
|
# for 5sing.kugou.com
|
||||||
html=get_html(url)
|
html = get_html(url)
|
||||||
ticket=r1(r'"ticket":\s*"(.*)"',html)
|
ticket = r1(r'"ticket":\s*"(.*)"', html)
|
||||||
j=loads(str(b64decode(ticket),encoding="utf-8"))
|
j = loads(str(b64decode(ticket), encoding="utf-8"))
|
||||||
url=j['file']
|
url = j['file']
|
||||||
title=j['songName']
|
title = j['songName']
|
||||||
songtype, ext, size = url_info(url)
|
songtype, ext, size = url_info(url)
|
||||||
print_info(site_info, title, songtype, size)
|
print_info(site_info, title, songtype, size)
|
||||||
if not info_only:
|
if not info_only:
|
||||||
download_urls([url], title, ext, size, output_dir, merge=merge)
|
download_urls([url], title, ext, size, output_dir, merge=merge)
|
||||||
elif url.lower().find("hash")!=-1:
|
elif url.lower().find("hash") != -1:
|
||||||
return kugou_download_by_hash(url,output_dir,merge,info_only)
|
return kugou_download_by_hash(url, output_dir, merge, info_only)
|
||||||
else:
|
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)
|
return kugou_download_playlist(url, output_dir=output_dir, merge=merge, info_only=info_only)
|
||||||
# raise NotImplementedError(url)
|
# raise NotImplementedError(url)
|
||||||
|
|
||||||
|
|
||||||
def kugou_download_by_hash(url,output_dir = '.', merge = True, info_only = False):
|
def kugou_download_by_hash(url, output_dir='.', merge=True, info_only=False):
|
||||||
#sample
|
# sample
|
||||||
#url_sample:http://www.kugou.com/song/#hash=93F7D2FC6E95424739448218B591AEAF&album_id=9019462
|
# url_sample:http://www.kugou.com/song/#hash=93F7D2FC6E95424739448218B591AEAF&album_id=9019462
|
||||||
hash_val = match1(url,'hash=(\w+)')
|
hash_val = match1(url, 'hash=(\w+)')
|
||||||
album_id = match1(url,'album_id=(\d+)')
|
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))
|
if not album_id:
|
||||||
j =loads(html)
|
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']
|
url = j['data']['play_url']
|
||||||
title = j['data']['audio_name']
|
title = j['data']['audio_name']
|
||||||
# some songs cann't play because of copyright protection
|
# some songs cann't play because of copyright protection
|
||||||
if(url == ''):
|
if (url == ''):
|
||||||
return
|
return
|
||||||
songtype, ext, size = url_info(url)
|
songtype, ext, size = url_info(url)
|
||||||
print_info(site_info, title, songtype, size)
|
print_info(site_info, title, songtype, size)
|
||||||
if not info_only:
|
if not info_only:
|
||||||
download_urls([url], title, ext, size, output_dir, merge=merge)
|
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
|
def kugou_download_playlist(url, output_dir='.', merge=True, info_only=False, **kwargs):
|
||||||
#sample: http://www.kugou.com/yy/html/rank.html
|
urls = []
|
||||||
if url.lower().find('rank') !=-1:
|
|
||||||
html=get_html(url)
|
# 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('<a href="(http://.*?)" data-active=')
|
pattern = re.compile('<a href="(http://.*?)" data-active=')
|
||||||
res = pattern.findall(html)
|
res = pattern.findall(html)
|
||||||
for song in res:
|
for song in res:
|
||||||
res = get_html(song)
|
res = get_html(song)
|
||||||
pattern_url = re.compile('"hash":"(\w+)".*"album_id":(\d)+')
|
pattern_url = re.compile('"hash":"(\w+)".*"album_id":(\d)+')
|
||||||
hash_val,album_id= res = pattern_url.findall(res)[0]
|
hash_val, album_id = res = pattern_url.findall(res)[0]
|
||||||
urls.append('http://www.kugou.com/song/#hash=%s&album_id=%s'%(hash_val,album_id))
|
if not album_id:
|
||||||
|
album_id = 123
|
||||||
|
urls.append('http://www.kugou.com/song/#hash=%s&album_id=%s' % (hash_val, album_id))
|
||||||
|
|
||||||
# download album
|
# download album
|
||||||
# album sample: http://www.kugou.com/yy/album/single/1645030.html
|
# album sample: http://www.kugou.com/yy/album/single/1645030.html
|
||||||
elif url.lower().find('album')!=-1:
|
elif url.lower().find('album') != -1:
|
||||||
html = get_html(url)
|
html = get_html(url)
|
||||||
pattern = re.compile('var data=(\[.*?\]);')
|
pattern = re.compile('var data=(\[.*?\]);')
|
||||||
res = pattern.findall(html)[0]
|
res = pattern.findall(html)[0]
|
||||||
for v in json.loads(res):
|
for v in json.loads(res):
|
||||||
urls.append('http://www.kugou.com/song/#hash=%s&album_id=%s'%(v['hash'],v['album_id']))
|
urls.append('http://www.kugou.com/song/#hash=%s&album_id=%s' % (v['hash'], v['album_id']))
|
||||||
|
|
||||||
# download the playlist
|
# download the playlist
|
||||||
# playlist sample:http://www.kugou.com/yy/special/single/487279.html
|
# playlist sample:http://www.kugou.com/yy/special/single/487279.html
|
||||||
@ -75,16 +81,15 @@ def kugou_download_playlist(url, output_dir = '.', merge = True, info_only = Fal
|
|||||||
html = get_html(url)
|
html = get_html(url)
|
||||||
pattern = re.compile('data="(\w+)\|(\d+)"')
|
pattern = re.compile('data="(\w+)\|(\d+)"')
|
||||||
for v in pattern.findall(html):
|
for v in pattern.findall(html):
|
||||||
urls.append('http://www.kugou.com/song/#hash=%s&album_id=%s'%(v[0],v[1]))
|
urls.append('http://www.kugou.com/song/#hash=%s&album_id=%s' % (v[0], v[1]))
|
||||||
print('http://www.kugou.com/song/#hash=%s&album_id=%s'%(v[0],v[1]))
|
print('http://www.kugou.com/song/#hash=%s&album_id=%s' % (v[0], v[1]))
|
||||||
|
|
||||||
#download the list by hash
|
# download the list by hash
|
||||||
for url in urls:
|
for url in urls:
|
||||||
kugou_download_by_hash(url,output_dir,merge,info_only)
|
kugou_download_by_hash(url, output_dir, merge, info_only)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
site_info = "kugou.com"
|
site_info = "kugou.com"
|
||||||
download = kugou_download
|
download = kugou_download
|
||||||
# download_playlist = playlist_not_supported("kugou")
|
# download_playlist = playlist_not_supported("kugou")
|
||||||
download_playlist=kugou_download_playlist
|
download_playlist = kugou_download_playlist
|
||||||
|
Loading…
Reference in New Issue
Block a user