Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Download Files from MP3 Blog?

$
0
0

Hi,

I'm fairly new to PowerShell, and I've no real background in coding or VBScript for what it's worth, but am a pretty quick learner all the same.  I have dabbled with PowerShell now and then over the years as an IT person and in the past month or two have started getting into it a lot more wondering why I've been avoiding it for so long when it's so damn cool!  In any case, as both a learning exercise, and due to actually wanting this, I'm looking for a little assistance as I'm stuck.

Basically, there's a blog that posts tracks in mp3 or wav format that I never have time to visit regularly nor listen to all of them.  I'd love to auto-download any new posts (and all past posts for that matter) which can later be synced to my music library and mobile player for listening at my leisure.

So, I started digging in and with a little sleuthing, I found that I could get all of the download links with: 

$iwr = Invoke-WebRequest http://lagasta.com
$iwr.Links | select href | where {$_.href -like "*download"}

which returned the first/main page of the blog like this:

href
----
http://soundcloud.com/smile-recordings/new-found-land-wings-edit/download
http://soundcloud.com/thehouseofdisco/monitor-66-ambient-blackbird/download
http://soundcloud.com/splendour/marathon-hannulelauri-remix/download
http://soundcloud.com/soul-button/mercury-ft-robert-owens/download
....

So far, so great!  Now, with a bit more sleuthing, I saw that "Start-BitsTransfer" was probably what I was after, so I tried piping it and got this:

PS> $iwr.Links | select href | where {$_.href -like "*download"} | foreach {start-bitstransfer $_ C:\Users\RickyBobby\Music\LaGaSta}

Which gave me:

start-bitstransfer : An incorrect value is specified in the Source parameter or in the Destination parameter. Verify 
that the directory and file names in the Source and Destination parameters are correct.

At line:1 char:73

+ $iwr.Links | select href | where {$_.href -like "*download"} | foreach {start-bi ...
+                                                                         ~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [Start-BitsTransfer], ArgumentException
    + FullyQualifiedErrorId : System.ArgumentException,Microsoft.BackgroundIntelligentTransfer.Management.NewBitsTrans
ferCommand

Hmmmm.  So I stepped back for a second and just tried one of the URLs to simplify things:

Invoke-WebRequest http://soundcloud.com/smile-recordings/new-found-land-wings-edit/download | Start-BitsTransfer -Destination C:\Users\RickyBobby\Music\LaGaSta

Which started and completed a transfer (awesome!) and then threw the following error (grrrr!) with nothing in the specified folder either:

Start-BitsTransfer : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input.

Double hmmm.  Ok, let's just see what Start-BitsTransfer does with it since it's new enough to me anyway:

Start-BitsTransfer -Source http://soundcloud.com/smile-recordings/new-found-land-wings-edit/download -Destination C:\Users\RickyBobby\Music\LaGaSta

That downloaded a file called "download" to the directory specified.  Ummmm, ok.  We're close.  Sorta.  

Then I visited the link in a browser just to see what I got - which was a "save file" dialog with the file name pre-populated - as expected.  Nothing special there really.  Comparing sizes from the PowerShell download with the browser download, all looked to be the same.  So, basically, PowerShell doesn't know what it transferred, just that it was told to do so it appears.  Right?  I then went through the help file and examples on Start-BitsTransfer but didn't see anything that helped me much or pointed me in the right direction in relation to extracting the file name or type and saving it as such.  I've found examples of people doing it with direct linked filenames, but in this case . . . nothing so far.

Annnnd, that's where I'm stuck.  Any pointers on what the errors mean (google wasn't helpful really) and how I achieve what I'm after?

Thanks in advance.


Viewing all articles
Browse latest Browse all 6937

Trending Articles