Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- import os
- def download_mp3s(download_folder='downloadfree', log_file='free_log.txt'):
- input_file = 'free-output.txt' # Name of the file containing MP3 URLs
- headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'}
- # Create the download folder if it doesn't exist
- if not os.path.exists(download_folder):
- os.makedirs(download_folder)
- with open(input_file, 'r', encoding='utf-8') as file:
- mp3_urls = file.readlines()
- with open(log_file, 'w', encoding='utf-8') as log:
- for url in mp3_urls:
- url = url.strip() # Remove any extra whitespace
- file_name = url.split('/')[-1] # Extract the file name from the URL
- try:
- response = requests.get(url, stream=True, headers=headers)
- response.raise_for_status()
- file_path = os.path.join(download_folder, file_name)
- with open(file_path, 'wb') as f:
- for chunk in response.iter_content(chunk_size=8192):
- f.write(chunk)
- log.write(f"Downloaded: {url}\n")
- print(f"Downloaded: {url}")
- except Exception as e:
- log.write(f"Failed to download {url}: {e}\n")
- print(f"Failed to download {url}: {e}")
- if __name__ == "__main__":
- download_mp3s()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement