I see there is a gid
for each track on Spotify.
As you see in the image, B
is the track ID but I don't understand A
.
Please check the response of the request shown in the previous image here.
Do you know what this gid is and how we can retrieve it?
Thanks in advance
UPDATE:
As an example, Spotify calls an API as https://spclient.wg.spotify.com/metadata/4/track/1e763423ad0e4862b20f9dbfdadc2cb7
for the track https://open.spotify.com/track/0VtMV3IYHAu7fyZmqnGE99. as you see the the id at the end of the API URL is 1e763423ad0e4862b20f9dbfdadc2cb7
which is different from the track id (0VtMV3IYHAu7fyZmqnGE99
). The response of the API is {"gid": "1e763423ad0e4862b20f9dbfdadc2cb7","name": "Oh Yeah","album": {"gid": "b6a45388cac54953b3fe0f8e0ab7c729","name": "Oh Glory","artist": [{"gid": "e8dba066dc3644b1b69510eb3cdd8a42","name": "Aime Simone"}],"label": "No Start No End","date": {"year": 2023,"month": 5,"day": 5},"cover_group": {"image": [{"file_id": "ab67616d00001e026cddc8afe19c5950b5f6f5b6","size": "DEFAULT","width": 300,"height": 300},{"file_id": "ab67616d000048516cddc8afe19c5950b5f6f5b6","size": "SMALL","width": 64,"height": 64},{"file_id": "ab67616d0000b2736cddc8afe19c5950b5f6f5b6","size": "LARGE","width": 640,"height": 640}]},"licensor": {"uuid": "1b3fb428ae7b41aa97c9b46c5b962d57"},"prerelease_config": {"earliest_reveal_date": {"year": 2023,"month": 5,"day": 4,"hour": 11},"earliest_coverart_reveal_date": {"year": 2023,"month": 5,"day": 4,"hour": 11}}},"artist": [{"gid": "e8dba066dc3644b1b69510eb3cdd8a42","name": "Aime Simone"}],"number": 10,"disc_number": 1,"duration": 122293,"popularity": 41,"external_id": [{"type": "isrc","id": "FR9W12241433"}],"file": [{"file_id": "a0ee4ae82c323cf5e45361670079e6a68f391b2f","format": "OGG_VORBIS_320"},{"file_id": "0d508123a2197901602399756f091ba8225ff781","format": "OGG_VORBIS_160"},{"file_id": "698098f862955a08c9204e9cd723de32ad4e48e2","format": "OGG_VORBIS_96"},{"file_id": "0833e88386b0320aabcc56ab893c1ae157a5fffc","format": "MP4_256_DUAL"},{"file_id": "999bff5d82f078c4d6c12a88ee7401e6cf36c048","format": "MP4_256"},{"file_id": "cca2b23924cc42ed2b8f1efc1c95766c5f26a7c8","format": "MP4_128"},{"file_id": "f80419a11fa42bb9054ef4975bdba2a7c2226077","format": "MP4_128_DUAL"},{"file_id": "41af902734adfc123dba2bb91fa1138c7632af6c","format": "AAC_24"}],"preview": [{"file_id": "b2f08b0f87cdef5489d51588dc61e5b6fd7e5ca2","format": "MP3_96"}],"earliest_live_timestamp": 1683198000,"has_lyrics": true,"licensor": {"uuid": "1b3fb428ae7b41aa97c9b46c5b962d57"},"language_of_performance": ["en"],"original_audio": {"uuid": "87a724f901a34555a86efdc16b65ee9b"},"original_title": "Oh Yeah","artist_with_role": [{"artist_gid": "e8dba066dc3644b1b69510eb3cdd8a42","artist_name": "Aime Simone","role": "ARTIST_ROLE_MAIN_ARTIST"}],"canonical_uri": "spotify:track:0VtMV3IYHAu7fyZmqnGE99","prerelease_config": {"earliest_reveal_date": {"year": 2023,"month": 5,"day": 4,"hour": 11}}}
.
The gid
probably means something like Global ID
or something of that sort. I've done some research (python codebase, JS codebase) and found that this gid
is some hexadecimal number which needs to be converted to a base62 number to get the actual ID.
In both codebases the functions used to convert the gid
to the ID and then to an URI are called gid2id
and id2uri
.
I've tried both but they either didn't work quite well as expected, meaning they didn't give the desired result or referenced functions that weren't in the codebase, so I've decided to throw together my own quick converter in python:
def gid_to_base62(gid):
base62_charset = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
decimal_number = int(gid, 16)
base62_id = ''
while decimal_number > 0:
remainder = decimal_number % 62
base62_id = base62_charset[remainder] + base62_id
decimal_number = decimal_number // 62
return base62_id
gid = '1e763423ad0e4862b20f9dbfdadc2cb7'
base62_id = gid_to_base62(gid)
print(base62_id) # -> 0VtMV3IYHAu7fyZmqnGE99
Now I have only tested this on 2 example gid's so use this converter with caution.