godeezer / lib

Deezer API implementation in Go
ISC License
5 stars 3 forks source link

Download returns 403 for high quality music on Hi-Fi accounts #11

Open fawni opened 2 years ago

fawni commented 2 years ago
_, err := client.Download(*song, deezer.FLAC)
log.Fatalln(err) // Deezer returned non-2XX code 403
samhza commented 2 years ago

If you don't have a premium/hi-fi account, you can only download 128-bit MP3s. This is a server-side limitation by Deezer that was implemented after I first started writing this library. I'll add a disclaimer to the README.

fawni commented 2 years ago

well the account i'm using is hifi but since i can download 128kbps mp3s i think it is a problem on deezer's end. thanks!

toniz4 commented 2 years ago

I'm experiencing the same problem, with a HIFI account. But with deemix I can download tracks in flac just fine

toniz4 commented 2 years ago

It apears that there is a more complex way for getting the url, this is a part of the python deezer librariy

    def get_tracks_url(self, track_tokens, track_format):
        if not isinstance(track_tokens, list):
            track_tokens = [track_tokens, ]
        if not self.current_user.get('license_token'):
            return []
        if (track_format == "FLAC" or track_format.startswith("MP4_RA")) and not self.current_user.get('can_stream_lossless') or track_format == "MP3_320" and not self.current_user.get('can_stream_hq'):
            raise WrongLicense(format)

        result = []
        try:
            request = self.session.post(
                "https://media.deezer.com/v1/get_url",
                json={
                    'license_token': self.current_user['license_token'],
                    'media': [{
                        'type': "FULL",
                        'formats': [
                            { 'cipher': "BF_CBC_STRIPE", 'format': track_format }
                        ]
                    }],
                    'track_tokens': track_tokens
                },
                headers = self.http_headers
            )
            request.raise_for_status()
            response = request.json()
        except requests.exceptions.HTTPError:
            return []

        if len(response.get('data', [])):
            for data in response['data']:
                if 'errors' in data:
                    if data['errors'][0]['code'] == 2002:
                        result.append(WrongGeolocation(self.current_user['country']))
                    else:
                        result.append(DeezerError(json.dumps(response)))
                if 'media' in data and len(data['media']):
                    result.append(data['media'][0]['sources'][0]['url'])
                else:
                    result.append(None)
        return result

what we are missing is that "licence_token".

samhza commented 2 years ago

I see now, I'm a bit busy with school but sometime soon I will try to get a Hi-Fi account for a bit so I can support the new way to get track URLs. PRs are open if someone wants to get this fix done before I get the time to.

toniz4 commented 2 years ago

I have a HIFI account, if you are avalible in a weekend, I can email you an arl, or sent it via matrix.

cassioavila (at) airmail.cc @cassioavila:matrix.org

This weekend i can try doing something, but I'm pretty busy with school too.