CoolFace
Apppublic

Abd756/StemSense

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
standalone_test.py50 linesDownload Raw Back to root
1import subprocess2import os3 4def download_by_name(song_name):5    """6    Standalone script to test spotDL downloading by song name.7    This does not explicitly use our Spotify API credentials.8    """9    print(f"\n--- Standalone spotDL Test ---")10    print(f"Task: Search and Download '{song_name}'")11    12    # Create a local test folder13    test_dir = os.path.join(os.getcwd(), "test_downloads")14    if not os.path.exists(test_dir):15        os.makedirs(test_dir)16        print(f"Created directory: {test_dir}")17 18    try:19        # spotdl can take a search query directly20        # Format: spotdl download "Song Name"21        command = [22            "spotdl",23            "download",24            song_name,25            "--output",26            os.path.join(test_dir, "{title} - {artist}.{output-ext}")27        ]28        29        print("Executing command: " + " ".join(command))30        print("Please wait, searching YouTube...\n")31        32        # We run this so you can see the progress bar in the terminal33        subprocess.run(command, check=True)34        35        print(f"\n[SUCCESS] Download completed!")36        print(f"Check the folder: {test_dir}")37        38    except subprocess.CalledProcessError as e:39        print(f"\n[ERROR] spotDL failed with return code {e.returncode}")40        print("This may be due to network issues or rate limits on YouTube/Spotify.")41    except Exception as e:42        print(f"\n[ERROR] Unexpected error: {e}")43 44if __name__ == "__main__":45    query = input("Enter song name (e.g. 'Stairway to Heaven'): ")46    if query.strip():47        download_by_name(query)48    else:49        print("No song name entered.")50