#初慕苏流年
#Q1274210585
#群556766602
import requests,json,urllib
def nianwy(music,s,t):
    aaaa=json.loads(requests.get("http://music.163.com/api/search/get/web?csrf_token=hlpretag=&hlposttag=&s="+music+"&type=1&offset=0&total=true&limit=20").text);aa=[aaaa["result"]["songs"][i]["id"] for i in range(6)];a=int(s);a=["http://music.163.com/song/media/outer/url?id="+str(aa[a])+".mp3",aaaa["result"]["songs"][a]["name"]+"-"+aaaa["result"]["songs"][s]["artists"][0]["name"]] if t==True else "http://music.163.com/song/media/outer/url?id="+str(aa[a])+".mp3";return a
def nianqq(music,s,t):
    aaa = requests.get("https://c.y.qq.com/soso/fcgi-bin/client_search_cp?ct=24&qqmusic_ver=1298&new_json=1&remoteplace=txt.yqq.song&searchid=61460539676714578&t=0&aggr=1&cr=1&catZhida=1&lossless=0&flag_qc=0&p=1&n=10&w={0}&g_tk_new_20200303=5381&g_tk=5381&loginUin=0&hostUin=0&format=json&inCharset=utf8&outCharset=utf-8&notice=0&platform=yqq.json&needNewCode=0".format(music));aaaa=json.loads(aaa.text);nian=aaaa["data"]["song"]["list"];bb=[];bb=[music["title"]+"-"+music["singer"][0]["title"] for music in nian];aaa=json.loads(requests.get("https://u.y.qq.com/cgi-bin/musicu.fcg?format=json&data=%7B%22req_0%22%3A%7B%22module%22%3A%22vkey.GetVkeyServer%22%2C%22method%22%3A%22CgiGetVkey%22%2C%22param%22%3A%7B%22guid%22%3A%22358840384%22%2C%22songmid%22%3A%5B%22{}%22%5D%2C%22songtype%22%3A%5B0%5D%2C%22uin%22%3A%221443481947%22%2C%22loginflag%22%3A1%2C%22platform%22%3A%2220%22%7D%7D%2C%22comm%22%3A%7B%22uin%22%3A%2218585073516%22%2C%22format%22%3A%22json%22%2C%22ct%22%3A24%2C%22cv%22%3A0%7D%7D".format(aaaa["data"]["song"]["list"][int(s)]['mid'])).text);aa=aaa['req_0']['data']['midurlinfo'][0]['purl'];a=["https://isure.stream.qqmusic.qq.com/"+aa,bb[s]] if t==True else "https://isure.stream.qqmusic.qq.com/"+aa;return a
def niankg(music,s,t):
    b=music;a=json.loads(requests.get("http://msearchcdn.kugou.com/api/v3/search/song?showtype=14&highlight=em&pagesize=30&tag_aggr=1&tagtype=%E5%85%A8%E9%83%A8&plat=0&sver=5&keyword={}&correct=1&api_ver=1&version=9108&page=1&area_code=1&tag=1&with_res_tag=1".format(b)).text[23:-21]);aa=[a["data"]["info"][i]["hash"] for i in range(6)];bb=[a["data"]["info"][i]["album_id"] for i in range(6)];c,s=int(s),requests.Session();headers={"Host": "www.kugou.com","Connection": "keep-alive","Cache-Control": "max-age=0","Upgrade-Insecure-Requests": "1","User-Agent": "Mozilla/5.0 (Linux; Android 8.1.0; PBAT00 Build/OPM1.171019.026; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/62.0.3202.84 Mobile Safari/537.36","dnt": "1","Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8","Referer": "http://www.kugou.com/yy/index.php?r=play/getdata&hash=f8784ebfbae36b324ec1e3441b6156b4&album_id=1645030&_=","Accept-Encoding": "gzip, deflate","Accept-Language": "zh-CN,en-US;q=0.9","Cookie": "kg_mid=99d022a988b55c42e89a27dfa084fdac; kg_dfid=0Qi8qz2gH29M3dfNNl2aQ6cD; kg_dfid_collect=d41d8cd98f00b204e9800998ecf8427e; KuGooRandom=66531611627702529; Hm_lvt_aedee6983d4cfc62f509129360d6bb3d=1611627606; Hm_lpvt_aedee6983d4cfc62f509129360d6bb3d=1611636395","X-Requested-With": "mark.via","If-Modified-Since": "","If-None-Natch": ""};a=[json.loads(s.get("http://www.kugou.com/yy/index.php?r=play/getdata&hash="+aa[c]+"&album_id="+bb[c]+"&_",headers=headers,allow_redirects=False).text)["data"]["play_url"],a["data"]["info"][c]["filename"]] if t==True else json.loads(s.get("http://www.kugou.com/yy/index.php?r=play/getdata&hash="+aa[c]+"&album_id="+bb[c]+"&_",headers=headers,allow_redirects=False).text)["data"]["play_url"];return a
def niandy(url):
    print("测试功能,随时删除");url_string=url;print("解析302地址中......");r = requests.head(url_string, stream=True);print("获取视频ID中......");a="https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids="+r.headers['Location'][38:57];print("获取链接ID中......");b="https://aweme.snssdk.com/aweme/v1/play/?video_id="+json.loads(requests.get(a).text)["item_list"][0]["video"]["vid"]+"&ratio=720p&line=0";return b
def niankw(song):
    import jsonpath;keyword = requests.utils.quote(song);s = requests.session();url = 'https://kuwo.cn/';headers = {'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9','Accept-Encoding': 'gzip, deflate, br','Accept-Language': 'zh-CN,zh;q=0.9','Cache-Control': 'no-cache','Connection': 'keep-alive','Host': 'kuwo.cn','Pragma': 'no-cache','Sec-Fetch-Dest': 'document','Sec-Fetch-Mode': 'navigate','Sec-Fetch-Site': 'none','Sec-Fetch-User': '?1','Upgrade-Insecure-Requests': '1','User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36',};s.get(url, headers=headers);csrf = s.cookies.get_dict()['kw_token'];url = f'https://kuwo.cn/api/www/search/searchMusicBykeyWord?key={keyword}&pn=1&rn=30&httpsStatus=1';headers = {'csrf': csrf,'Referer': f'https://kuwo.cn/search/list?key={keyword}','User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36',};r = s.get(url, headers=headers).json();rid = jsonpath.jsonpath(r, '$..rid')[0];url = f'https://kuwo.cn/url?format=mp3&rid={rid}&response=url&type=convert_url3&br=128kmp3&from=web&t=1614342354424&httpsStatus=1';headers = {'Accept': 'application/json, text/plain, */*','Accept-Encoding': 'gzip, deflate, br','Accept-Language': 'zh-CN,zh;q=0.9','Cache-Control': 'no-cache','Connection': 'keep-alive','Host': 'kuwo.cn','Pragma': 'no-cache','Referer': f'https://kuwo.cn/search/list?key={keyword}','Sec-Fetch-Dest': 'empty','Sec-Fetch-Mode': 'cors','Sec-Fetch-Site': 'same-origin','User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36',};r = s.get(url, headers=headers).json();music_url = r.get("url");return music_url
