From 02eb2cdc9a25fff46ddff2cc83ba3482d9a6aed0 Mon Sep 17 00:00:00 2001 From: nathom Date: Thu, 15 Apr 2021 13:52:51 -0700 Subject: [PATCH] Reformat spoofbuz.py --- streamrip/spoofbuz.py | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/streamrip/spoofbuz.py b/streamrip/spoofbuz.py index 1ae81db..5a3fc8d 100644 --- a/streamrip/spoofbuz.py +++ b/streamrip/spoofbuz.py @@ -9,10 +9,20 @@ import requests class Spoofer: def __init__(self): - self.seed_timezone_regex = r'[a-z]\.initialSeed\("(?P[\w=]+)",window\.utimezone\.(?P[a-z]+)\)' + self.seed_timezone_regex = ( + r'[a-z]\.initialSeed\("(?P[\w=]+)",window\.ut' + r"imezone\.(?P[a-z]+)\)" + ) # note: {timezones} should be replaced with every capitalized timezone joined by a | - self.info_extras_regex = r'name:"\w+/(?P{timezones})",info:"(?P[\w=]+)",extras:"(?P[\w=]+)"' - self.app_id_regex = r'{app_id:"(?P\d{9})",app_secret:"\w{32}",base_port:"80",base_url:"https://www\.qobuz\.com",base_method:"/api\.json/0\.2/"},n\.base_url="https://play\.qobuz\.com"' + self.info_extras_regex = ( + r'name:"\w+/(?P{timezones})",info:"' + r'(?P[\w=]+)",extras:"(?P[\w=]+)"' + ) + self.app_id_regex = ( + r'{app_id:"(?P\d{9})",app_secret:"\w{32}",base_port:"80"' + r',base_url:"https://www\.qobuz\.com",base_method:"/api\.js' + r'on/0\.2/"},n\.base_url="https://play\.qobuz\.com"' + ) login_page_request = requests.get("https://play.qobuz.com/login") login_page = login_page_request.text bundle_url_match = re.search( @@ -33,24 +43,30 @@ class Spoofer: for match in seed_matches: seed, timezone = match.group("seed", "timezone") secrets[timezone] = [seed] - """The code that follows switches around the first and second timezone. Why? Read on: - Qobuz uses two ternary (a shortened if statement) conditions that should always return false. - The way Javascript's ternary syntax works, the second option listed is what runs if the condition returns false. - Because of this, we must prioritize the *second* seed/timezone pair captured, not the first. + """ + The code that follows switches around the first and second timezone. + Qobuz uses two ternary (a shortened if statement) conditions that + should always return false. The way Javascript's ternary syntax + works, the second option listed is what runs if the condition returns + false. Because of this, we must prioritize the *second* seed/timezone + pair captured, not the first. """ keypairs = list(secrets.items()) secrets.move_to_end(keypairs[1][0], last=False) + info_extras_regex = self.info_extras_regex.format( - timezones="|".join([timezone.capitalize() for timezone in secrets]) + timezones="|".join(timezone.capitalize() for timezone in secrets) ) info_extras_matches = re.finditer(info_extras_regex, self.bundle) for match in info_extras_matches: timezone, info, extras = match.group("timezone", "info", "extras") secrets[timezone.lower()] += [info, extras] + for secret_pair in secrets: secrets[secret_pair] = base64.standard_b64decode( "".join(secrets[secret_pair])[:-44] ).decode("utf-8") + vals = list(secrets.values()) vals.remove("") return vals