Wednesday, June 27, 2012

Wallpaperswide download script in Windows

A few of the visitors of my blog found it difficult to run my wallpapers download script (http://vikas-reddy.blogspot.in/2012/01/script-to-download-wallpapers-from.html) in their Windows OSes. So, here's what I did to run it in my Win XP Pro SP2 (32-bit).
  1. Install Ruby 1.9.3-p194 from  http://rubyinstaller.org/downloads/. Normally the defaults are fine. I installed it to my "C:\" folder
  2. Install nokogiri gem using "C:\Ruby193\bin\gem" install nokogiri
  3. Install wget from  http://gnuwin32.sourceforge.net/packages/wget.htm. Keep the defaults, or else, change the "wget" line in the script to reflect the correct executable path.
  4. Download the following code into a file named wallpaperswide-script.rb, and adjust Resolution and OutputDirectory variables. It's 1600x900 and "C:\Wallpapers" respectively by default. Check out the original post for available resolutions.
  5. Run it using "C:\Ruby193\bin\ruby.exe" "C:\wallpaperswide-script.rb"
  6. That's it, all your wallpapers will get downloaded into the given folder.
require 'open-uri'
require 'nokogiri'

Resolution = "1600x900"
Base_URL   = "http://wallpaperswide.com/#{Resolution}-wallpapers-r/page/"
Output_Directory = "C:\\Wallpapers"


(1..2805).each do |page_num|

  # Go page by page
  url = Base_URL + page_num.to_s

  # Parse html
  f = open(url)
  doc = Nokogiri::HTML(f)

  # Loop over image-boxes
  doc.css("div.thumb").each do |wallp|

    # Extract wallpaper subpage url
    wallp.css("div[onclick]").attr("onclick").value =~ /prevframe_show\('(.*)'\)/
    subpage_url = $1
    subpage_url =~ %r|http://wallpaperswide\.com/[^/]+/([\w\d]+)\.html|

    # Generate url of the required wallpaper
    wallp_url = %|http://wallpaperswide.com/download/#{$1}-#{Resolution}.jpg|
    
    # Download... with a user-agent parameter just in case...
    # use '--limit-rate=100k' to limit download speed
    system(%|"C:\\Program Files\\GnuWin32\\bin\\wget.exe" -c -U "Firefox/4.5.6" -P "#{Output_Directory}" "#{wallp_url}"|)

  end
end
I'm continually working on it. You can find the latest version of the code on my github account.


The below listed screenshots will guide you through the process...




9 comments:

S3P3HR said...

Hi .

Can you tell me how to modify it so I can use a proxy in it ? a simple 127.0.0.1:8080 is enough ... your script worked perfect ... till they cencord it :)

Anonymous said...

Hi how are you?

I make everything you post, and works but instead of download the .jpg download the html page of the thumbnail of wallpaperswide.com

Do you know if the change the plataform or I'm makeing something wrong???

Regards
Bruno

Unknown said...

Hi, thanks for the script,I really like the idea,

unfortunately it's not working anymore since the site doesn't allow to access their images directly.

What I mean is that if you try to open, say http://wallpaperswide.com/download/mosque_2-wallpaper-1680x1050.jpg, it sends you to the html download page where you should click the link with the resolution for the picture to download.

That's very unpleasant, because now the script downloads just the .html files and not the .jpegs.
Is there any way around it and do you plan on updating it?

Once again thanks for the wonderful program and i look forward to your answer.

Unknown said...

Hello

I modified this script to download from http://www.hdwallpapers.in

If you want to download for example wallpapers from only one categories you need to change base_URL

require 'open-uri'
require 'nokogiri'

Resolution = "1366x768"
Base_URL = "http://www.hdwallpapers.in/nature__landscape-desktop-wallpapers/page/"
Output_Directory = "C:\\Tapety"


(1..34).each do |page_num|

# Go page by page
url = Base_URL + page_num.to_s

# Parse html
f = open(url)
doc = Nokogiri::HTML(open(url))
doc.xpath('//div[@class="thumb"]/a').each do |node|
wallpaper_link = node['href']
wallpaper_link.sub! '-wallpapers.html', ''
wallpaper_link.sub! '/', ''

# Generate url of the required wallpaper
wallp_url = %|http://www.hdwallpapers.in/download/#{wallpaper_link}-#{Resolution}.jpg|
puts wallp_url

# Download... with a user-agent parameter just in case...
# use '--limit-rate=100k' to limit download speed
system(%|"C:\\Program Files (x86)\\GnuWin32\\bin\\wget.exe" -c -U "Firefox/4.5.6" -P "#{Output_Directory}" "#{wallp_url}"|)

end
end

Vishal said...
This comment has been removed by the author.
Vishal said...

Thankx a lot to the original creator of this wonderful script to download all wallpapers automatically, this is great piece of work.

I used this script on windows 10 after reading information given in insturctions (i know nothing about this type of files ie linux based initially but i read instructions carefully and things worked for me)

Steps to remember :
1. To install NOKOGIRI you have to write or copy paste "C:\Ruby193\bin\gem" install nokogiri in CMD command prompt.

2. Make sure your Ruby version name is correct (if you had downloaded latest one,change its name in script)

3. to download individual categories wallpapers,change the base url.

And many thankx to HDWALLPAPERS.IN script maker.

mseker87 said...

Hi,

Thanks a lot for the great work of such.I'm not a coder or else but I'm not that new in coding so, I tried to run code myself, I downloaded newer versions of ruby and wget, did modifications accordingly. installed nokogiri successfully (i guess). edited a *.rb file with notepad. but when it came to run it with ruby, i get this following error:

-:1: syntax error, unexpected $undefined, expecting tSTRING_CONTENT or tSTRING_DBEG or tSTRING_DVAR or tSTRING_END
C:\wallpaperswide-script.rb

if you could help, it will be more than appreciated. thanks again for all the contributions.

Vishal said...

For running .rb the script
Open Command Prompt CMD and then type
"C:\Ruby193\bin\ruby.exe" "C:\wallpaperswide-script.rb"

Please make sure you have Ruby version correct in path.
Mine was Ruby193 version so i wrote Ruby193.

mseker87 said...

Thanks a lot, I got it running and downloading just fine.