Files
music-tools/download_spotify.py

26 lines
911 B
Python
Executable File

import sys
from subprocess import call
import re
url_pattern = "^https?:\\/\\/(?:www\\.)?[-a-zA-Z0-9@:%._\\+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b(?:[-a-zA-Z0-9()@:%_\\+.~#?&\\/=]*)$"
def main():
if (len(sys.argv) != 2):
print("Wrong parameters!")
sys.exit(-1)
url = sys.argv[1].strip()
print("passing link " + str(url))
if (re.match(url_pattern,url) == None):
print("Url has to be a valid link!")
sys.exit(-1)
if ("spotify" not in url or "https://" not in url):
print("Url has to be a spotify link!")
sys.exit(-1)
print("executing command")
call("spotdl download " + url, shell=True, user="sem")
# call("./download-spotify.sh " + url, shell=True, user="sem") # run as user sem to have the SPOTIPY_CLIENT_ID and SPOTIPY_CLIENT_SECRET environment variables set
if __name__ == "__main__":
main()