import os import pandas as pd import requests df=pd.read_csv("MR_Words.csv") def download_audio_from_dataframe(df, url_column, folder_path): for index, row in df.iterrows(): audio_url = row[url_column] if pd.notna(audio_url) and isinstance(audio_url, str): file_name = os.path.basename(audio_url) try: # Create the folder if it doesn't exist os.makedirs(folder_path, exist_ok=True) # Combine folder path and file name to get the full path full_path = os.path.join(folder_path, file_name) # Send a GET request to the URL response = requests.get(audio_url) # Check if the request was successful (status code 200) if response.status_code == 200: # Open a local file and write the content of the response with open(full_path, 'wb') as audio_file: audio_file.write(response.content) print(f"Audio file downloaded successfully to {full_path}") else: print(f"Failed to download audio file. Status code: {response.status_code}") except Exception as e: print(f"Error: {e}") print(file_name) continue # Example usage # Assuming you have a DataFrame named 'df' with a column 'audio_links' containing URLs with filenames # Specify the column name url_column_name = 'recordingserverurl' # Specify the download folder download_folder = 'path_to/Marathi/words' # Call the function to download audio files download_audio_from_dataframe(df, url_column_name, download_folder)