[PowerShell] / Get-MorningSickness.ps1 Repository:
ViewVC logotype

Annotation of /Get-MorningSickness.ps1

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (view) (download)

1 : ian 1 Set-StrictMode -Version Latest
2 :    
3 :     $htClient = New-Object system.net.webclient
4 :     $clientId = "client_id=b45b1aa10f1ac2941910a7f0d10f8e28"
5 :     $savePath = Join-Path (Join-Path $env:USERPROFILE Downloads) "HMS Podcast"
6 :     if ( !( Test-Path $savePath ) ){ $null = New-Item -Type "Directory" -Path $savePath }
7 :    
8 :    
9 :     "Downloading XML Feed..."
10 :     $htXmlData = [xml]$htClient.DownloadString(
11 :     "https://api.sndcdn.com/e1/users/22917967/sounds?limit=99&offset=0&linked_partitioning=1&" + $clientId)
12 :     $mp3Results = $htXmlData.SelectNodes("//track") | Select-Object title, download-url
13 :     "$($mp3Results.Length) records found."
14 :     Write-Debug "Debug is currently enabled!!!"
15 :    
16 :     $skipCount = 0
17 :     $dlCount = 0
18 :     $procCount = 0
19 :     "Downloading Content to $($savePath)"
20 :     ""
21 :     $mp3Results | ForEach-Object {
22 :     $procCount++
23 :     $pcntCmplt = [int][math]::round( ( $procCount / ($mp3Results.Length + 1) )*100)
24 :    
25 : ian 2 $saveFullName = Join-Path $savePath (($_.title -replace ":|\?|/|\\|\||\*|<|>|""", "-") + ".mp3")
26 : ian 1 Write-Progress -Activity "Downloading..." -Status $_.title -CurrentOperation "Progress: $($pcntCmplt)%" -PercentComplete $pcntCmplt
27 :     if ( $DebugPreference -ne "SilentlyContinue" ) {
28 :     Write-Debug "Sleep for 1 seconds"
29 :     Start-Sleep 1
30 :     }
31 :     if ( !( Test-Path $saveFullName ) ) {
32 :     $dlCount++
33 :     "Downloading: $($_.title).mp3"
34 :     $htClient.DownloadFile( $_.'download-url' + "?" + $clientId, $saveFullName )
35 :     }
36 :     else {
37 :     $skipCount++
38 :     "Skipping - Already Downloaded: $($_.title).mp3"
39 :     }
40 :     }
41 :     Write-Progress -Activity "Downloading..." -Status "Downloading Complete" -Completed
42 :     if ( $DebugPreference -ne "SilentlyContinue" ) {
43 :     Write-Debug "Sleep for 3 seconds"
44 :     Start-Sleep 5
45 :     }
46 :    
47 :     ""
48 :     "$($procCount) records | Downloaded: $($dlCount) | Skipped: $($skipCount)"
49 :     ""

Contact
ViewVC Help
Powered by ViewVC 1.0.4