movie_searcher 0.0.6 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +3 -1
- data/lib/imdb_party/exclude.yaml +22 -0
- data/lib/imdb_party/movie.rb +1 -1
- data/lib/movie_searcher.rb +33 -10
- data/movie_searcher.gemspec +1 -1
- data/spec/movie_searcher_spec.rb +50 -4
- metadata +6 -5
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
movie_searcher (0.0.
|
4
|
+
movie_searcher (0.0.7)
|
5
5
|
hintable_levenshtein
|
6
6
|
httparty
|
7
7
|
|
@@ -38,5 +38,7 @@ DEPENDENCIES
|
|
38
38
|
autotest-fsevent
|
39
39
|
autotest-growl
|
40
40
|
autotest-standalone
|
41
|
+
hintable_levenshtein
|
42
|
+
httparty
|
41
43
|
movie_searcher!
|
42
44
|
rspec
|
@@ -0,0 +1,22 @@
|
|
1
|
+
excluded:
|
2
|
+
- EXTENDED
|
3
|
+
- "((xvid(-[a-z]+)?))"
|
4
|
+
- "(720|480)p"
|
5
|
+
- B(R|D)Rip
|
6
|
+
- cam
|
7
|
+
- telesync|([^a-z])ts([^a-z]?)
|
8
|
+
- telecine|([^a-z])tc([^a-z]?)
|
9
|
+
- "([^a-z])rx([^a-z]?)"
|
10
|
+
- dvdscr
|
11
|
+
- screener
|
12
|
+
- hdtv
|
13
|
+
- dvdrip
|
14
|
+
- workprint
|
15
|
+
- brrip|bluray|blu(-?)ray
|
16
|
+
- dvd(-?)r
|
17
|
+
- x264
|
18
|
+
- UNRATED
|
19
|
+
- IMAGiNE
|
20
|
+
- SCR
|
21
|
+
- "((ac3(-[a-z]+)?))"
|
22
|
+
- LIMITED
|
data/lib/imdb_party/movie.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module ImdbParty
|
2
2
|
class Movie
|
3
|
-
attr_accessor :imdb_id, :title, :directors, :writers, :tagline, :company, :plot, :runtime, :rating, :poster_url, :release_date, :certification, :genres, :actors, :trailers
|
3
|
+
attr_accessor :imdb_id, :title, :directors, :writers, :tagline, :company, :plot, :runtime, :rating, :poster_url, :release_date, :certification, :genres, :actors, :trailers, :year
|
4
4
|
|
5
5
|
def initialize(options={})
|
6
6
|
if not options.nil? and options.keys.first.class == Symbol
|
data/lib/movie_searcher.rb
CHANGED
@@ -2,7 +2,7 @@ require "imdb_party"
|
|
2
2
|
require 'imdb_party/levenshtein'
|
3
3
|
|
4
4
|
class MovieSearcher
|
5
|
-
attr_accessor :options
|
5
|
+
attr_accessor :options, :cleaners
|
6
6
|
|
7
7
|
def initialize(args)
|
8
8
|
args.keys.each { |name| instance_variable_set "@" + name.to_s, args[name] unless name == :options }
|
@@ -15,6 +15,8 @@ class MovieSearcher
|
|
15
15
|
}
|
16
16
|
|
17
17
|
@options.merge!(args[:options]) unless args[:options].nil?
|
18
|
+
|
19
|
+
@cleaners = YAML.load(File.read("#{File.dirname(__FILE__)}/imdb_party/exclude.yaml"))["excluded"]
|
18
20
|
end
|
19
21
|
|
20
22
|
def self.find_by_release_name(search_value, options = {})
|
@@ -29,7 +31,7 @@ class MovieSearcher
|
|
29
31
|
end
|
30
32
|
|
31
33
|
def to_long?
|
32
|
-
@split = @search_value.split(@options[:split])
|
34
|
+
@split = self.cleaner(@search_value).split(@options[:split])
|
33
35
|
@split.length > @options[:long]
|
34
36
|
end
|
35
37
|
|
@@ -39,17 +41,14 @@ class MovieSearcher
|
|
39
41
|
until current <= 0 do
|
40
42
|
title = @split.take(current).join(' ')
|
41
43
|
movies = @options[:imdb].find_by_title(title)
|
42
|
-
break if movies.any?
|
44
|
+
break if movies.any? and movies.reject{ |movie| self.shortest(movie, title).nil? }.any?
|
43
45
|
current -= 1
|
44
46
|
end
|
45
47
|
|
46
48
|
return if movies.nil? or not movies.any?
|
47
|
-
|
48
|
-
# Cleaning up the title, no years allowed
|
49
|
-
title = title.gsub(/[^a-z0-9]/i, '').gsub(/(19|20)\d{2}/, '')
|
50
|
-
|
49
|
+
|
51
50
|
movie = movies.map do |movie|
|
52
|
-
[movie,
|
51
|
+
[movie, self.shortest(movie, title)]
|
53
52
|
end.reject do |value|
|
54
53
|
value.last.nil?
|
55
54
|
end.sort_by do |_,value|
|
@@ -58,12 +57,36 @@ class MovieSearcher
|
|
58
57
|
|
59
58
|
return if movie.nil?
|
60
59
|
|
61
|
-
|
60
|
+
ImdbParty::Movie.new(movie.first)
|
62
61
|
end
|
63
62
|
|
64
63
|
def self.method_missing(method, *args, &block)
|
65
64
|
result = ImdbParty::Imdb.new.send(method, *args)
|
66
|
-
return if result.nil?
|
67
65
|
result.class == Array ? result.map{|r| ImdbParty::Movie.new(r)} : result
|
68
66
|
end
|
67
|
+
|
68
|
+
def cleaner(string)
|
69
|
+
@cleaners.each do |clean|
|
70
|
+
string = string.gsub(/#{clean}/i, ' ')
|
71
|
+
end
|
72
|
+
|
73
|
+
[/(19|20\d{2})/, /\./, /\s*-\s*/, /\s{2,}/].each do |regex|
|
74
|
+
string = string.gsub(regex, ' ')
|
75
|
+
end
|
76
|
+
|
77
|
+
string.strip
|
78
|
+
end
|
79
|
+
|
80
|
+
def shortest(a,b)
|
81
|
+
# If the release contains a year, then the corresponding movie from IMDB should have the same year
|
82
|
+
if year = @search_value.match(/(19|20\d{2})/)
|
83
|
+
return nil unless year[1] == a[:year]
|
84
|
+
end
|
85
|
+
|
86
|
+
Levenshtein.distance(self.super_cleaner(a[:title]), self.super_cleaner(self.cleaner(b)), @options[:limit])
|
87
|
+
end
|
88
|
+
|
89
|
+
def super_cleaner(string)
|
90
|
+
string.gsub(/[^a-z0-9]/i, '')
|
91
|
+
end
|
69
92
|
end
|
data/movie_searcher.gemspec
CHANGED
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "movie_searcher"
|
6
|
-
s.version = "0.0.
|
6
|
+
s.version = "0.0.8"
|
7
7
|
s.platform = Gem::Platform::RUBY
|
8
8
|
s.authors = ["Linus Oleander", "Jon Maddox"]
|
9
9
|
s.email = ["linus@oleander.nu", "jon@mustacheinc.com"]
|
data/spec/movie_searcher_spec.rb
CHANGED
@@ -17,10 +17,6 @@ describe MovieSearcher do
|
|
17
17
|
MovieSearcher.find_by_release_name("asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd").should be_nil
|
18
18
|
end
|
19
19
|
|
20
|
-
it "should return nil when setting the limit to low" do
|
21
|
-
MovieSearcher.find_by_release_name('Paranormal Activity 2 2010 UNRATED DVDRip XviD-Larceny', :options => {:limit => 0}).should be_nil
|
22
|
-
end
|
23
|
-
|
24
20
|
it "should return the right movie" do
|
25
21
|
[{
|
26
22
|
:title => "Live Free Or Die Hard 2007 DVDRIP XviD-CRNTV", :iid => "tt0337978"
|
@@ -30,6 +26,10 @@ describe MovieSearcher do
|
|
30
26
|
:title => "Heartbreaker 2010 LIMITED DVDRip XviD-SUBMERGE", :iid => "tt1465487"
|
31
27
|
},{
|
32
28
|
:title => "Paranormal Activity 2 2010 UNRATED DVDRip XviD-Larceny", :iid => "tt1536044"
|
29
|
+
}, {
|
30
|
+
:title => "The.Town.2010.EXTENDED.480p.BRRip.XviD-NYDIC", :iid => "tt0840361"
|
31
|
+
}, {
|
32
|
+
:title => "I Spit On Your Grave UNRATED 2010 DVDRip XviD-TWiZTED", :iid => "tt1242432"
|
33
33
|
}].each do |movie|
|
34
34
|
MovieSearcher.find_by_release_name(movie[:title]).imdb_id.should eq(movie[:iid])
|
35
35
|
end
|
@@ -188,4 +188,50 @@ describe MovieSearcher, "should still have the same people" do
|
|
188
188
|
it "should not have a role" do
|
189
189
|
@movie.writers.first.role.should be_nil
|
190
190
|
end
|
191
|
+
end
|
192
|
+
|
193
|
+
describe MovieSearcher, "should have a cleaner" do
|
194
|
+
before(:all) do
|
195
|
+
@movie = MovieSearcher.new({})
|
196
|
+
end
|
197
|
+
|
198
|
+
it "should contain a list of at least 15 cleaners" do
|
199
|
+
@movie.should have_at_least(15).cleaners
|
200
|
+
end
|
201
|
+
|
202
|
+
it "should clean up this release names" do
|
203
|
+
[{
|
204
|
+
:string => "Unstoppable 2010 BDRip XviD-REMALiA",
|
205
|
+
:exclude => ["2010", "BDRip", "XviD"]
|
206
|
+
}, {
|
207
|
+
:string => "True Grit 2010 SCR XViD - IMAGiNE",
|
208
|
+
:exclude => ["2010", "SCR", "XViD", "IMAGiNE", "-"]
|
209
|
+
}, {
|
210
|
+
:string => "Black Swan 2010 DVDSCR XviD-ViSiON",
|
211
|
+
:exclude => ["2010", "DVDSCR", "XviD-ViSiON"]
|
212
|
+
}, {
|
213
|
+
:string => "Red 2010 720p BRRip XviD AC3-FLAWL3SS",
|
214
|
+
:exclude => ["720p", "BRRip", "XviD", "AC3-FLAWL3SS"]
|
215
|
+
}, {
|
216
|
+
:string => "I Spit On Your Grave UNRATED 2010 DVDRip 480p XviD-TWiZTED",
|
217
|
+
:exclude => ["UNRATED", "2010", "DVDRip", "XviD-TWiZTED", "XviD", "480p"]
|
218
|
+
}].each do |value|
|
219
|
+
string = @movie.cleaner(value[:string])
|
220
|
+
value[:exclude].each do |exclude|
|
221
|
+
string.should_not include(exclude)
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
it "should not contain to many spaces in a row" do
|
227
|
+
@movie.cleaner("Unstoppable 2010 BDRip XviD-REMALiA").should_not match(/\s{2,}/)
|
228
|
+
end
|
229
|
+
|
230
|
+
it "should not contain any dots" do
|
231
|
+
@movie.cleaner("The.Town.2010.EXTENDED.480p.BRRip.XviD-NYDIC").should_not match(/\./)
|
232
|
+
end
|
233
|
+
|
234
|
+
it "should not contain any -" do
|
235
|
+
@movie.cleaner("The.Town.2010.EXTENDED.480p.BRRip.XviD-NYDIC").should_not match(/-/)
|
236
|
+
end
|
191
237
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: movie_searcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 15
|
5
|
+
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 8
|
10
|
+
version: 0.0.8
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Linus Oleander
|
@@ -138,6 +138,7 @@ files:
|
|
138
138
|
- README.md
|
139
139
|
- Rakefile
|
140
140
|
- lib/imdb_party.rb
|
141
|
+
- lib/imdb_party/exclude.yaml
|
141
142
|
- lib/imdb_party/httparty_icebox.rb
|
142
143
|
- lib/imdb_party/imdb.rb
|
143
144
|
- lib/imdb_party/levenshtein.rb
|
@@ -178,7 +179,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
178
179
|
requirements: []
|
179
180
|
|
180
181
|
rubyforge_project:
|
181
|
-
rubygems_version: 1.
|
182
|
+
rubygems_version: 1.3.7
|
182
183
|
signing_key:
|
183
184
|
specification_version: 3
|
184
185
|
summary: IMDB client using the IMDB API that their iPhone app uses
|