Created
February 24, 2020 22:34
-
-
Save sinancetinkaya/b0a793762ff12823ca39eab19f91b009 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
""" | |
This code generates m3u file of a soundcloud playlist or a single track | |
""" | |
import sys | |
from sclib import SoundcloudAPI, Track, Playlist # pip3 install soundcloud-lib | |
def main(argv): | |
try: | |
# url = argv[1] | |
# or enter the url like below | |
url = input("Enter SoundCloud url:") | |
except IndexError: | |
print('Usage: soundcloud_m3u playlist/track url') | |
return False | |
api = SoundcloudAPI() | |
response = api.resolve(url) | |
if type(response) is Playlist: | |
tracks = response.tracks | |
title = response.title | |
elif type(response) is Track: | |
tracks = [response] | |
title = response.title | |
else: | |
print("unknown response") | |
return False | |
with open(f'./{title}.m3u', mode='w', encoding="utf-8") as fp: | |
line = "#EXTM3U\n" | |
print(line + "\n") | |
fp.write(line) | |
for idx, track in enumerate(tracks, 1): | |
line = f"#EXTINF:{idx}, {track.title}" | |
print(line) | |
fp.write(line + "\n") | |
line = f"{track.permalink_url}\n" | |
print(line) | |
fp.write(line + "\n") | |
if __name__ == '__main__': | |
main(sys.argv) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment