Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save shaobin0604/215825 to your computer and use it in GitHub Desktop.
Save shaobin0604/215825 to your computer and use it in GitHub Desktop.
钢炼漫画下载脚本
#--------------------------------------------------
# Name: fullmetal_alchemist_comic_book_download_script.rb
# Description: This Ruby script is used to batch download Fullmetal Alchemis
# comic books which are hosted on http://www.jumpcn.com.
# Make ensure wget program can be found via PATH environment variable.
# The Windows version of wget program can be found at http://users.ugent.be/~bpuype/wget/.
#
# Usage:
# ruby fullmetal_alchemist_comic_book_download_script.rb chapter
#
# Note:
# the chapter argument must be an Integer. Up to now, the valid chapter should be in
# eval((1..18).to_a + (74..100).to_a)
#
# Author: Bin Shao <[email protected]> http://aquarium.yo2.cn
# Date: Oct. 19, 2009
# License: Apache License, Version 2.0
#--------------------------------------------------
require 'logger'
$log = Logger.new(STDOUT)
$log.level = Logger::INFO
# valid chapters up to now
VALID_CHAPTERS_UPTO_NOW = (1..18).to_a + (74..100).to_a
# Download pictures in chapter
#
# @param chapter Integer the chapter to be downloaded
#
def download_chapter_pics(chapter)
unless chapter_valid?(chapter)
$log.error "chapter not valid"
end
command_template = 'wget --directory-prefix="Fullmetal Alchemist/%03d" \
http://gc.jumpcn.com/1/g/gang-zhi-lian-jin-shu-shi/%d/%03d.jpg'
i = 0
loop do
i += 1
system(command_template % [chapter, chapter, i])
break unless $?.exitstatus == 0
end
end
def chapter_valid?(chapter)
chapter.is_a?(Integer) && VALID_CHAPTERS_UPTO_NOW.include?(chapter)
end
if __FILE__ == $0
# chapters = (1..18).to_a + (74..100).to_a
if ARGV.length != 1
puts "Usage: ruby fullmetal_alchemist_comic_book_download_script.rb chapter"
puts "chapter must be an Integer"
else
download_chapter_pics(ARGV[0].to_i)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment