Skip to content

Commit d53cd50

Browse files
authored
Create Download-Channl9VideosFromRSS.ps1
1 parent c94cf82 commit d53cd50

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
Param (
2+
[Parameter(Mandatory=$true)]
3+
[string]
4+
$RssUrl,
5+
6+
[ValidateScript({Test-Path $_ -PathType 'Container'})]
7+
[string]
8+
$DownloadFolder = '.\'
9+
)
10+
11+
Push-Location $DownloadFolder
12+
13+
$WebClient = New-Object System.Net.WebClient
14+
15+
Write-Output 'Downloading RSS feed...'
16+
try {
17+
$RSSWebObject = ([xml]($WebClient).downloadstring($RssUrl))
18+
}
19+
catch {
20+
throw
21+
break
22+
}
23+
24+
$counter=0;
25+
foreach ($item in $RSSWebObject.rss.channel.item) {
26+
$counter++
27+
28+
if ($null -eq $item.enclosure.url) {
29+
Write-Output $('{0:D2}: No URL found)' -f $counter)
30+
continue
31+
}
32+
$url = New-Object System.Uri($item.enclosure.url) -ErrorAction Stop
33+
$FileName = '{0:D2}. {1}' -f $counter,$url.Segments[-1]
34+
35+
Write-Output $FileName
36+
if (!(Test-Path $FileName)) {
37+
# $WebClient.DownloadFile($url, $FileName)
38+
Invoke-WebRequest -Uri $url -OutFile $FileName -ErrorAction Stop
39+
}
40+
}
41+
42+
Pop-Location

0 commit comments

Comments
 (0)