Files
2024-05-26 13:25:28 +08:00

100 lines
5.2 KiB
Python

try:
from Provider import SessionProvider, SongStatus, AccountType
except:
from Extensions.Provider import SessionProvider, SongStatus, AccountType
from enum import Enum
import httpx
import re
from functools import lru_cache
try:
print(_)
except:
_ = lambda x: x
# 次奥,要手写API了
class QQMusicSession(SessionProvider):
session = None
providerName = "QQMusic"
URL_Keyword = ["y.qq.com"]
accountType = AccountType.ACCOUNT_NOLOGIN
cookies = {}
def __init__(self):
print(_("WARN: This extension is deprecated due to the change of APIkey of y.qq.com!"))
def loginAnonymous(self):
return {"status": 501, "msg": _("QQMusic does not support anonymous login.")}, 501
def loginCredential(self, content: str, key: str):
cookies = content
return {"status": 200, "msg": _("Cookies updated.")}
def login(self) -> dict:
if cookies:
self.accountType = AccountType.ACCOUNT_COOKIE
return {"status": 200, "msg": _("QQMusic login succeeded.")}
else:
return {"status": 401, "msg": _("Cookie required!")}, 401
def logout(self):
self.accountType = AccountType.ACCOUNT_NOLOGIN
self.cookies = ""
return {"status": 200, "msg": _("QQMusic logout succeeded.")}
def parseURL(self, content: str) -> str or None:
mid = None
try:
if "fcgi-bin/u?__" in content:
content = re.search(r"https://.*", content).group()
print(content)
mid = httpx.get(content).headers.get("location")
mid = re.search(r"songmid=(.+?)&", mid).group(1)
elif "ryqq/songDetail" in content:
mid = re.search(r"/[^/]+$", content).group()[1:]
except Exception as e:
print(e)
return None
return mid
def checkURL(self, content: str) -> bool:
for i in self.URLKeyword:
if i in content:
return True
return False
def getSongURL(self, content: str) -> str:
payload = r"https://u.y.qq.com/cgi-bin/musicu.fcg?format=json&data={%22req_0%22:{%22module%22:%22vkey.GetVkeyServer%22,%22method%22:%22CgiGetVkey%22,%22param%22:{%22filename%22:[%22PREFIXSONGMIDSONGMID.SUFFIX%22],%22guid%22:%2210000%22,%22songmid%22:[%22SONGMID%22],%22songtype%22:[0],%22uin%22:%220%22,%22loginflag%22:1,%22platform%22:%2220%22}},%22loginUin%22:%220%22,%22comm%22:{%22uin%22:%220%22,%22format%22:%22json%22,%22ct%22:24,%22cv%22:0}}"
payload = payload.replace("PREFIX", "M500")
payload = payload.replace("SONGMID", content)
payload = payload.replace("SUFFIX", "mp3")
data = httpx.get(payload, cookies=self.cookies)
print(payload)
print(data.json())
print(a:=data.json()["req_0"]["data"]["midurlinfo"][0]["purl"])
print(b:=data.json()["req_0"]["data"]["sip"][0])
return b+a
@lru_cache(maxsize=256)
def _getSongStatus(self, content:str) -> dict:
payload = r"https://u.y.qq.com/cgi-bin/musicu.fcg?format=json&data={%22req%22:{%22module%22:%22music.pf_song_detail_svr%22,%22method%22:%22get_song_detail_yqq%22,%22param%22:{%22songmid%22:%22SONGMID%22}},%22loginUin%22:%220%22,%22comm%22:{%22uin%22:%220%22,%22format%22:%22json%22,%22ct%22:24,%22cv%22:0}}"
payload = payload.replace("SONGMID", content)
data = httpx.get(payload,cookies=self.cookies )
print(data.json())
def dumpSession(self) -> str:
return self.cookies
def restoreSession(self, session: str):
self.cookies = session
self.login()
if __name__ == "__main__":
cookies = "pac_uid=1_1599172402; iip=0; _qimei_fingerprint=a60e880d499fb09dfa3fc2e7b67f5cac; _qimei_q36=; _qimei_h38=5261d3497d310405f78852440900000df17a1e; RK=vx0t0LFmeo; ptcz=ad36d5ca2a0e7a6b7250c853a187f263446dfb2530128858c1c61c5fcc10875c; pgv_pvid=2920262853; eas_sid=d14770F6p8X5a1M6V2z6X8H9W1; qq_domain_video_guid_verify=c6c04001d0488e55; o_cookie=1599172402; suid=ek168787168502135101; _qimei_uuid42=18401162425100258014e7193532ca71547ede2d09; vversion_name=8.2.95; pgv_info=ssid=s4743344675; uin=1599172402; fqm_pvqid=d34c53e5-031d-4762-b0e1-10a3b13013b6; fqm_sessionid=12a505d3-2ba4-4fd8-b025-6d773e4153e6; ts_refer=cn.bing.com/; ts_uid=2582842080; ts_last=y.qq.com/n/ryqq/songDetail/002vbWwe3ZmffT; login_type=1; psrf_qqaccess_token=2BFFE211C6375E16CAE328C65066052A; qm_keyst=Q_H_L_63k3Naa-qgZKZwiv-Q6TaqMCUYqy0nrKuDW6p2NbmOYb0AYcnh1ttAqA9Az9tpu2D1FCrAkeJFQ; wxunionid=; euin=oK4qNK6lowvzoc**; psrf_qqrefresh_token=B75229616609EF6988510371BEF3EFA2; psrf_qqunionid=9A90D76C7D610B8DF336DC5F19EC8773; qqmusic_key=Q_H_L_63k3Naa-qgZKZwiv-Q6TaqMCUYqy0nrKuDW6p2NbmOYb0AYcnh1ttAqA9Az9tpu2D1FCrAkeJFQ; tmeLoginType=2; music_ignore_pskey=202306271436Hn@vBj; psrf_musickey_createtime=1714623437; wxrefresh_token=; psrf_access_token_expiresAt=1722399437; psrf_qqopenid=027F5F42CADC5D52F710B2936B81B0C5; wxopenid="
qmsess = QQMusicSession()
smid = qmsess.parseURL("https://c6.y.qq.com/base/fcgi-bin/u?__=yCNzlNSNbaWD")
smid = qmsess.parseURL("https://y.qq.com/n/ryqq/songDetail/000lKV2G0PEkc3")
print(qmsess.loginCredential(cookies, ""))
print(qmsess.login())
print(qmsess.getSongURL(smid))
#print(qmsess._getSongStatus(smid))