53 lines
1.7 KiB
Python
53 lines
1.7 KiB
Python
import subprocess
|
|
import sys
|
|
|
|
url = "https://soundcloud.com/"
|
|
path = "musicbya/sets/13th-dec-crash-out"
|
|
|
|
command_link = url + path
|
|
|
|
dl_path = "/Users/azeem/repos/sc-audio-downloader/audio/13-DEC-CO-SC"
|
|
|
|
# run command scdl -l command_link --path dl_path in command line, log output constantly into python terminal
|
|
|
|
def run_scdl_with_output():
|
|
"""Run scdl command and stream output to terminal"""
|
|
command = ["scdl", "-l", command_link, "--path", dl_path, "--flac", "--name-format", "%(playlist_index)s - %(title)s.%(ext)s"]
|
|
|
|
print(f"Running command: {' '.join(command)}")
|
|
print("-" * 50)
|
|
|
|
try:
|
|
# Use subprocess.Popen to get real-time output
|
|
process = subprocess.Popen(
|
|
command,
|
|
stdout=subprocess.PIPE,
|
|
stderr=subprocess.STDOUT,
|
|
universal_newlines=True,
|
|
bufsize=1
|
|
)
|
|
|
|
# Stream output line by line
|
|
for line in process.stdout:
|
|
print(line.rstrip())
|
|
sys.stdout.flush() # Ensure immediate output
|
|
|
|
# Wait for process to complete and get return code
|
|
return_code = process.wait()
|
|
|
|
if return_code == 0:
|
|
print("\n" + "=" * 50)
|
|
print("Download completed successfully!")
|
|
else:
|
|
print(f"\n" + "=" * 50)
|
|
print(f"Command failed with return code: {return_code}")
|
|
|
|
except FileNotFoundError:
|
|
print("Error: scdl command not found. Make sure it's installed and in your PATH.")
|
|
print("You can install it with: pip install scdl")
|
|
except Exception as e:
|
|
print(f"An error occurred: {e}")
|
|
|
|
if __name__ == "__main__":
|
|
run_scdl_with_output()
|