def download_playlistspo(self,
                             URL,
                             output=stock_output + "/",
                             quality=stock_quality,
                             recursive_quality=stock_recursive_quality,
                             recursive_download=stock_recursive_download,
                             not_interface=stock_not_interface,
                             zips=stock_zip):
        array = []

        URL = (URL.split("?")[0].split("/"))

        try:
            tracks = self.spo.user_playlist_tracks(URL[-3], URL[-1])
        except Exception as a:
            if not "The access token expired" in str(a):
                raise exceptions.InvalidLink("Invalid link ;)")

            self.spo = Spotify(generate_token())

            tracks = self.spo.user_playlist_tracks(URL[-3], URL[-1])

        for a in tracks['items']:
            try:
                array.append(
                    self.download_trackspo(
                        a['track']['external_urls']['spotify'], output,
                        quality, recursive_quality, recursive_download,
                        not_interface))
            except:
                print("Track not found :(")
                array.append("None")

        if tracks['total'] != 100:
            for a in range(tracks['total'] // 100):
                try:
                    tracks = self.spo.next(tracks)
                except:
                    self.spo = Spotify(generate_token())

                    tracks = self.spo.next(tracks)

                for a in tracks['items']:
                    try:
                        array.append(
                            self.download_trackspo(
                                a['track']['external_urls']['spotify'], output,
                                quality, recursive_quality, recursive_download,
                                not_interface))
                    except:
                        print("Track not found :(")
                        array.append("None")

        if zips:
            zip_name = "{}playlist {}.zip".format(output, URL[-1])
            create_zip(zip_name, array)
            return array, zip_name

        return array
    def download_trackspo(self,
                          URL,
                          output=stock_output + "/",
                          quality=stock_quality,
                          recursive_quality=stock_recursive_quality,
                          recursive_download=stock_recursive_download,
                          not_interface=stock_not_interface):
        URL = URL.split("?")[0]

        try:
            url = self.spo.track(URL)
        except Exception as a:
            if not "The access token expired" in str(a):
                raise exceptions.InvalidLink("Invalid link ;)")

            self.spo = Spotify(generate_token())

            url = self.spo.track(URL)

        isrc = url['external_ids']['isrc']

        url = request("https://api.deezer.com/track/isrc:%s" % isrc,
                      True).json()

        name = self.download_trackdee(url['link'], output, quality,
                                      recursive_quality, recursive_download,
                                      not_interface)

        return name
    def __init__(self, token):
        self.spo = Spotify(generate_token())

        self.req = Session()
        self.req.cookies['arl'] = token

        user_id = (self.req.get("https://www.deezer.com/").text.split(
            "'deezer_user_id': ")[1].split(",")[0])

        if user_id == "0":
            raise exceptions.BadCredentials("Wrong token: %s :(" % token)
    def download_name(self,
                      artist,
                      song,
                      output=stock_output + "/",
                      quality=stock_quality,
                      recursive_quality=stock_recursive_quality,
                      recursive_download=stock_recursive_download,
                      not_interface=stock_not_interface):
        query = "track:{} artist:{}".format(song, artist)

        try:
            search = self.spo.search(query)
        except:
            self.spo = Spotify(generate_token())

            search = self.spo.search(query)

        try:
            return self.download_trackspo(
                search['tracks']['items'][0]['external_urls']['spotify'],
                output, quality, recursive_quality, recursive_download,
                not_interface)
        except IndexError:
            raise exceptions.TrackNotFound("Track not found: :(")
    def download_albumspo(self,
                          URL,
                          output=stock_output + "/",
                          quality=stock_quality,
                          recursive_quality=stock_recursive_quality,
                          recursive_download=stock_recursive_download,
                          not_interface=stock_not_interface,
                          zips=stock_zip):
        URL = URL.split("?")[0]

        try:
            tracks = self.spo.album(URL)
        except Exception as a:
            if not "The access token expired" in str(a):
                raise exceptions.InvalidLink("Invalid link ;)")

            self.spo = Spotify(generate_token())

            tracks = self.spo.album(URL)

        tot = tracks['total_tracks']

        try:
            upc = tracks['external_ids']['upc']

            while upc[0] == "0":
                upc = upc[1:]

            url = request("https://api.deezer.com/album/upc:%s" % upc).json()

            names = self.download_albumdee(url['link'], output, quality,
                                           recursive_quality,
                                           recursive_download, not_interface,
                                           zips)
        except KeyError:
            search = tot // 5

            try:
                url = self.spo.track(tracks['tracks']['items'][search]
                                     ['external_urls']['spotify'])
            except:
                self.spo = Spotify(generate_token())

                url = self.spo.track(tracks['tracks']['items'][search]
                                     ['external_urls']['spotify'])

            isrc = url['external_ids']['isrc']

            try:
                ids = request("https://api.deezer.com/track/isrc:%s" % isrc,
                              True).json()['album']['id']

                tracks = request("https://api.deezer.com/album/%d" % ids,
                                 True).json()

                if tot != tracks['nb_tracks']:
                    raise exceptions.TrackNotFound("")

                names = self.download_albumdee(tracks['link'], output, quality,
                                               recursive_quality,
                                               recursive_download,
                                               not_interface, zips)
            except (exceptions.TrackNotFound, exceptions.NoDataApi):
                raise exceptions.AlbumNotFound("Album not found :(")

        return names