opendmm 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ef198597eed1838f18bdea348b976e6f0ddebcf3
4
- data.tar.gz: f5fe6baeec8b303d9bca0bd9635f069a37cec3fb
3
+ metadata.gz: 807b507fdae159cc6e2ef1ad1e795944180ee9dd
4
+ data.tar.gz: 5f04d17817251b805f5fe671b865ef7de792cc84
5
5
  SHA512:
6
- metadata.gz: 8f215662315bc97bd6567ef8f2836f74cf905a091b511fb846c78c9c95e62c62b5cea80a3cbddc582e3a1617f49081f11f98bda0581869b5eebe5c95f108f7fa
7
- data.tar.gz: 1f08c993484f83a3d7e6c51995f7a40071892d5c7865f7d1d1ba8b2b7889441f45369f0c53165f5711a9066337036f377fe562e53c3b4e8d277c92afc8c44eee
6
+ metadata.gz: 7b5802d38018ace981d8052f31789923a42cdc3ac94ed1caa1e8f26734739e9c1ecb8081f8c878e3b7957e1c4326d75cfaf36af0f8e642ca76f59e8239125552
7
+ data.tar.gz: bf1baf2b3b73676cf6b50a702561814d92175014408c7e24ad778151bef50416a05df3056355bcc085c2c3fc491f2c6270e302e50d217dddc9cc857109741f79
data/.travis.yml CHANGED
@@ -1,4 +1,3 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 2.1.2
4
- script: rake test GFW_MODE=1
data/lib/opendmm/maker.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'active_support/core_ext/string/filters'
2
2
  require 'httparty'
3
+ require 'logger'
3
4
  require 'nokogiri'
4
5
  require 'opendmm/utils'
5
6
 
@@ -51,8 +52,9 @@ module OpenDMM
51
52
  return result if result
52
53
  end
53
54
  nil
54
- rescue
55
- nil
55
+ rescue Errno::ETIMEDOUT => e
56
+ tries++
57
+ tries <= 5 ? retry : raise
56
58
  end
57
59
  end
58
60
  end
@@ -22,7 +22,7 @@ module OpenDMM
22
22
  specs = Utils.hash_from_dl(html.css('#actress > div > dl'))
23
23
  return {
24
24
  actresses: specs['出演女優'].css('a').map(&:text),
25
- code: specs['品番'].text,
25
+ code: parse_code(specs['品番'].text),
26
26
  cover_image: html.at_xpath('//*[@id="thumbnail"]/a[1]')['href'],
27
27
  description: html.css('#brand > p.p_actress_detail').text,
28
28
  genres: specs['ジャンル'].css('a').map(&:text),
@@ -35,6 +35,13 @@ module OpenDMM
35
35
  title: html.css('#brand > div.m_t_4 > h3').text,
36
36
  }
37
37
  end
38
+
39
+ def self.parse_code(text)
40
+ return text unless text.include? '⁄'
41
+ text.lines.map do |line|
42
+ line.split '⁄'
43
+ end.squish_hard.to_h['DVD']
44
+ end
38
45
  end
39
46
  end
40
47
  end
@@ -9,7 +9,7 @@ module OpenDMM
9
9
  follow_redirects false
10
10
 
11
11
  def self.search(name)
12
- get("/ja/vl_searchbyid.php?keyword=#{name}")
12
+ get("/ja/vl_searchbyid.php?keyword=#{CGI::escape(name)}")
13
13
  end
14
14
 
15
15
  def self.item(id)
@@ -52,8 +52,9 @@ module OpenDMM
52
52
  jav_id = Parser.parse_search_result(search_result)
53
53
  end
54
54
  Parser.parse_item(Site.item(jav_id)) if jav_id
55
- rescue
56
- nil
55
+ rescue Errno::ETIMEDOUT => e
56
+ tries++
57
+ tries <= 5 ? retry : raise
57
58
  end
58
59
  end
59
60
  end
data/lib/opendmm/utils.rb CHANGED
@@ -69,51 +69,33 @@ module OpenDMM
69
69
  $stderr = STDERR
70
70
  content = content.encode('UTF-8', encoding, invalid: :replace, undef: :replace, replace: '')
71
71
  end
72
+ end
73
+ end
72
74
 
73
- def self.cleanup(details)
74
- return nil unless details
75
- details = self.squish(details)
76
- if details[:movie_length].instance_of? String
77
- details[:movie_length] = ChronicDuration.parse(details[:movie_length])
78
- end
79
- if details[:page]
80
- if details[:cover_image] && !details[:cover_image].start_with?('http')
81
- details[:cover_image] = URI.join(details[:page], details[:cover_image]).to_s
82
- end
83
- if details[:sample_images]
84
- details[:sample_images] = details[:sample_images].map do |uri|
85
- uri.start_with?('http') ? uri : URI.join(details[:page], uri).to_s
86
- end
87
- end
88
- if details[:thumbnail_image] && !details[:thumbnail_image].start_with?('http')
89
- details[:thumbnail_image] = URI.join(details[:page], details[:thumbnail_image]).to_s
90
- end
91
- end
92
- if details[:release_date].instance_of? String
93
- details[:release_date] = Date.parse(details[:release_date])
94
- end
95
- details
96
- end
75
+ class Object
76
+ def squish_hard
77
+ presence
78
+ end
79
+ end
97
80
 
98
- def self.squish(obj)
99
- case obj
100
- when String
101
- obj.squish!
102
- obj.gsub!(/^[\s-]*$/, '')
103
- when Hash
104
- obj = obj.map do |k, v|
105
- [k, squish(v)]
106
- end.select do |kv|
107
- kv.second.present?
108
- end.to_h.symbolize_keys
109
- when Array
110
- obj = obj.map do |v|
111
- squish(v)
112
- end.select do |v|
113
- v.present?
114
- end
115
- end
116
- return obj.present? ? obj : nil
117
- end
81
+ class String
82
+ def squish_hard
83
+ squish.gsub(/^[\s-]*$/, '').presence
84
+ end
85
+ end
86
+
87
+ class Hash
88
+ def squish_hard
89
+ map do |k, v|
90
+ [k, v.squish_hard]
91
+ end.select do |k_v|
92
+ k_v.second.present?
93
+ end.to_h.presence
94
+ end
95
+ end
96
+
97
+ class Array
98
+ def squish_hard
99
+ map(&:squish_hard).select(&:present?).presence
118
100
  end
119
101
  end
@@ -1,3 +1,3 @@
1
1
  module OpenDMM
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
data/lib/opendmm.rb CHANGED
@@ -4,6 +4,26 @@ require 'opendmm/search_engines/jav_library'
4
4
 
5
5
  module OpenDMM
6
6
  def self.search(name)
7
- Utils.cleanup(Maker.search(name) || SearchEngine::JavLibrary.search(name))
7
+ details = Maker.search(name) || SearchEngine::JavLibrary.search(name)
8
+ return nil unless details
9
+ details = details.squish_hard
10
+ if !details[:cover_image].start_with?('http')
11
+ details[:cover_image] = URI.join(details[:page], details[:cover_image]).to_s
12
+ end
13
+ if !details[:thumbnail_image].start_with?('http')
14
+ details[:thumbnail_image] = URI.join(details[:page], details[:thumbnail_image]).to_s
15
+ end
16
+ if details[:sample_images]
17
+ details[:sample_images] = details[:sample_images].map do |uri|
18
+ uri.start_with?('http') ? uri : URI.join(details[:page], uri).to_s
19
+ end
20
+ end
21
+ if details[:movie_length].instance_of? String
22
+ details[:movie_length] = ChronicDuration.parse(details[:movie_length])
23
+ end
24
+ if details[:release_date].instance_of? String
25
+ details[:release_date] = Date.parse(details[:release_date])
26
+ end
27
+ details
8
28
  end
9
29
  end
@@ -0,0 +1,29 @@
1
+ {
2
+ "actresses": [
3
+ "鈴木心湖"
4
+ ],
5
+ "code": "CND-062",
6
+ "cover_image": "http://candy-av.com/images/works/cnd062/cnd062pl.jpg",
7
+ "description": "絶対美少女シリーズ、今月の新人は奇跡の透明感を持つ純白美肌の鈴木心湖!まさに容姿端麗、18歳とは思えない洗練された美しさの彼女は見た目の完成度だけでなく性格もとってもハートフル!時おり見せるあどけない表情や仕草と完成された容姿のギャップがたまりません!",
8
+ "genres": [
9
+ "デビュー作品"
10
+ ],
11
+ "movie_length": 7200,
12
+ "page": "http://candy-av.com/works/-/detail/=/cid=cnd062",
13
+ "release_date": "2013-10-01",
14
+ "sample_images": [
15
+ "http://candy-av.com/images/works/cnd062/cnd062jp-01.jpg",
16
+ "http://candy-av.com/images/works/cnd062/cnd062jp-02.jpg",
17
+ "http://candy-av.com/images/works/cnd062/cnd062jp-03.jpg",
18
+ "http://candy-av.com/images/works/cnd062/cnd062jp-04.jpg",
19
+ "http://candy-av.com/images/works/cnd062/cnd062jp-05.jpg",
20
+ "http://candy-av.com/images/works/cnd062/cnd062jp-06.jpg",
21
+ "http://candy-av.com/images/works/cnd062/cnd062jp-07.jpg",
22
+ "http://candy-av.com/images/works/cnd062/cnd062jp-08.jpg",
23
+ "http://candy-av.com/images/works/cnd062/cnd062jp-09.jpg",
24
+ "http://candy-av.com/images/works/cnd062/cnd062jp-10.jpg"
25
+ ],
26
+ "thumbnail_image": "http://candy-av.com/images/works/cnd062/cnd062pm.jpg",
27
+ "series": "絶・対・美・少・女",
28
+ "title": "絶・対・美・少・女 奇跡の純白透明感 AVデビュー 鈴木心湖(18歳)"
29
+ }
@@ -17,7 +17,7 @@ class FixtureTest < Minitest::Test
17
17
  end
18
18
 
19
19
  def assert_has_basic_keys(product)
20
- %i(code title thumbnail_image cover_image).each do |key|
20
+ %i(code title thumbnail_image cover_image page).each do |key|
21
21
  assert product[key], "Key #{key} should not be absent"
22
22
  end
23
23
  end
@@ -67,8 +67,6 @@ class FixtureTest
67
67
  assert_has_basic_keys(actual)
68
68
  assert_no_unknown_keys(actual)
69
69
  assert_equal expected, actual, HashDiff.diff(expected, actual)
70
- rescue Errno::ETIMEDOUT => e
71
- raise unless ENV['GFW_MODE']
72
70
  end
73
71
  end
74
72
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opendmm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jun Zhou
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-21 00:00:00.000000000 Z
11
+ date: 2014-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -185,6 +185,7 @@ files:
185
185
  - test/fixtures/CHS-015.json
186
186
  - test/fixtures/CLUB-003.json
187
187
  - test/fixtures/CND-012.json
188
+ - test/fixtures/CND-062.json
188
189
  - test/fixtures/CWM-156.json
189
190
  - test/fixtures/Carib 021511-620.json
190
191
  - test/fixtures/DCOL-017.json
@@ -344,6 +345,7 @@ test_files:
344
345
  - test/fixtures/CHS-015.json
345
346
  - test/fixtures/CLUB-003.json
346
347
  - test/fixtures/CND-012.json
348
+ - test/fixtures/CND-062.json
347
349
  - test/fixtures/CWM-156.json
348
350
  - test/fixtures/Carib 021511-620.json
349
351
  - test/fixtures/DCOL-017.json