addic7ed 2.0.4 → 2.1.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: a9ac47ab606d0c47c0f231fda702b005f6d8a6f6
4
- data.tar.gz: f9f084432ec3ef5dfc2db748755e19d3ba8064aa
3
+ metadata.gz: d090b6dafb401806828c94d5eecc00b74848d9e3
4
+ data.tar.gz: adbf02a35ab41850d6bd8cfce2781c71043813a0
5
5
  SHA512:
6
- metadata.gz: 2b8a15c946b67feead67c43ff1e959e259c145d4fba34b6f13c2df5b5310ca529906da3ddd635a1f87a2a4b45e09e1efbac0f77a631118574f10367e4238d7d3
7
- data.tar.gz: f09d4f14b1a727b13708b2213fd6915b30a40f526d98907266e25b0b8651845e7d482a56ee789b5a513e771a8e50cefa201d234fa037854f5590adaa61b04915
6
+ metadata.gz: 7d2f78dcefedda6702524cd946d3ce811008e6f3e5bccb53d89ced041e79f46342c3664e232c9d26f4ca095aab5a9b15048108ad60031de401d3bbe3005c289e
7
+ data.tar.gz: 2c05be5aeb32c812dbb2db8eda5ea261d6801d8a86c6d39056d2905c25e1061cd0357adcc8d7b9d21be6b2c2cb9767d2fbc70d29bf08de0d4d7ff58712906a97
@@ -1,5 +1,7 @@
1
1
  require 'addic7ed/version'
2
2
  require 'addic7ed/common'
3
+ require 'addic7ed/services/addic7ed_version_normalizer'
4
+ require 'addic7ed/services/addic7ed_comment_normalizer'
3
5
  require 'addic7ed/errors'
4
6
  require 'addic7ed/show_list'
5
7
  require 'addic7ed/video_file'
@@ -58,7 +58,7 @@ module Addic7ed
58
58
  def extract_version(sub_node)
59
59
  version_node = sub_node.css('.NewsTitle').first
60
60
  raise Addic7ed::ParsingError unless version_node
61
- version_node.content.gsub(/ \nVersion /, '').gsub(/,.*/, '')
61
+ version_node.content
62
62
  end
63
63
 
64
64
  def extract_language(sub_node)
@@ -101,6 +101,5 @@ module Addic7ed
101
101
  raise Addic7ed::ParsingError unless comment_node
102
102
  comment_node.content.gsub(/<img[^>]+\>/i, "")
103
103
  end
104
-
105
104
  end
106
105
  end
@@ -0,0 +1,19 @@
1
+ module Addic7ed
2
+ class Addic7edCommentNormalizer
3
+ attr_reader :comment
4
+
5
+ def initialize(comment)
6
+ @comment = comment || ""
7
+ end
8
+
9
+ def self.call(comment)
10
+ new(comment).call
11
+ end
12
+
13
+ def call
14
+ comment.downcase
15
+ end
16
+ end
17
+
18
+ private
19
+ end
@@ -0,0 +1,24 @@
1
+ module Addic7ed
2
+ class Addic7edVersionNormalizer
3
+ attr_reader :version
4
+
5
+ def initialize(version)
6
+ @version = version || ""
7
+ end
8
+
9
+ def self.call(version)
10
+ new(version).call
11
+ end
12
+
13
+ def call
14
+ version.
15
+ gsub(/[[:space:]]/, "").
16
+ upcase.
17
+ gsub(/,[\d\. ]+MBS$/, '').
18
+ gsub(/(^VERSION *|720P|1080P|HDTV|PROPER|RERIP|INTERNAL|X\.?264)/, '').
19
+ gsub(/[- \.]/, '')
20
+ end
21
+ end
22
+
23
+ private
24
+ end
@@ -5,14 +5,14 @@ module Addic7ed
5
5
  attr_accessor :url
6
6
 
7
7
  def initialize(options = {})
8
- @version = normalize_version(options[:version])
8
+ @version = Addic7edVersionNormalizer.call(options[:version])
9
9
  @language = options[:language]
10
10
  @status = options[:status]
11
11
  @url = options[:url]
12
12
  @via = options[:via]
13
13
  @hi = options[:hi]
14
14
  @downloads = options[:downloads].to_i || 0
15
- @comment = normalize_comment(options[:comment])
15
+ @comment = Addic7edCommentNormalizer.call(options[:comment])
16
16
  end
17
17
 
18
18
  def to_s
@@ -42,23 +42,16 @@ module Addic7ed
42
42
 
43
43
  protected
44
44
 
45
- def normalize_version(version)
46
- (version || "").
47
- gsub(/(^Version *|720p|1080p|hdtv|proper|rerip|internal|x\.?264)/i, '').
48
- gsub(/^[- \.]*/, '').gsub(/[- \.]*$/, '').
49
- upcase
50
- end
51
-
52
- def normalize_comment(comment)
53
- (comment || "").downcase
45
+ def is_compatible_with?(other_version)
46
+ defined_as_compatible_with(other_version) || generally_compatible_with?(other_version) || commented_as_compatible_with?(other_version)
54
47
  end
55
48
 
56
- def is_compatible_with?(other_version)
57
- generally_compatible_with?(other_version) || commented_as_compatible_with?(other_version)
49
+ def defined_as_compatible_with(other_version)
50
+ version.split(",").include? other_version
58
51
  end
59
52
 
60
53
  def generally_compatible_with?(other_version)
61
- version == other_version || COMPATIBILITY_720P[version] == other_version || COMPATIBILITY_720P[other_version] == version
54
+ COMPATIBILITY_720P[version] == other_version || COMPATIBILITY_720P[other_version] == version
62
55
  end
63
56
 
64
57
  def commented_as_compatible_with?(other_version)
@@ -1,3 +1,3 @@
1
1
  module Addic7ed
2
- VERSION = "2.0.4"
2
+ VERSION = "2.1.0"
3
3
  end
@@ -0,0 +1,12 @@
1
+ require "spec_helper"
2
+ require "./lib/addic7ed"
3
+
4
+ describe Addic7ed::Addic7edCommentNormalizer do
5
+ def normalized_comment(comment)
6
+ described_class.call(comment)
7
+ end
8
+
9
+ it "downcases everything" do
10
+ expect(normalized_comment("DiMENSiON")).to eq "dimension"
11
+ end
12
+ end
@@ -0,0 +1,73 @@
1
+ require "spec_helper"
2
+ require "./lib/addic7ed"
3
+
4
+ describe Addic7ed::Addic7edVersionNormalizer do
5
+ def normalized_version(version)
6
+ described_class.call(version)
7
+ end
8
+
9
+ it "upcases everything" do
10
+ expect(normalized_version("DiMENSiON")).to eq "DIMENSION"
11
+ end
12
+
13
+ it "removes white spaces and line breaks and non-breaking spaces" do
14
+ expect(normalized_version(" \n DIMENSION \u00a0 ")).to eq "DIMENSION"
15
+ end
16
+
17
+ it "removes the filesize" do
18
+ expect(normalized_version("DIMENSION, 0.00 MBs")).to eq "DIMENSION"
19
+ end
20
+
21
+ it "removes heading or trailing dots" do
22
+ expect(normalized_version(".DIMENSION.")).to eq "DIMENSION"
23
+ end
24
+
25
+ it "removes heading or trailing whitespaces" do
26
+ expect(normalized_version(" DIMENSION ")).to eq "DIMENSION"
27
+ end
28
+
29
+ it "removes heading or trailing dashes" do
30
+ expect(normalized_version("-DIMENSION-")).to eq "DIMENSION"
31
+ end
32
+
33
+ it "removes '720p' tag" do
34
+ expect(normalized_version("720P DIMENSION")).to eq "DIMENSION"
35
+ end
36
+
37
+ it "removes '1080p' tag" do
38
+ expect(normalized_version("1080P DIMENSION")).to eq "DIMENSION"
39
+ end
40
+
41
+ it "removes 'HDTV' tag" do
42
+ expect(normalized_version("HDTV DIMENSION")).to eq "DIMENSION"
43
+ end
44
+
45
+ it "removes 'x264' tag" do
46
+ expect(normalized_version("X264 DIMENSION")).to eq "DIMENSION"
47
+ expect(normalized_version("X.264 DIMENSION")).to eq "DIMENSION"
48
+ end
49
+
50
+ it "removes 'PROPER' tag" do
51
+ expect(normalized_version("PROPER DIMENSION")).to eq "DIMENSION"
52
+ end
53
+
54
+ it "removes 'RERIP' tag" do
55
+ expect(normalized_version("RERIP DIMENSION")).to eq "DIMENSION"
56
+ end
57
+
58
+ it "removes 'INTERNAL' tag" do
59
+ expect(normalized_version("INTERNAL DIMENSION")).to eq "DIMENSION"
60
+ end
61
+
62
+ it "removes the 'Version' prefix" do
63
+ expect(normalized_version("Version DIMENSION")).to eq "DIMENSION"
64
+ end
65
+
66
+ it "removes combined tags" do
67
+ expect(normalized_version("Version 720P PROPER X264 HDTV DIMENSION")).to eq "DIMENSION"
68
+ end
69
+
70
+ it "supports multiple concatenated versions" do
71
+ expect(normalized_version("-TLA, -FoV")).to eq "TLA,FOV"
72
+ end
73
+ end
@@ -1,62 +1,20 @@
1
1
  require "spec_helper"
2
2
  require "./lib/addic7ed"
3
3
 
4
- describe Addic7ed::Subtitle, "#normalize_version!" do
5
- def normalized_version(version)
6
- Addic7ed::Subtitle.new(version: version).version
7
- end
8
-
9
- it "upcases everything" do
10
- expect(normalized_version("DiMENSiON")).to eq 'DIMENSION'
11
- end
12
-
13
- it "removes heading or trailing dots" do
14
- expect(normalized_version(".DIMENSION.")).to eq 'DIMENSION'
15
- end
16
-
17
- it "removes heading or trailing whitespaces" do
18
- expect(normalized_version(" DIMENSION ")).to eq 'DIMENSION'
19
- end
20
-
21
- it "removes heading or trailing dashes" do
22
- expect(normalized_version("-DIMENSION-")).to eq 'DIMENSION'
23
- end
24
-
25
- it "removes '720p' tag" do
26
- expect(normalized_version("720P DIMENSION")).to eq 'DIMENSION'
27
- end
28
-
29
- it "removes '1080p' tag" do
30
- expect(normalized_version("1080P DIMENSION")).to eq 'DIMENSION'
31
- end
32
-
33
- it "removes 'HDTV' tag" do
34
- expect(normalized_version("HDTV DIMENSION")).to eq 'DIMENSION'
35
- end
36
-
37
- it "removes 'x264' tag" do
38
- expect(normalized_version("X264 DIMENSION")).to eq 'DIMENSION'
39
- expect(normalized_version("X.264 DIMENSION")).to eq 'DIMENSION'
40
- end
41
-
42
- it "removes 'PROPER' tag" do
43
- expect(normalized_version("PROPER DIMENSION")).to eq 'DIMENSION'
44
- end
45
-
46
- it "removes 'RERIP' tag" do
47
- expect(normalized_version("RERIP DIMENSION")).to eq 'DIMENSION'
48
- end
4
+ describe Addic7ed::Subtitle, "#initialize" do
5
+ let(:version) { "Version DIMENSiON" }
6
+ let(:comment) { "Works for LOL" }
49
7
 
50
- it "removes 'INTERNAL' tag" do
51
- expect(normalized_version("INTERNAL DIMENSION")).to eq 'DIMENSION'
52
- end
8
+ subject { described_class.new(version: version, comment: comment) }
53
9
 
54
- it "removes the 'Version' prefix" do
55
- expect(normalized_version("Version DIMENSION")).to eq 'DIMENSION'
10
+ it "normalizes Addic7ed version" do
11
+ expect(Addic7ed::Addic7edVersionNormalizer).to receive(:call).with(version)
12
+ subject
56
13
  end
57
14
 
58
- it "removes combined tags" do
59
- expect(normalized_version("Version 720P PROPER X264 HDTV DIMENSION")).to eq "DIMENSION"
15
+ it "normalizes Addic7ed comment" do
16
+ expect(Addic7ed::Addic7edCommentNormalizer).to receive(:call).with(comment)
17
+ subject
60
18
  end
61
19
  end
62
20
 
@@ -125,6 +83,19 @@ describe Addic7ed::Subtitle, "#works_for?" do
125
83
  expect(subtitle.works_for? "IMMERSE").to be false
126
84
  end
127
85
  end
86
+
87
+ context "when it has multiple versions" do
88
+ let(:subtitle) { Addic7ed::Subtitle.new(version: "FOV,TLA") }
89
+
90
+ it "returns true if it works for one of them" do
91
+ expect(subtitle.works_for? "TLA").to be true
92
+ expect(subtitle.works_for? "FOV").to be true
93
+ end
94
+
95
+ it "returns false when none of them work" do
96
+ expect(subtitle.works_for? "LOL").to be false
97
+ end
98
+ end
128
99
  end
129
100
  end
130
101
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: addic7ed
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.4
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Baudino
@@ -108,12 +108,16 @@ files:
108
108
  - lib/addic7ed/episode.rb
109
109
  - lib/addic7ed/errors.rb
110
110
  - lib/addic7ed/parser.rb
111
+ - lib/addic7ed/services/addic7ed_comment_normalizer.rb
112
+ - lib/addic7ed/services/addic7ed_version_normalizer.rb
111
113
  - lib/addic7ed/show_list.rb
112
114
  - lib/addic7ed/subtitle.rb
113
115
  - lib/addic7ed/version.rb
114
116
  - lib/addic7ed/video_file.rb
115
117
  - spec/lib/addic7ed/common_spec.rb
116
118
  - spec/lib/addic7ed/episode_spec.rb
119
+ - spec/lib/addic7ed/services/addic7ed_comment_normalizer_spec.rb
120
+ - spec/lib/addic7ed/services/addic7ed_version_normalizer_spec.rb
117
121
  - spec/lib/addic7ed/show_list_spec.rb
118
122
  - spec/lib/addic7ed/subtitle_spec.rb
119
123
  - spec/lib/addic7ed/video_file_spec.rb
@@ -155,6 +159,8 @@ summary: Addic7ed auto-downloader
155
159
  test_files:
156
160
  - spec/lib/addic7ed/common_spec.rb
157
161
  - spec/lib/addic7ed/episode_spec.rb
162
+ - spec/lib/addic7ed/services/addic7ed_comment_normalizer_spec.rb
163
+ - spec/lib/addic7ed/services/addic7ed_version_normalizer_spec.rb
158
164
  - spec/lib/addic7ed/show_list_spec.rb
159
165
  - spec/lib/addic7ed/subtitle_spec.rb
160
166
  - spec/lib/addic7ed/video_file_spec.rb