Last active
August 10, 2020 20:16
-
-
Save akleemans/e1de3548484e037d0bd419ad6cedfe6d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
'''Download the current Spotify Top 50 from Youtube.''' | |
import urllib.request | |
import subprocess | |
# fetch charts | |
print('Downloading charts...') | |
req = urllib.request.Request('https://spotifycharts.com/regional/global/weekly/latest/download', headers={'User-Agent': 'Mozilla/5.0'}) | |
with urllib.request.urlopen(req) as page: | |
charts = page.read().decode('utf-8') | |
for row in charts.split('\n')[2:52]: | |
title = row.split(',')[2] + ' - ' + row.split(',')[1] | |
title = title.replace('"', '') | |
print('Searching for:', title) | |
title = urllib.parse.quote(title) | |
content = urllib.request.urlopen('http://www.youtube.com/results?search_query=' + title).read().decode('utf-8') | |
yt_link = content.split('"videoId":"')[1].split('"')[0] | |
download_query = 'youtube-dl --extract-audio --audio-format mp3 https://www.youtube.com/watch?v=' + yt_link | |
subprocess.run(download_query.split()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment