Skip to content

Instantly share code, notes, and snippets.

@Vocaned
Last active August 22, 2025 20:41
Show Gist options
  • Select an option

  • Save Vocaned/4f8abe2eb11b60e0089460660e692d4c to your computer and use it in GitHub Desktop.

Select an option

Save Vocaned/4f8abe2eb11b60e0089460660e692d4c to your computer and use it in GitHub Desktop.
#!/bin/env python3
# Lists each entry of a spotify list (playlist/album/artist), for yt-dlp, scrobbling etc.
from bs4 import BeautifulSoup
import re
import requests
import sys
import json
if len(sys.argv) < 2 or not sys.argv[1].startswith('https://open.spotify.com/'):
print(f'{sys.argv[0]} [spotify url]')
sys.exit(1)
url = sys.argv[1].replace('open.spotify.com/', 'embed.spotify.com/')
soup = BeautifulSoup(requests.get(url).text, features='html.parser')
j = json.loads(soup.css.select('#__NEXT_DATA__')[0].text)
entity = j['props']['pageProps']['state']['data']['entity']
if entity['type'] == 'track':
print(f"{entity['artists'][0]['name']} - {entity['name']}")
else: # TODO: explicitly check entity types, for now just assume album/artist/playlist or anything that has a trackList
tracks = []
for track in entity['trackList']:
artist = re.split(r',\s', track['subtitle'], maxsplit=1)[0]
tracks.append(f"{artist} - {track['title']}")
print('\n'.join(tracks))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment