Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $ErrorActionPreference = "Continue"
- function wait-ie {
- do {
- Start-Sleep -Milliseconds 5000
- }
- while($ie.Busy)
- }
- function downloadFile($url, $targetFile) {
- $uri = New-Object "System.Uri" "$url"
- $request = [System.Net.HttpWebRequest]::Create($uri)
- $request.set_Timeout(15000) #15 second timeout
- $response = $request.GetResponse()
- $totalLength = [System.Math]::Floor($response.get_ContentLength()/1024)
- $responseStream = $response.GetResponseStream()
- $targetStream = New-Object -TypeName System.IO.FileStream -ArgumentList $targetFile, Create
- $buffer = new-object byte[] 10KB
- $count = $responseStream.Read($buffer,0,$buffer.length)
- $downloadedBytes = $count
- while ($count -gt 0) {
- $targetStream.Write($buffer, 0, $count)
- $count = $responseStream.Read($buffer,0,$buffer.length)
- $downloadedBytes = $downloadedBytes + $count
- Write-Progress -activity "Downloading file '$($url.split('/') | Select -Last 1)'" -status "Downloaded ($([System.Math]::Floor($downloadedBytes/1024))K of $($totalLength)K): " -PercentComplete ((([System.Math]::Floor($downloadedBytes/1024)) / $totalLength) * 100)
- }
- Write-Progress -activity "Finished downloading file '$($url.split('/') | Select -Last 1)'"
- $targetStream.Flush()
- $targetStream.Close()
- $targetStream.Dispose()
- $responseStream.Dispose()
- }
- function next-song {
- do {
- Start-Sleep -Milliseconds 5000
- If($ie.Document.getElementById("still_listening_ignore") -ne $null) {
- $ie.Document.getElementById("still_listening_ignore").click()
- }
- }
- while($songName -eq ($ie.Document.body.getElementsByClassName("songTitle") | Select-Object -ExpandProperty innerText))
- If($ie.Document.getElementById("still_listening_ignore") -ne $null) {
- $ie.Document.getElementById("still_listening_ignore").click()
- }
- $songName = $ie.Document.body.getElementsByClassName("songTitle") | Select-Object -ExpandProperty innerText
- $songArtist = $ie.Document.body.getElementsByClassName("artistSummary") | Select-Object -ExpandProperty innerText
- # element ID is jp_audio_1 for Pandora One
- $songDownload = $ie.Document.getElementById("jp_audio_0") | Select-Object -ExpandProperty src
- $filePath = $directory + $songArtist + ' - ' + $songName + '.m4a'
- If(!(Test-Path $filePath)) {
- Write-Host "Downloading $songName by $songArtist" -ForegroundColor Green
- downloadFile -url $songDownload -targetFile $filePath
- }
- Else {
- Write-Host "Already downloaded $songName by $songArtist" -ForegroundColor Yellow
- }
- next-song
- }
- $directory = "<directory>\" # must have a slash at the end
- $height = [System.Windows.Forms.Screen]::PrimaryScreen.WorkingArea.Height
- $width = [System.Windows.Forms.Screen]::PrimaryScreen.WorkingArea.Width/2
- $ie = new-object -com "InternetExplorer.Application"
- $ie.navigate("http://www.pandora.com/")
- wait-ie
- $ie.visible = $true
- $ie.Top = 0
- $ie.Left = $width.ToString()
- $ie.Width = $width.ToString()
- $ie.Height = $height.ToString()
- next-song
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement