├── .gitignore ├── renovate.json ├── README.md └── download-podcast.ps1 /.gitignore: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://docs.renovatebot.com/renovate-schema.json", 3 | "extends": [ 4 | "config:recommended" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Download Podcast 2 | 3 | This is a silly script I wrote to download podcasts from an RSS feed. 4 | 5 | ## PowerShell 6 | 7 | ```powershell 8 | .\download-podcast.ps1 -rssFeedUrl "https://example.com/rss" -maxRetries 3 9 | ``` 10 | -------------------------------------------------------------------------------- /download-podcast.ps1: -------------------------------------------------------------------------------- 1 | param ( 2 | [Parameter(Mandatory = $true)] 3 | [string]$rssFeedUrl, 4 | [int]$maxRetries = 3 5 | ) 6 | 7 | function Test-Url { 8 | param ( 9 | [string]$url 10 | ) 11 | return $url -match '^https?://' 12 | } 13 | 14 | function Get-PodcastEpisodes { 15 | param ( 16 | [Parameter(Mandatory = $true)] 17 | [string]$rssFeedUrl, 18 | [int]$maxRetries 19 | ) 20 | 21 | if (-not (Test-Url -url $rssFeedUrl)) { 22 | Write-Host "Invalid URL: $rssFeedUrl" 23 | return 24 | } 25 | 26 | Write-Host "Loading RSS feed from $rssFeedUrl" 27 | # Load RSS feed 28 | [xml]$rssFeed = (Invoke-WebRequest -Uri $rssFeedUrl).Content 29 | 30 | # Get podcast title and remove invalid characters for Windows 31 | $podcastTitle = $rssFeed.rss.channel.title -replace '[\\/:*?"<>|]', '' 32 | Write-Host "Podcast title: $podcastTitle" 33 | 34 | # Create directory for podcast 35 | if (-not (Test-Path -Path $podcastTitle)) { 36 | Write-Host "Creating directory for podcast: $podcastTitle" 37 | New-Item -ItemType Directory -Path $podcastTitle | Out-Null 38 | } 39 | else { 40 | Write-Host "Directory already exists: $podcastTitle" 41 | } 42 | 43 | # Download episodes 44 | $rssFeed.rss.channel.item | ForEach-Object { 45 | # Remove invalid characters from episode title 46 | $episodeTitle = $_.title -replace '[\\/:*?"<>|]', '' 47 | $episodeUrl = $_.enclosure.url 48 | $outputFile = Join-Path -Path $podcastTitle -ChildPath "$episodeTitle.mp3" 49 | 50 | if (-not (Test-Path -Path $outputFile)) { 51 | Write-Host "Downloading episode: $episodeTitle" 52 | $retryCount = 0 53 | $success = $false 54 | 55 | while (-not $success -and $retryCount -lt $maxRetries) { 56 | try { 57 | Invoke-WebRequest -Uri $episodeUrl -OutFile $outputFile 58 | Write-Host "Downloaded: $outputFile" 59 | $success = $true 60 | } 61 | catch { 62 | $retryCount++ 63 | Write-Host "Failed to download $episodeTitle. Attempt $retryCount of $maxRetries." 64 | if ($retryCount -eq $maxRetries) { 65 | Write-Host "Failed to download $episodeTitle after $maxRetries attempts." 66 | } 67 | } 68 | } 69 | } 70 | else { 71 | Write-Host "Episode already downloaded: $outputFile" 72 | } 73 | } 74 | } 75 | 76 | Write-Host "Starting podcast download process..." 77 | Get-PodcastEpisodes -rssFeedUrl $rssFeedUrl -maxRetries $maxRetries 78 | Write-Host "Podcast download process completed." 79 | --------------------------------------------------------------------------------