Fix InvalidAppSecret

This commit is contained in:
Vitiko 2021-11-26 21:56:26 -04:00
parent e586e7d868
commit b9b1d134f1
2 changed files with 18 additions and 13 deletions

View File

@ -74,7 +74,8 @@ class Client:
} }
elif epoint == "favorite/getUserFavorites": elif epoint == "favorite/getUserFavorites":
unix = time.time() unix = time.time()
r_sig = "userLibrarygetAlbumsList" + str(unix) + kwargs["sec"] # r_sig = "userLibrarygetAlbumsList" + str(unix) + kwargs["sec"]
r_sig = "favoritegetUserFavorites" + str(unix) + kwargs["sec"]
r_sig_hashed = hashlib.md5(r_sig.encode("utf-8")).hexdigest() r_sig_hashed = hashlib.md5(r_sig.encode("utf-8")).hexdigest()
params = { params = {
"app_id": self.id, "app_id": self.id,
@ -90,7 +91,7 @@ class Client:
if int(fmt_id) not in (5, 6, 7, 27): if int(fmt_id) not in (5, 6, 7, 27):
raise InvalidQuality("Invalid quality id: choose between 5, 6, 7 or 27") raise InvalidQuality("Invalid quality id: choose between 5, 6, 7 or 27")
r_sig = "trackgetFileUrlformat_id{}intentstreamtrack_id{}{}{}".format( r_sig = "trackgetFileUrlformat_id{}intentstreamtrack_id{}{}{}".format(
fmt_id, track_id, unix, self.sec fmt_id, track_id, unix, kwargs.get("sec", self.sec)
) )
r_sig_hashed = hashlib.md5(r_sig.encode("utf-8")).hexdigest() r_sig_hashed = hashlib.md5(r_sig.encode("utf-8")).hexdigest()
params = { params = {
@ -110,11 +111,12 @@ class Client:
raise InvalidAppIdError("Invalid app id.\n" + RESET) raise InvalidAppIdError("Invalid app id.\n" + RESET)
else: else:
logger.info(f"{GREEN}Logged: OK") logger.info(f"{GREEN}Logged: OK")
elif epoint in ["track/getFileUrl", "favorite/getUserFavorites"]: elif (
if r.status_code == 400: epoint in ["track/getFileUrl", "favorite/getUserFavorites"]
raise InvalidAppSecretError( and r.status_code == 400
f"Invalid app secret: {r.json()}.\n" + RESET ):
) raise InvalidAppSecretError(f"Invalid app secret: {r.json()}.\n" + RESET)
r.raise_for_status() r.raise_for_status()
return r.json() return r.json()
@ -193,17 +195,20 @@ class Client:
def test_secret(self, sec): def test_secret(self, sec):
try: try:
self.api_call("favorite/getUserFavorites", sec=sec) self.api_call("track/getFileUrl", id=5966783, fmt_id=5, sec=sec)
return True return True
except InvalidAppSecretError as error: except InvalidAppSecretError:
logger.info("Invalid SECRET: %s", error)
return False return False
def cfg_setup(self): def cfg_setup(self):
for secret in self.secrets: for secret in self.secrets:
if secret and self.test_secret(secret): # Falsy secrets
if not secret:
continue
if self.test_secret(secret):
self.sec = secret self.sec = secret
break break
if self.sec is None: if self.sec is None:
raise InvalidAppSecretError("Invalid app secret.\n" + RESET) raise InvalidAppSecretError("Can't find any valid app secret.\n" + RESET)

View File

@ -13,7 +13,7 @@ requirements = read_file("requirements.txt").strip().split()
setup( setup(
name=pkg_name, name=pkg_name,
version="0.9.9.4", version="0.9.9.5",
author="Vitiko", author="Vitiko",
author_email="vhnz98@gmail.com", author_email="vhnz98@gmail.com",
description="The complete Lossless and Hi-Res music downloader for Qobuz", description="The complete Lossless and Hi-Res music downloader for Qobuz",