Wallpaper Downloader

0
  • Version
  • Download
  • File Size 0.93 KB
  • File Count
  • Create Date March 6, 2018
  • Last Updated March 6, 2018

Wallpaper Downloader

Source code:

function Download-Wallpaper
{
   param
   (
       [string]
       [Parameter(Mandatory)]
       $Folder,
 
       [Parameter(ValueFromPipeline)]
       [Int]
       $Page=1
   )
   
   begin
   {
       $url = "http://wallpaperswide.com/page/$Page"
       $targetExists = Test-Path  -Path $Folder
       if (!$targetExists) { $null = New-Item -Path $Folder -ItemType Directory }
   }
   process
   {
       $web = Invoke-WebRequest -Uri $url -UseBasicParsing
 
       $web.Images.src | 
       ForEach-Object {
   
           $filename = $_.Split('/' )[-1].Replace('t1.jpg','wallpaper-3840x2160.jpg')
           $source = "http://wallpaperswide.com/download/$filename"
   
           $TargetPath = Join-Path -Path $folder -ChildPath $filename
 
           Invoke-WebRequest -Uri $source -OutFile $TargetPath
       }
   }
   end
   {
       explorer $Folder
   }
}
Download-Wallpaper -Folder d:	empwallpaper