Beispiel #1
0
 def cfg_setup(self):
     for secret in self.secrets:
         if self.test_secret(secret):
             self.sec = secret
             break
     if not hasattr(self, "sec"):
         raise InvalidAppSecretError("Invalid app secret.\n" + RESET)
Beispiel #2
0
    def cfg_setup(self):
        for secret in self.secrets:
            if secret and self.test_secret(secret):
                self.sec = secret
                break

        if self.sec is None:
            raise InvalidAppSecretError("Invalid app secret.\n" + RESET)
Beispiel #3
0
    def cfg_setup(self):
        for secret in self.secrets:
            # Falsy secrets
            if not secret:
                continue

            if self.test_secret(secret):
                self.sec = secret
                break

        if self.sec is None:
            raise InvalidAppSecretError("Can't find any valid app secret.\n" +
                                        RESET)
Beispiel #4
0
 def api_call(self, epoint, **kwargs):
     if epoint == "user/login":
         params = {
             "email": kwargs["email"],
             "password": kwargs["pwd"],
             "app_id": self.id,
         }
     elif epoint == "track/get":
         params = {"track_id": kwargs["id"]}
     elif epoint == "album/get":
         params = {"album_id": kwargs["id"]}
     elif epoint == "playlist/get":
         params = {
             "extra": "tracks",
             "playlist_id": kwargs["id"],
             "limit": 500,
             "offset": kwargs["offset"],
         }
     elif epoint == "artist/get":
         params = {
             "app_id": self.id,
             "artist_id": kwargs["id"],
             "limit": 500,
             "offset": kwargs["offset"],
             "extra": "albums",
         }
     elif epoint == "label/get":
         params = {
             "label_id": kwargs["id"],
             "limit": 500,
             "offset": kwargs["offset"],
             "extra": "albums",
         }
     elif epoint == "userLibrary/getAlbumsList":
         unix = time.time()
         r_sig = "userLibrarygetAlbumsList" + str(unix) + kwargs["sec"]
         r_sig_hashed = hashlib.md5(r_sig.encode("utf-8")).hexdigest()
         params = {
             "app_id": self.id,
             "user_auth_token": self.uat,
             "request_ts": unix,
             "request_sig": r_sig_hashed,
         }
     elif epoint == "track/getFileUrl":
         unix = time.time()
         track_id = kwargs["id"]
         fmt_id = kwargs["fmt_id"]
         if int(fmt_id) not in (5, 6, 7, 27):
             raise InvalidQuality("Invalid quality id: choose between 5, 6, 7 or 27")
         r_sig = "trackgetFileUrlformat_id{}intentstreamtrack_id{}{}{}".format(
             fmt_id, track_id, unix, self.sec
         )
         r_sig_hashed = hashlib.md5(r_sig.encode("utf-8")).hexdigest()
         params = {
             "request_ts": unix,
             "request_sig": r_sig_hashed,
             "track_id": track_id,
             "format_id": fmt_id,
             "intent": "stream",
         }
     else:
         params = kwargs
     r = self.session.get(self.base + epoint, params=params)
     if epoint == "user/login":
         if r.status_code == 401:
             raise AuthenticationError("Invalid credentials.\n" + RESET)
         elif r.status_code == 400:
             raise InvalidAppIdError("Invalid app id.\n" + RESET)
         else:
             logger.info(f"{GREEN}Logged: OK")
     elif epoint in ["track/getFileUrl", "userLibrary/getAlbumsList"]:
         if r.status_code == 400:
             raise InvalidAppSecretError("Invalid app secret.\n" + RESET)
     r.raise_for_status()
     return r.json()