Module: HotPixiv

Defined in:
lib/hotpixiv.rb,
lib/hotpixiv/utils.rb,
lib/hotpixiv/download.rb

Defined Under Namespace

Modules: Utils Classes: Download, Log

Constant Summary collapse

VERSION =
'0.2.3'
PIXIV_API_URL =
'http://iphone.pxv.jp/iphone/'
REFERER =
'http://www.pixiv.net/'
USER_AGENT =
'Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us)
AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16'
DOWNLOAD_TIMEOUT =
10
PAGE =
10
POINT_BORDER =
0
LOG_LEVEL =
1
URL_REGEXP =
/s?http?:\/\/img\d{2}.pixiv.net\/img\/.*?\/\d{8}\.(jpg|gif|png)/

Class Method Summary collapse

Class Method Details

.get(params) ⇒ Object

画像を取得する



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/hotpixiv.rb', line 36

def get(params)
  begin
    # 基本設定
    init(params)
    # 画像のダウンロード
    Download.new.run(params) do |level, msg|
      # 処理が成功した場合
      if level == :info
        @log.info = msg
        puts "[OK]\t#{msg}\n"
      # 処理が失敗した場合
      elsif level == :error
        @log.error = msg
        puts "[NG]\t#{msg}\n"
      end
    end
  rescue => e
    @log.error = e.message
  end
  # エラーがあった場合は出力
  @log.error.print
end

.init(params) ⇒ Object

共通設定



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/hotpixiv.rb', line 19

def init(params)
  begin
    params.merge!(Utils.load(params[:config]))
  rescue
    unless params[:config].nil? || Utils.file?(params[:config])
      raise "Config file not found."
    end
  ensure
    @log = Log.new(params[:log], params[:debug])
  end
  params[:point_border] ||= POINT_BORDER
  keywords = Utils.read_text(params[:file_keyword])
  keywords << params[:keyword] if keywords.length == 0
  params[:keywords] = keywords
end