Created
April 6, 2015 14:40
-
-
Save mossbanay/b1561b407ecdf4841e68 to your computer and use it in GitHub Desktop.
Generate a m3u playlist from your latest likes on SoundCloud
This file contains hidden or 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
import soundcloud | |
import os | |
import argparse | |
client = None | |
def parse_args(): | |
parser = argparse.ArgumentParser() | |
parser.add_argument("clientid", help="Client ID from SoundCloud") | |
parser.add_argument("clientsecret", help="Client Secret from SoundCloud") | |
parser.add_argument("username", help="SoundCloud Username") | |
parser.add_argument("password", help="SoundCloud Password") | |
parser.add_argument("output", help="Output file") | |
return parser.parse_args() | |
def get_track_stream_url(track): | |
global client | |
if track.streamable: | |
url = client.get(track.stream_url, allow_redirects=False).location | |
return url | |
def main(): | |
print('Creating client ...') | |
args = parse_args() | |
global client | |
client = soundcloud.Client(client_id=args.clientid, | |
client_secret=args.clientsecret, | |
username=args.username, | |
password=args.password) | |
print('Fetching track urls ...') | |
favourited_tracks = client.get('/me/favorites') | |
stream_urls = filter(lambda x: x != None, map(get_track_stream_url, favourited_tracks)) | |
with open(args.output, 'w') as f: | |
f.write('#EXTM3U\n') | |
for url in stream_urls: | |
f.write(url + '\n') | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment