fix this scippt : import os
import subprocess
import shutil
import tempfile
from basic_pitch import ICASSP_2022_MODEL_PATH
from basic_pitch.inference import predict_and_save

def download_song_from_spotify(song_query):
    """Download song from Spotify using spotdl."""
    tmpdirname = tempfile.mkdtemp()
    try:
        print("Downloading song...")
        # Corrected the placeholder to {output-ext}
        output_template = os.path.join(tmpdirname, 'downloaded_song.{output-ext}')
        
        # Use spotdl to download the song to the temporary directory
        subprocess.run([
            'spotdl', 'download', song_query,
            '--output', output_template
        ], check=True)
        
        # Look for the downloaded song in the temporary directory
        # Fetch the correct file extension
        downloaded_files = os.listdir(tmpdirname)
        if downloaded_files:
            song_file = os.path.join(tmpdirname, downloaded_files[0])
            return song_file, tmpdirname  # Return the song path and temp directory
        else:
            print("Failed to download song.")
            return None, tmpdirname
    except subprocess.CalledProcessError as e:
        print(f"An error occurred while downloading the song: {e}")
        return None, tmpdirname

def audio_to_midi_with_basic_pitch(audio_file, output_dir):
    """Convert audio file to MIDI using Basic Pitch."""
    if not os.path.exists(audio_file):
        print(f"Error: Audio file {audio_file} not found.")
        return
    
    try:
        # Run inference and save MIDI file
        predict_and_save(
            [audio_file],               # List of audio files
            output_directory=output_dir,  # Where to save outputs
            save_midi=True,             # Save the MIDI file
            sonify_midi=False,          # Disable sonification
            save_model_outputs=False,   # Skip saving model outputs
            save_notes=False,           # Skip saving detected notes
            model_or_model_path=ICASSP_2022_MODEL_PATH  # The model used for inference
        )
        print("Conversion complete. MIDI file saved.")
    except Exception as e:
        print(f"An error occurred during audio to MIDI conversion: {e}")
        
# ---- Main Program ----
if __name__ == "__main__":
    song_query = input("Enter the song title or Spotify link: ")

    # Step 1: Download the song
    downloaded_song, tmpdirname = download_song_from_spotify(song_query)

    if downloaded_song:
        # Step 2: Convert audio to MIDI
        current_dir = os.getcwd()
        print("Converting audio to MIDI...")
        audio_to_midi_with_basic_pitch(downloaded_song, current_dir)

        # Clean up: Remove the temporary directory containing the downloaded song
        if os.path.exists(tmpdirname):
            shutil.rmtree(tmpdirname)
    else:
        print("Failed to download the song.") ,,,because this error : Downloading song...
Processing query:
https://open.spotify.com/track/3KrCsMdvkOI9mxbXiCjCuN?si=405c73ea3b6e48b1
FFmpegError: Failed to convert Mofe. - prince of egypt (Slowed Down), you can find error
here: C:\Users\ZILA\.spotdl\errors\ffmpeg_error_2024-10-01-17-53-47.txt
                                                                                        
Failed to download song.
Failed to download the song.,, output file is this : ### return_code:
3165764104

### arguments:
['-nostdin', '-y', '-i', 'C:\\Users\\ZILA\\.spotdl\\temp\\QLctCeVaNSw.webm', '-movflags', '+faststart', '-v', 'debug', '-progress', '-', '-nostats', '-codec:a', 'libmp3lame', '-b:a', '129k', 'C:\\Users\\ZILA\\AppData\\Local\\Temp\\tmpxh7g1lyh\\downloaded_song.mp3']

### ffmpeg:
ffmpeg

### version:
7.1

### build_year:
2024

### error:
ffmpeg version 7.1 Copyright (c) 2000-2024 the FFmpeg developers
built with clang version 19.1.0
configuration: --prefix=/d/bld/ffmpeg_1727723574466/_h_env/Library --cc=clang.exe --cxx=clang++.exe --nm=llvm-nm --ar=llvm-ar --disable-doc --enable-openssl --enable-demuxer=dash --enable-hardcoded-tables --enable-libfreetype --enable-libharfbuzz --enable-libfontconfig --enable-libopenh264 --enable-libdav1d --ld=lld-link --target-os=win64 --enable-cross-compile --toolchain=msvc --host-cc=clang.exe --extra-libs=ucrt.lib --extra-libs=vcruntime.lib --extra-libs=oldnames.lib --strip=llvm-strip --disable-stripping --host-extralibs= --disable-libopenvino --enable-gpl --enable-libx264 --enable-libx265 --enable-libaom --enable-libsvtav1 --enable-libxml2 --enable-pic --enable-shared --disable-static --enable-version3 --enable-zlib --enable-libopus --pkg-config=/d/bld/ffmpeg_1727723574466/_build_env/Library/bin/pkg-config
libavutil      59. 39.100 / 59. 39.100
libavcodec     61. 19.100 / 61. 19.100
libavformat    61.  7.100 / 61.  7.100
libavdevice    61.  3.100 / 61.  3.100
libavfilter    10.  4.100 / 10.  4.100
libswscale      8.  3.100 /  8.  3.100
libswresample   5.  3.100 /  5.  3.100
libpostproc    58.  3.100 / 58.  3.100
Splitting the commandline.
Reading option '-nostdin' ... matched as option 'stdin' (enable or disable interaction on standard input) with argument 0.
Reading option '-y' ... matched as option 'y' (overwrite output files) with argument '1'.
Reading option '-i' ... matched as input url with argument 'C:\Users\ZILA\.spotdl\temp\QLctCeVaNSw.webm'.
Reading option '-movflags' ... matched as AVOption 'movflags' with argument '+faststart'.
Reading option '-v' ... matched as option 'v' (set logging level) with argument 'debug'.
Reading option '-progress' ... matched as option 'progress' (write program-readable progress information) with argument '-'.
Reading option '-nostats' ... matched as option 'stats' (print progress report during encoding) with argument 0.
Reading option '-codec:a' ... matched as option 'codec' (alias for -c (select encoder/decoder)) with argument 'libmp3lame'.
Reading option '-b:a' ... matched as option 'b' (video bitrate (please use -b:v)) with argument '129k'.
Reading option 'C:\Users\ZILA\AppData\Local\Temp\tmpxh7g1lyh\downloaded_song.mp3' ... matched as output url.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option nostdin (enable or disable interaction on standard input) with argument 0.
Applying option y (overwrite output files) with argument 1.
Applying option v (set logging level) with argument debug.
Applying option progress (write program-readable progress information) with argument -.
[pipe @ 0000025E33A4C480] Setting default whitelist 'crypto,data'
Applying option nostats (print progress report during encoding) with argument 0.
Successfully parsed a group of options.
Parsing a group of options: input url C:\Users\ZILA\.spotdl\temp\QLctCeVaNSw.webm.
Successfully parsed a group of options.
Opening an input file: C:\Users\ZILA\.spotdl\temp\QLctCeVaNSw.webm.
[AVFormatContext @ 0000025E33AABF00] Opening 'C:\Users\ZILA\.spotdl\temp\QLctCeVaNSw.webm' for reading
[file @ 0000025E33A4CCC0] Setting default whitelist 'file,crypto,data'
[matroska,webm @ 0000025E33AABF00] Format matroska,webm probed with size=2048 and score=100
st:0 removing common factor 1000000 from timebase
[matroska,webm @ 0000025E33AABF00] Before avformat_find_stream_info() pos: 532 bytes read:32768 seeks:0 nb_streams:1
Transform tree:
mdct_inv_float_avx2 - type: mdct_float, len: 120, factors[2]: [2, any], flags: [aligned, out_of_place, inv_only]
fft_pfa_15xM_asm_float_avx2 - type: fft_float, len: 60, factors[2]: [15, 2], flags: [aligned, inplace, out_of_place, preshuf, asm_call]
fft4_fwd_asm_float_sse2 - type: fft_float, len: 4, factor: 2, flags: [aligned, inplace, out_of_place, preshuf, asm_call]
Transform tree:
mdct_inv_float_avx2 - type: mdct_float, len: 240, factors[2]: [2, any], flags: [aligned, out_of_place, inv_only]
fft_pfa_15xM_asm_float_avx2 - type: fft_float, len: 120, factors[2]: [15, 2], flags: [aligned, inplace, out_of_place, preshuf, asm_call]
fft8_asm_float_avx - type: fft_float, len: 8, factor: 2, flags: [aligned, inplace, out_of_place, preshuf, asm_call]
Transform tree:
mdct_inv_float_avx2 - type: mdct_float, len: 480, factors[2]: [2, any], flags: [aligned, out_of_place, inv_only]
fft_pfa_15xM_asm_float_avx2 - type: fft_float, len: 240, factors[2]: [15, 2], flags: [aligned, inplace, out_of_place, preshuf, asm_call]
fft16_asm_float_fma3 - type: fft_float, len: 16, factor: 2, flags: [aligned, inplace, out_of_place, preshuf, asm_call]
Transform tree:
mdct_inv_float_avx2 - type: mdct_float, len: 960, factors[2]: [2, any], flags: [aligned, out_of_place, inv_only]
fft_pfa_15xM_asm_float_avx2 - type: fft_float, len: 480, factors[2]: [15, 2], flags: [aligned, inplace, out_of_place, preshuf, asm_call]
fft32_asm_float_fma3 - type: fft_float, len: 32, factor: 2, flags: [aligned, inplace, out_of_place, preshuf, asm_call]
[opus @ 0000025E33ABEAC0] skip 312/960 samples
[matroska,webm @ 0000025E33AABF00] All info found
[matroska,webm @ 0000025E33AABF00] After avformat_find_stream_info() pos: 1118 bytes read:32768 seeks:0 frames:1
Input #0, matroska,webm, from 'C:\Users\ZILA\.spotdl\temp\QLctCeVaNSw.webm':
Metadata:
encoder         : google/video-file
Duration: 00:02:34.48, start: -0.007000, bitrate: 129 kb/s
Stream #0:0(eng), 1, 1/1000: Audio: opus, 48000 Hz, stereo, fltp, delay 312 (default)
Successfully opened the file.
Parsing a group of options: output url C:\Users\ZILA\AppData\Local\Temp\tmpxh7g1lyh\downloaded_song.mp3.
Applying option codec:a (alias for -c (select encoder/decoder)) with argument libmp3lame.
Applying option b:a (video bitrate (please use -b:v)) with argument 129k.
Successfully parsed a group of options.
Opening an output file: C:\Users\ZILA\AppData\Local\Temp\tmpxh7g1lyh\downloaded_song.mp3.
[out#0/mp3 @ 0000025E33A83400] No explicit maps, mapping streams automatically...
[aost#0:0 @ 0000025E33A8D080] Unknown encoder 'libmp3lame'
[aost#0:0 @ 0000025E33A8D080] Error selecting an encoder
Error opening output file C:\Users\ZILA\AppData\Local\Temp\tmpxh7g1lyh\downloaded_song.mp3.
Error opening output files: Encoder not found
[AVIOContext @ 0000025E33A53940] Statistics: 32768 bytes read, 0 seeks