Friday, October 16, 2015

Download MP3s with Powershell

So I found a site with some MP3s that I wanted but didn't want to download but didn't want to right click.. Save as.. blah blah.. so after some searching and modifing some scripts i made this.


Change the 2 variables $theurl ; the website URL, and $storagedir ; the place you want to store them and watch it go. It has some thing built into it that takes care of url variables, direct url, and some url encoding issues. I tried to comment it as much as I could.


# =================================================================================
# =                                                                               =
# =                       Variables to change. Begin                              =
# =                                                                               =
# =================================================================================


$theurl = "http://www.sky-animes.com/music/LQ/7185"
$storagedir = "C:\source\mp3\FullMetal"


# =================================================================================
# =                                                                               =
# =                      Variables to change. End                                 =
# =                                                                               =
# =================================================================================



$response = Invoke-WebRequest -Uri $theurl  -UseBasicParsing -Verbose
$links = $response.Links
$imgurlinks = @()
$webclient = New-Object System.Net.WebClient

Write-Output "-------------------------------------------------------------------------"
Write-Output "-------------------------------------------------------------------------"

$response.Links.href


Write-Output "-------------------------------------------------------------------------"
Write-Output "-------------------------------------------------------------------------"



md $storagedir -ErrorAction SilentlyContinue

ForEach ($link in $links){ #loop through all the hrefs on the page with a ForEach

    $href = $link.href #put the href to Variable.


    if ($href -like "*.mp3" ) { #Look for only mp3's hrefs
    
        $filename = $href.Split("/")[-1]
        #Write-Output "Href: " $href
        #Write-Output "FileName: " $filename
       
        if ($filename -like "*?*"){ #does the filename have a query?
            $filename2 = $filename.Split("?")[0] #make the filename2 the filename without any queries
        } #End If
        else{
            $filename2 = $filename #since no queries were found just make the filename2 the name of the orginal filename
        } # End Else
       


        if($href -contains "http://"){ #does the href have a direct path to the file? if not lets try and add in the orignating url to it so it can find it.
            $newhref = $href #No need to mess with the href.. just pass it to the newhref and move along.
        } #End http:// if
       
        else{
            $newhref = $theurl + "\" + $href #put together theUrl and the Href to make a path to try.
        } #End http:// else

       
        $newFile = $filename2.Replace("%20","-") # Replace %20 url encoded spaces with an Underscore for the new mp3 file.
        $newFile = $newFile.Replace("&","-and-") # Replace & url encoded spaces with an "-and-" for the new mp3 file.
        $newFile = $newFile.Replace("---","-") # Replace & url encoded spaces with an "-and-" for the new mp3 file.
      
     

        $newFile = "$storagedir\$newFile" #put together the path and the file of where to put the file when downloaded.

        $newhref = $newhref.Replace("&","&")


        Write-Output "Href Location: " $newhref
        Write-Output "Download Location: " $newFile

        $webclient.DownloadFile($newhref,$newFile) #download the file using the href and the file we just put together above.

    } #end MP3 If.
} #end ForEach


       
explorer $storagedir #open the output folder








3 comments:

  1. My Admin Journal: Mp3S With Powershell >>>>> Download Now

    >>>>> Download Full

    My Admin Journal: Mp3S With Powershell >>>>> Download LINK

    >>>>> Download Now

    My Admin Journal: Mp3S With Powershell >>>>> Download Full

    >>>>> Download LINK ea

    ReplyDelete