Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import requests
- import xml.etree.ElementTree as ET
- import subprocess
- # Define the URL of the RSS feed
- rss_url = "https://feeds.buzzsprout.com/258846.rss"
- # Define headers with a custom user-agent to avoid blocking
- 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.36"
- }
- # Fetch the RSS feed with custom headers to avoid blocking
- try:
- response = requests.get(rss_url, headers=headers, timeout=10)
- # Check if the request was successful
- if response.status_code != 200:
- print(f"Failed to fetch the RSS feed. HTTP Status Code: {response.status_code}")
- exit(1)
- except requests.exceptions.RequestException as e:
- print(f"An error occurred while fetching the RSS feed: {e}")
- exit(1)
- # Parse the XML content of the RSS feed
- root = ET.fromstring(response.content)
- # Define the folder to save podcasts
- download_folder = "podcasts"
- if not os.path.exists(download_folder):
- os.makedirs(download_folder)
- # Loop through each item in the RSS feed and extract the audio URL
- for item in root.findall(".//item"):
- # Look for the <enclosure> tag and extract the 'url' attribute
- enclosure = item.find("enclosure")
- if enclosure is not None:
- audio_url = enclosure.get("url")
- if audio_url and audio_url.endswith(".mp3"): # Check if it's an mp3 file
- # Get the podcast file name from the URL
- file_name = os.path.join(download_folder, audio_url.split("/")[-1])
- # Download the file using wget
- print(f"Downloading {file_name}...")
- subprocess.run(["wget", audio_url, "-O", file_name])
- print("Download complete.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement