comic_walker 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7fe84087441847fad172320a68b0a4849d5ccb0f
4
- data.tar.gz: ad4627cd74295d5e64c457d74729cd379dedb10f
3
+ metadata.gz: cb14c85698eca69d903464c619f9eaa5819d22dc
4
+ data.tar.gz: 5f34fa556f6f77abba057de04548a780b7ba28d5
5
5
  SHA512:
6
- metadata.gz: 7ca5b14ea61e4a6118ee906b64e7dff21b95ec07b9c9e70827b765d6952fb8d824973bb1ba50ffe8ed918a40030d2f625d29621d41a69d2380cadc43d4bedbcf
7
- data.tar.gz: 62076faf1ff081f17c5f42e5e9cba25949ad523eb87c3e2b54fda226524cfdd7b9e4be0bd6db98670776eca38666ea4a63c8b9c576c05020650989c1ca68a14c
6
+ metadata.gz: d83cd4e18c92cda33bef1b18fb6dc4d0d47b6750f28552099f923fe6b910366f6d3ad792137922152e20fcacf783ed1f690441030465408bb144eab6e6b6dd8c
7
+ data.tar.gz: ceb400b3e83e4471ae29e113db4270565e234125be3b8dc4e4f48e60bc33e4cfb09bc9b1203eb117f519d5e87712ba4337f126fa465961ff6ec680d2e09db048
@@ -1,3 +1,7 @@
1
+ # 0.4.0 (2015-12-19)
2
+ - Fix save command for site renewal
3
+ - https://github.com/eagletmt/comic_walker/issues/6
4
+
1
5
  # 0.3.0 (2014-05-12)
2
6
  - Download configuration_pack and images directly
3
7
  - Drop jar file download
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.add_dependency "addressable"
25
25
  spec.add_dependency "http-cookie"
26
26
  spec.add_dependency "net-http-persistent"
27
- spec.add_dependency "retryable"
27
+ spec.add_dependency "retryable", ">= 2.0.0"
28
28
  spec.add_dependency "rmagick"
29
29
  spec.add_dependency "thor"
30
30
  end
@@ -31,10 +31,15 @@ module ComicWalker
31
31
  end
32
32
 
33
33
  def get_u1(cid)
34
- uri = Addressable::URI.parse("http://comic-walker.com/viewer/?cid=#{cid}")
34
+ uri = Addressable::URI.parse("http://comic-walker.com/viewer/?tw=2&dlcl=ja&cid=#{cid}")
35
35
  Net::HTTP.start(uri.host, 80) do |http|
36
36
  res = http.get(uri.request_uri)
37
- Addressable::URI.unescape(HTTP::Cookie.cookie_value_to_hash(res['set-cookie'])['u1'])
37
+ if set_cookie = res['set-cookie']
38
+ u1 = HTTP::Cookie.cookie_value_to_hash(set_cookie)['u1']
39
+ if u1
40
+ Addressable::URI.unescape(u1)
41
+ end
42
+ end
38
43
  end
39
44
  end
40
45
 
@@ -43,6 +43,10 @@ module ComicWalker
43
43
  def get_jpeg(file)
44
44
  get(url_prefix + file + '/0.jpeg').body
45
45
  end
46
+
47
+ def get_dat(file)
48
+ get(url_prefix + file + '/0.dat').body
49
+ end
46
50
  end
47
51
  end
48
52
  end
@@ -13,7 +13,11 @@ module ComicWalker
13
13
  dat_path = Pathname.new(file).join('0.dat')
14
14
  img_fname = dat_path.parent.basename.sub_ext('.jpg')
15
15
  img_path = img_dir.join(sprintf('%03d_%s', i, img_fname))
16
- decoder.decode(file, dat_path, img_path, license.get_jpeg(file))
16
+ if decoder.has_keys?
17
+ decoder.decode_b64(file, dat_path, img_path, license.get_dat(file))
18
+ else
19
+ decoder.decode(file, dat_path, img_path, license.get_jpeg(file))
20
+ end
17
21
  puts "#{dat_path} -> #{img_path}"
18
22
  end
19
23
  end
@@ -6,6 +6,15 @@ module ComicWalker
6
6
  attr_reader :pages
7
7
 
8
8
  def initialize(configuration_pack)
9
+ fname = '0.dat'
10
+ ct = configuration_pack['ct']
11
+ st = configuration_pack['st']
12
+ et = configuration_pack['et']
13
+ if ct && st && et
14
+ @key1 = (ct + st + fname).unpack('C*')
15
+ @key2 = (ct + fname + et).unpack('C*')
16
+ @key3 = (fname + st + et).unpack('C*')
17
+ end
9
18
  @pages = []
10
19
  configuration_pack['configuration']['contents'].each do |content|
11
20
  pages[content['index']-1] = content['file']
@@ -16,6 +25,23 @@ module ComicWalker
16
25
  end
17
26
  end
18
27
 
28
+ def has_keys?
29
+ !!@key1
30
+ end
31
+
32
+ def decode_b64(file, dat_path, img_path, b64data)
33
+ bs = 128
34
+ hs = 1024
35
+ blob = Unknown.finish(
36
+ @key1, hs,
37
+ Unknown.decrypt(
38
+ @key2, bs,
39
+ Unknown.prepare(@key3, Base64.decode64(b64data).unpack('C*'))
40
+ )
41
+ ).pack('C*')
42
+ decode(file, dat_path, img_path, blob)
43
+ end
44
+
19
45
  def decode(file, dat_path, img_path, blob)
20
46
  src = Magick::Image.from_blob(blob).first
21
47
  width = src.columns
@@ -5,6 +5,47 @@ module ComicWalker
5
5
  module Unknown
6
6
  module_function
7
7
 
8
+ # @param [Array<Fixnum>] key
9
+ # @param [Array<Fixnum>] data Encrypted data
10
+ # @return [Array<Fixnum>]
11
+ def prepare(key, data)
12
+ s = Cipher.gen_rc4_table(key)
13
+ data.map.with_index do |b, i|
14
+ b ^ s[i % 256]
15
+ end
16
+ end
17
+
18
+ # @param [Array<Fixnum>] key
19
+ # @param [Integer] bsize block size?
20
+ # @param [Array<Fixnum>] data Encrypted data
21
+ # @return [Array<Fixnum>] Chunked decrypted data
22
+ def decrypt(key, bsize, data)
23
+ s = []
24
+ 0.step(data.size-1, bsize) do |i|
25
+ s << data[i]
26
+ end
27
+
28
+ c = Cipher.decrypt_rc4(key, s)
29
+ # s.size == c.size
30
+
31
+ 0.step(data.size-1, bsize) do |i|
32
+ data[i] = c.shift
33
+ end
34
+ data
35
+ end
36
+
37
+ # @param [Array<Fixnum>] key
38
+ # @param [Integer] hsize header size?
39
+ # @param [Array<Fixnum>] data Encrypted data
40
+ # @return [Array<Fixnum>] data
41
+ def finish(key, hsize, data)
42
+ hsize = [hsize, data.size].min
43
+ Cipher.decrypt_rc4(key, data.slice(0, hsize)).each.with_index do |x, i|
44
+ data[i] = x
45
+ end
46
+ data
47
+ end
48
+
8
49
  # Calculate moves.
9
50
  # @param [Integer] width Width of the image
10
51
  # @param [Integer] height Height of the image
@@ -26,7 +26,7 @@ module ComicWalker
26
26
 
27
27
  def create_session
28
28
  on_exception = lambda { |exception| create_user }
29
- retryable(tries: 2, on: UnknownDeviceError, sleep: 0, exception_cb: on_exception) do
29
+ Retryable.retryable(tries: 2, on: UnknownDeviceError, sleep: 0, exception_cb: on_exception) do
30
30
  res = post('/user_sessions/create', {
31
31
  DID: @uuid,
32
32
  PIN: @uuid,
@@ -66,7 +66,7 @@ module ComicWalker
66
66
  }.merge(params)
67
67
 
68
68
  on_exception = lambda { |exception| create_session }
69
- retryable(tries: 2, on: NoValidSessionError, sleep: 0, exception_cb: on_exception) do
69
+ Retryable.retryable(tries: 2, on: NoValidSessionError, sleep: 0, exception_cb: on_exception) do
70
70
  res = get('/v1/contents', params)
71
71
  case res.body
72
72
  when 'NoValidSessionError'
@@ -1,5 +1,5 @@
1
1
  module ComicWalker
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
 
4
4
  VIEWER_VERSION = "1.0.5_2014-04-11"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: comic_walker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kohei Suzuki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-11 00:00:00.000000000 Z
11
+ date: 2015-12-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -100,14 +100,14 @@ dependencies:
100
100
  requirements:
101
101
  - - ">="
102
102
  - !ruby/object:Gem::Version
103
- version: '0'
103
+ version: 2.0.0
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
- version: '0'
110
+ version: 2.0.0
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: rmagick
113
113
  requirement: !ruby/object:Gem::Requirement
@@ -182,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
182
182
  version: '0'
183
183
  requirements: []
184
184
  rubyforge_project:
185
- rubygems_version: 2.2.2
185
+ rubygems_version: 2.5.0
186
186
  signing_key:
187
187
  specification_version: 4
188
188
  summary: Client library for ComicWalker