Skip to content

Instantly share code, notes, and snippets.

@kyujin-cho
Last active July 23, 2017 09:42
Show Gist options
  • Select an option

  • Save kyujin-cho/b2b348a8984157c769a8b9ce2d98a141 to your computer and use it in GitHub Desktop.

Select an option

Save kyujin-cho/b2b348a8984157c769a8b9ce2d98a141 to your computer and use it in GitHub Desktop.
Soundcloud Downloader
import re
import urllib.request
import os
import os.path
import subprocess
p = re.compile('https:\/\/.+')
l = open('playlist.m3u8', 'r').read()
result = p.findall(l)
if not os.path.exists('output'):
os.makedirs('output')
i = 0
try:
for file in result:
i += 1
print('downloading #', i, 'of', len(result), '...')
with open('output/' + str(i) + '.mp3', 'wb') as f:
mp3 = urllib.request.urlopen(file)
f.write(mp3.read())
except:
print('M3U8 file too old! Try with a newer one.')
exit()
print('calling', ['mp3cat', '-o', 'output/result.mp3'] + ['output/' + str(j) + '.mp3' for j in range(1, i + 1)])
subprocess.call(['mp3cat', '-o', 'output/result.mp3'] + ['output/' + str(j) + '.mp3' for j in range(1, i + 1)])
@kyujin-cho

kyujin-cho commented Jul 23, 2017

Copy link
Copy Markdown
Author

Developed for macOS/Linux
Prequisites
- mp3cat installed

How-to
1. Download m3u8 file from soundcloud page, save it as 'playlist.m3u8' and place it in the same folder of the script
2. Run script
3. Your file is in the output folder, named result.mp3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment