Skip to content

Instantly share code, notes, and snippets.

@bunnykek
Last active April 18, 2022 09:57
Show Gist options
  • Save bunnykek/c9e7ff0e425c1c912a77e8b75ba1ed2d to your computer and use it in GitHub Desktop.
Save bunnykek/c9e7ff0e425c1c912a77e8b75ba1ed2d to your computer and use it in GitHub Desktop.
Exports Apple-Music playlist into unique_album_links_list.txt
# mini script by bunny
# exports apple-music playlist into unique_albums_list.txt
import requests
import re
headers = {
'authorization': 'Bearer eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IldlYlBsYXlLaWQifQ'
'.eyJpc3MiOiJBTVBXZWJQbGF5IiwiaWF0IjoxNjQ0OTQ5MzI0LCJleHAiOjE2NjA1MDEzMjR9.3RUn173ddFRpam0ksOFS'
'-vJFR-wCtJHzcSdGr7exxFQScWxzQxHGht4wyt6iJQqNcEOR4BRmv6O4-2B4jzrGsQ',
'origin': 'https://music.apple.com',
}
reg = re.compile('https://music.apple.com/\w{2}/album/.+?/(\d+)')
if __name__ == "__main__":
playlist_Id = str(input("Enter the AppleMusic playlist ID : "))
albums_list = []
url = f'https://api.music.apple.com/v1/catalog/us/playlists/{playlist_Id}/tracks'
while 1:
response = requests.get(url, headers=headers)
temp = re.findall(reg, response.text)
albums_list += set(temp)
if 'next' in response.json():
url = 'https://api.music.apple.com'+response.json()['next']
else:
break
albums_list = set(albums_list)
fileName = f"{len(albums_list)}_albums.txt"
file = open(fileName, 'w')
for link in albums_list:
file.write("https://music.apple.com/us/album/_/"+ link + "\n")
file.close()
print(fileName)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment