doorxp

Blog

you-get kugou.py 修改

修改文件路径 /usr/local/Cellar/you-get/0.4.1650/libexec/lib/python3.11/site-packages/you_get/extractors/kugou.py

内容如下:


#!/usr/bin/env python


__all__ = ['kugou_download']

from ..common import *
from json import loads
from base64 import b64decode
import re
from selenium import webdriver

def kugou_download(url, output_dir=".", merge=True, info_only=False, **kwargs):

options = webdriver.ChromeOptions()
options.add_argument("headless")

browser=webdriver.Chrome(options=options)
browser.get(url)
hash = browser.execute_script('return window.hash;')
album_id = browser.execute_script('return window.album_id;')
album_audio_id = browser.execute_script('return window.album_audio_id;')
encode_album_audio_id = browser.execute_script('return window.encode_album_audio_id;')

bInfo = browser.execute_async_script('const callback = arguments[arguments.length - 1];window.getBaseInfo(1014, function(bInfo) {callback(bInfo);});')


info = browser.execute_async_script(
"""
       const callback = arguments[arguments.length - 1];
       window.infSign({from:112,appid:%d,dfid:"%s",encode_album_audio_id:"%s",mid:"%s",platid:%d,token:"",userid:"0",uuid:"%s"}, null, {
           useH5: true,
           postType: 'json',
           callback: function (spa){$.ajax({
               type: "GET",
               url: "https://wwwapi.kugou.com/play/songinfo",timeout: 5000,data: spa,
               "success": function (res, status, xhr) {
                   callback(res);
                   }
               }
           );
       }
   });
""" %(bInfo['appid'],bInfo['dfid'],encode_album_audio_id, bInfo['mid'], bInfo['plat'], bInfo['uuid']))
logging.debug(info)

play_url = info["data"]["play_url"]
title = info["data"]["song_name"]
# ext = "mp3"
# size = info["data"]["filesize"];

songtype, ext, size = url_info(play_url)
print_info(site_info, title, songtype, size)

download_urls([play_url], title, ext, size, output_dir, merge=merge)

#html = get_html(url,faker=True)
# var hash = "33209AA0259DEF69D0B61333CBE4701A"
# var album_id = "67025894"
# var album_audio_id = "482684975"
# var encode_album_audio_id = "7zdm3zb8"

# hashre = re.compile(r'var hash = "(.*?)"')
# hash = hashre.search(html).group(1).lower()

# album_idre = re.compile(r'var album_id = "(.*?)"')
# album_id = album_idre.search(html).group(1)

# album_audio_idre = re.compile(r'var album_audio_id = "(.*?)"')
# album_audio_id = album_audio_idre.search(html).group(1)

# encode_album_audio_idre = re.compile(r'var encode_album_audio_id = "(.*?)"')
# encode_album_audio_id = encode_album_audio_idre.search(html).group(1)


# if url.lower().find("5sing") != -1:
#     # for 5sing.kugou.com
#     html = get_html(url, faker=True)
#     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("-") == -1:
#     return kugou_download_by_hash(url, output_dir, merge, info_only)
# else:
#     # 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+)')
#     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), faker=True)
#     j = loads(html)
#     url = j['data']['play_url']
#     title = j['data']['audio_name']
#     # some songs cann't play because of copyright protection
#     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,faker=True)
#         pattern = re.compile('<a href="(http://.*?)" data-active=')
#         res = pattern.findall(html)

#         for song in res:
#             res = get_html(song, faker=True)
#             pattern_url = re.compile('"hash":"(\w+)".*"album_id":(\d)+')
#             hash_val, album_id = res = pattern_url.findall(res)[0]
#             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
#     # album sample:   http://www.kugou.com/yy/album/single/1645030.html
#     elif url.lower().find('album') != -1:
#         html = get_html(url, faker=True)
#         pattern = re.compile('var data=(\[.*?\]);')
#         res = pattern.findall(html)[0]
#         for v in json.loads(res):
#             urls.append('http://www.kugou.com/song/#hash=%s&album_id=%s' % (v['hash'], v['album_id']))

#     # download the playlist        
#     # playlist sample:http://www.kugou.com/yy/special/single/487279.html
#     else:
#         html = get_html(url, faker=True)
#         pattern = re.compile('data="(\w+)\|(\d+)"')
#         for v in pattern.findall(html):
#             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]))

#     logging.debug(urls)

#     # download the list by hash
#     for url in urls:
#         kugou_download_by_hash(url, output_dir, merge, info_only)


site_info = "kugou.com"
download = kugou_download
# download_playlist = playlist_not_supported("kugou")
#download_playlist = kugou_download_playlist


发表评论:

«   2024年11月   »
123
45678910
11121314151617
18192021222324
252627282930
控制面板
您好,欢迎到访网站!
  查看权限
网站分类
搜索
最新留言

    Powered By Z-BlogPHP 1.5.1 Zero

    Copyright doorxp.com Rights Reserved.