Class: ComicWalker::ContentDownloader

Inherits:
Object
  • Object
show all
Defined in:
lib/comic_walker/content_downloader.rb

Instance Method Summary collapse

Constructor Details

#initialize(client, cid) ⇒ ContentDownloader

Returns a new instance of ContentDownloader.



3
4
5
6
# File 'lib/comic_walker/content_downloader.rb', line 3

def initialize(client, cid)
  @client = client
  @cid = cid
end

Instance Method Details

#image_dir(license) ⇒ Object



25
26
27
28
29
# File 'lib/comic_walker/content_downloader.rb', line 25

def image_dir(license)
  info = license.get_info.first
  title = info['issues'].first['content_name']
  Pathname.new(title).join(@cid).tap(&:mkpath)
end

#saveObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/comic_walker/content_downloader.rb', line 8

def save
  license = @client.get_license(@cid)
  decoder = ItemDecoder.new(license.get_configuration_pack)
  img_dir = image_dir(license)
  decoder.pages.each.with_index do |file, i|
    dat_path = Pathname.new(file).join('0.dat')
    img_fname = dat_path.parent.basename.sub_ext('.jpg')
    img_path = img_dir.join(sprintf('%03d_%s', i, img_fname))
    if decoder.has_keys?
      decoder.decode_b64(file, dat_path, img_path, license.get_dat(file))
    else
      decoder.decode(file, dat_path, img_path, license.get_jpeg(file))
    end
    puts "#{dat_path} -> #{img_path}"
  end
end