File size: 1,646 Bytes
cef39e3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
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)
|