Friday, July 06, 2012

A powershell image downloader for Reddit

Yes, I know there are a million of these, so this will make one million and one.

This is a image downloader for Reddit. Many of the images on Reddit are simply linked and can be downloaded directly from the XML source. This example configures a web proxy, and downloads from the /r/pics subboard.

# .NET class 
$webClient = new-object System.Net.WebClient 
# specify your proxy address and port 
$proxy = new-object System.Net.WebProxy ""  
# replace your credential by your domain, username, and pasword 
$proxy.Credentials = New-Object System.Net.NetworkCredential ("Domain\UserName", "Password") 
# specify an header if you want to check info in your logs on your proxy 
$webClient.Headers.Add("user-agent", "Windows Powershell WebClient Header") 
# File to download 
$url = "" 
[xml]$myxml = $Webclient.Downloadstring($url)
$"<") | %{$_| select-string -pattern link} | %{$webclient.DownloadFile($_.line.split('"')[1],"c:\temp\red\" + $_.line.split('"')[1].split("/")[-1] )}

No comments: