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

View of /Get-MorningSickness.ps1

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (download) (annotate)
Wed Jul 10 03:37:35 2013 UTC (7 years, 3 months ago) by ian
File size: 1830 byte(s)
Special characters now replaced to avoid download errors;
Set-StrictMode -Version Latest

$htClient = New-Object system.net.webclient
$clientId = "client_id=b45b1aa10f1ac2941910a7f0d10f8e28"
$savePath = Join-Path (Join-Path $env:USERPROFILE Downloads) "HMS Podcast"
if ( !( Test-Path $savePath ) ){ $null = New-Item -Type "Directory" -Path $savePath }


"Downloading XML Feed..."
$htXmlData = [xml]$htClient.DownloadString(
    "https://api.sndcdn.com/e1/users/22917967/sounds?limit=99&offset=0&linked_partitioning=1&" + $clientId)
$mp3Results = $htXmlData.SelectNodes("//track") | Select-Object title, download-url
"$($mp3Results.Length) records found."
Write-Debug "Debug is currently enabled!!!"

$skipCount = 0
$dlCount = 0
$procCount = 0
"Downloading Content to $($savePath)"
""
$mp3Results | ForEach-Object {
    $procCount++
    $pcntCmplt = [int][math]::round( ( $procCount / ($mp3Results.Length + 1) )*100)
    
    $saveFullName = Join-Path $savePath (($_.title -replace ":|\?|/|\\|\||\*|<|>|""", "-") + ".mp3")
    Write-Progress -Activity "Downloading..." -Status $_.title -CurrentOperation "Progress: $($pcntCmplt)%" -PercentComplete $pcntCmplt
    if ( $DebugPreference -ne "SilentlyContinue" ) {
        Write-Debug "Sleep for 1 seconds"
        Start-Sleep 1
    }
    if ( !( Test-Path $saveFullName ) ) {
        $dlCount++
        "Downloading: $($_.title).mp3"
        $htClient.DownloadFile( $_.'download-url' + "?" + $clientId, $saveFullName )
    }
    else {
        $skipCount++
        "Skipping - Already Downloaded: $($_.title).mp3"
    }
}
Write-Progress -Activity "Downloading..." -Status "Downloading Complete" -Completed
if ( $DebugPreference -ne "SilentlyContinue" ) {
    Write-Debug "Sleep for 3 seconds"
    Start-Sleep 5
}

""
"$($procCount) records | Downloaded: $($dlCount) | Skipped: $($skipCount)"
""

Contact
ViewVC Help
Powered by ViewVC 1.0.4