-
Notifications
You must be signed in to change notification settings - Fork 0
/
MST3KSeason0Downloader.ps1
72 lines (63 loc) · 2.57 KB
/
MST3KSeason0Downloader.ps1
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
###Suppress Progress bar because it significantly slows downloading in PS 5 and lower###
$ProgressPreference = 'SilentlyContinue'
###Get web links as Chrome###
$agent = ([Microsoft.PowerShell.Commands.PSUserAgent]::Chrome)
###Get all links on the webpage###
$mst3k = iwr 'https://archive.org/details/mst3k_season_0' -UseBasicParsing -UserAgent $agent
###Get all mp4 links###
$links=$mst3k.links.href | where {$_ -like "*.mp4"}
###Where you want the files stored###
Add-Type -AssemblyName System.Windows.Forms
$FolderBrowser = New-Object System.Windows.Forms.FolderBrowserDialog
$FolderBrowser.Description = 'Select a folder'
$FolderBrowser.RootFolder = "MyComputer"
$FolderBrowser.SelectedPath = "$env:USERPROFILE\Downloads"
$FolderBrowser.ShowDialog()
$dest = $FolderBrowser.SelectedPath
###Create containing folder if necessary###
if($dest -notlike "*\MST3K"){
$newfolder = New-Item "$dest\MST3K" -ItemType Directory -Force
$dest = $newfolder.FullName
}
###Download all video files with the above links/parameters###
Foreach($link in $links){
###Set each video's variables###
$decode = [System.Web.HttpUtility]::UrlDecode($link)
$title = ($decode -split ' - ')[-1]
$episode = ($decode -split ' - ')[1].Replace('K','0x')
$filename = "MST3K - $episode - $title"
$season = 'Specials'
$seasonfolder = New-Item "$dest\$season" -ItemType Directory -Force | select -ExpandProperty Fullname
###Create folder if not present###
if(!(Test-Path "$dest\$season")){
@"
****************************
*********$($season.toupper())**********
****************************
"@
}
###Download file if not present###
if(!(Test-Path "$seasonFolder\$fileName")){
###Counter for retries as sometimes archive.org does rate limit and we just try again###
$count = 0
###Loop the download until the file is present or retries up to 30 times###
Do{
try{
"Downloading $filename"
$null = Iwr "https://archive.org$link" -OutFile "$seasonFolder\$fileName" -UseBasicParsing -UserAgent $agent
"Download SUCCESSFUL"
} catch {
if($count -lt 30){
"Download FAILED...Retrying in 60 seconds"
Start-Sleep -Seconds 60
} else {
"Download FAILED...Moving on to next episode"
$_
}
}
$count++
} until ((Test-Path "$seasonFolder\$fileName") -or $count -ge 30)
} else {
"Already downloaded $filename"
}
}