kokarare1212 / librespot-python

Open Source Spotify Client
http://librespot-python.rtfd.io
Apache License 2.0
220 stars 43 forks source link

How can I get audio key? #243

Closed staniel359 closed 10 months ago

staniel359 commented 10 months ago

Hello.

From my console I try to call session.audio_key().get_audio_key(track.gid, file.file_id) but after some time it returns _queue.Empty.

What's the problem?

kokarare1212 commented 10 months ago

Please provide debug logs according to README.md.

staniel359 commented 10 months ago

@kokarare1212

>>> session.audio_key().get_audio_key(b'46982c56ce8f4470a377026e2fe1ac2f', b'c04e355b9f4606b21f94b2a4de5db26aeca0163f')
CRITICAL:Librespot:Session:Failed reading packet! Failed to receive packet
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): apresolve.spotify.com:443
DEBUG:urllib3.connectionpool:https://apresolve.spotify.com:443 "GET /?type=accesspoint HTTP/1.1" 200 None
INFO:Librespot:Session:Connection successfully!
INFO:Librespot:Session:Session.Receiver started
INFO:Librespot:Session:Re-authenticated as varkxpososm9sp59ojzpoc7rj!
INFO:Librespot:Session:Skipping 02
INFO:Librespot:Session:Received license_version: 0
INFO:Librespot:Session:Received country_code: GB
DEBUG:Librespot:Session:Parsed product info: {'type': 'free', 'ab-ad-player-targeting': '1', 'ab-ad-requester': '1', 'ab-android-push-notifications': '1', 'ab-browse-music-tuesday': '1', 'ab-collection-bookmark-model': '1', 'ab-collection-followed-artists-only': '1', 'ab-collection-hide-unavailable-albums': '0', 'ab-collection-offline-mode': '0', 'ab-collection-union': '1', 'ab-desktop-hide-follow': '0', 'ab-desktop-playlist-annotation-edit': '1', 'ab-mobile-discover': '0', 'ab-mobile-running-onlymanualmode': 'only-manual', 'ab-mobile-running-tempo-detection': 'Control', 'ab-mobile-social-feed': '1', 'ab-mobile-startpage': '0', 'ab-moments-experience': '0', 'ab-new-share-flow': '0', 'ab-play-history': '0', 'ab-playlist-extender': '5', 'ab-sugarpills-sanity-check': '0', 'ab-test-group': '82', 'ab-watch-now': '0', 'ab_recently_played_feature_time_filter_threshold': 'com.spotify.gaia=30,driving-mode=120,spotify%3Ainternal%3Astartpage=30', 'ad-catalogues': 'spotify', 'ad-formats-preroll-video': '0', 'ad-formats-video-takeover': '1', 'ad-persist-reward-time': '0', 'ad-session-persistence': '1', 'ad-use-adlogic': 'stream', 'addon-hifi': '0', 'ads': '1', 'allow-override-internal-prefs': '0', 'ap-resolve-pods': '1', 'app-developer': '0', 'arsenal_country': '1', 'audio-preview-url-template': 'https://p.scdn.co/mp3-preview/{id}', 'audio-quality': '0', 'audiobook-onboarding-completed': '0', 'audiobook-onboarding-dismissed': '0', 'autoplay': '1', 'backend-advised-bitrate': '1', 'browse-overview-enabled': '1', 'buffering-strategy': '0', 'buffering-strategy-parameters': '0.8:0.2:0.0:0.0:0.0:0.0:1.0:10:10:2000:10000:10485760', 'capper-profile': None, 'capping-bar-threshold': '3601', 'catalogue': 'free', 'collection': '1', 'created_by_partner': None, 'employee-free-opt-in': '0', 'enable-annotations': '2', 'enable-annotations-read': '0', 'enable-autostart': '1', 'enable-crossfade': '1', 'enable-gapless': '1', 'expiry': '1', 'explicit-content': '1', 'fb-grant-permission-local-render': '0', 'fb-info-confirmation': 'control', 'filter-explicit-content': '0', 'financial-product': 'pr:free,tc:0', 'head-file-caching': '1', 'head-files': '1', 'head-files-url': 'https://heads-fa.scdn.co/head/{file_id}', 'hifi-eligible': '0', 'hifi-optin-intent': '0', 'high-bitrate': '0', 'image-url': 'https://i.scdn.co/image/{file_id}', 'incognito_mode_timeout': '21600', 'india-experience': '0', 'instant-search': '0', 'instant-search-expand-sidebar': '0', 'is_email_verified': '1', 'key-caching-auto-offline': '0', 'key-caching-max-count': '10000', 'key-caching-max-offline-seconds': '1800', 'key-memory-cache-mode': '1:15,300', 'lastfm-session': None, 'libspotify': '0', 'license-acceptance-grace-days': '0', 'license-agreements': None, 'local-files-import': '0', 'metadata-link-lookup-modes': '0', 'mobile': '0', 'mobile-browse': '0', 'mobile-login': '0', 'mobile-payment': '0', 'name': 'Spotify Free', 'network-operator-premium-activation': '1', 'nft-disabled': '1', 'offline': '0', 'on-demand': '1', 'pause-after': '18000', 'payments-locked-state': '0', 'player-license': 'on-demand', 'playlist-annotations-markup': '0', 'playlist-folders': '1', 'preferred-locale': 'en', 'prefetch-keys': '1', 'prefetch-strategy': '18', 'prefetch-window-max': '2', 'profile-image-upload': '1', 'publish-activity': '0', 'publish-playlist': '1', 'radio': '1', 'remote-control': '6', 'send-email': '0', 'shows-collection': '1', 'shows-collection-jam': '1', 'shuffle': '0', 'shuffle-algorithm': '1', 'sidebar-navigation-enabled': '0', 'storage-size-config': '10240,90,500,3', 'streaming': '1', 'streaming-rules': None, 'track-cap': '0', 'ugc-abuse-report': '1', 'ugc-abuse-report-url': 'https://support.spotify.com/abuse/?uri={uri}', 'use-fb-publish-backend': '2', 'use-pl3': '0', 'use-playlist-app': '0', 'use-playlist-uris': '0', 'user-profile-show-invitation-codes': '0', 'video-cdn-sampling': '1', 'video-device-blacklisted': '0', 'video-initial-bitrate': '200000', 'video-keyframe-url': 'http://keyframes-fa.cdn.spotify.com/keyframes/v1/sources/{source_id}/keyframe/heights/{height}/timestamps/{timestamp_ms}.jpg', 'video-manifest-url': 'https://spclient.wg.spotify.com/manifests/v6/{type}/sources/{source_id}/options/supports_drm', 'video-wifi-initial-bitrate': '800000', 'wanted-licenses': None, 'widevine-license-url': 'https://spclient.wg.spotify.com/widevine-license/v1/video/license'}
INFO:Librespot:Session:Skipping 1f
INFO:Librespot:Session:Skipping 69
DEBUG:Librespot:MercuryClient:Handling packet, cmd: 0xb5, seq: -4684563848139636736, flags: b'\x01', parts: 1
DEBUG:Librespot:MercuryClient:Couldn't dispatch Mercury event seq: -4684563848139636736, uri: hm://pusher/v1/connections/NWNmZDZhY2RiYThmNjBhM2U4ODgxMTA4MmIxODQyNTFhZGEzNDIzZStBUCt0Y3A6Ly9nYWUyLWFjY2Vzc3BvaW50LWMtaDVmYi5nYWUyLnNwb3RpZnkubmV0OjUwMTYrNzBBREM0NEVGQUJCNzc2QkY4NUM3NzQyRTg0MjM4RkE1Qjk2MTE1MzREN0Y5OEVGNTczOTc0RjlGNEIyOTc5Qw%3D%3D, code: 200, payload: b''
DEBUG:Librespot:Session:Received 0x10: d4cb2bdcc2e31b3e6c62a46ef8f32b29a35e109c
INFO:Librespot:Session:Skipping unknown command cmd: 0x75, payload: b'\x00\x00\x00'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.10/site-packages/librespot/audio/__init__.py", line 274, in get_audio_key
    key = callback.wait_response()
  File "/usr/local/lib/python3.10/site-packages/librespot/audio/__init__.py", line 315, in wait_response
    return self.__reference.get(block=False)
  File "/usr/local/lib/python3.10/queue.py", line 168, in get
    raise Empty
_queue.Empty
kokarare1212 commented 10 months ago

As a general troubleshooting, could you please check if the music is restricted by country or account type, or if it is available in a different codec?

staniel359 commented 10 months ago

@kokarare1212 It's not restricted as session.content_feeder().load() worked. If I run it, I see that file_id is c04e355b9f4606b21f94b2a4de5db26aeca0163f (for .ogg 160). Also track's spotify id 29d0nY7TzCoi22XBqDQkiP converts to 46982c56ce8f4470a377026e2fe1ac2f global id.

kokarare1212 commented 10 months ago

Ah, I missed something important. The argument passed must be bytes, not hex.

staniel359 commented 10 months ago

@kokarare1212 But I pass it as b'id_value'.

kokarare1212 commented 10 months ago

No, it is not.

session.audio_key().get_audio_key(b'F\x98,V\xce\x8fDp\xa3w\x02n/\xe1\xac/', b'\xc0N5[\x9fF\x06\xb2\x1f\x94\xb2\xa4\xde]\xb2j\xec\xa0\x16?')
staniel359 commented 10 months ago

@kokarare1212 I see. How can I convert them to these values?

kokarare1212 commented 10 months ago

You can use this: https://docs.python.org/3/library/stdtypes.html#bytes.fromhex

kokarare1212 commented 10 months ago

No, it's Shannon Cipher( https://www.cantorsparadise.com/shannon-ciphers-and-perfect-security-d70c10379ac2 )

staniel359 commented 10 months ago

@kokarare1212 Thanks!