.find_by_file(file_path) ⇒ Object

Finds the movie based on the nfo file (or similar file)

35
36
37
38
39
40
41
42
43
44
45
46
47
48

# File 'lib/movie_searcher.rb', line 35defself.find_by_file(file_path)data=File.read(file_path)# If the file is encoded in something non valid (according to ruby), then it can't be read here
# The {valid_encoding} method is not included in ruby 1.8.7, that's why i'm using {respond_to?}
# More info here: http://blog.grayproductions.net/articles/ruby_19s_string
# If the user uses 1.8.7 and the string isn't encoded in UTF-8, nothing happens.
# The script won't throw an exception as it does in 1.9.2
returnifdata.respond_to?(:valid_encoding?)andnotdata.valid_encoding?ifdata=~/imdb\.com\/title\/(tt\d+)/returnself.find_movie_by_id($1)endend

.find_by_folder(folder_path) ⇒ Object

Finds the movie based on the folder

51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70

# File 'lib/movie_searcher.rb', line 51defself.find_by_folder(folder_path)# Relative path?
folder_path=self.relative?(folder_path)# Makes sure that every directory looks the same, an raises an exception if the dir does not exist
folder_path=Dir.new(folder_path).path%x{cd '#{folder_path}' && find '#{folder_path}' -maxdepth 4}.split(/\n/).eachdo|file|# Locating every textfile in the directory
# We're hoping to find a nfo file
ifMimer.identify(file).text?result=self.find_by_file(file)returnresultunlessresult.nil?endend# Last resort, we hope that the folder contain the release name
returnself.find_by_release_name(File.split(folder_path).last)end

#shortest(a, b) ⇒ Object

126
127
128
129
130
131
132
133

# File 'lib/movie_searcher.rb', line 126defshortest(a,b)# If the release contains a year, then the corresponding movie from IMDB should have the same year
ifyear=@search_value.match(/(19|20\d{2})/)returnnilunlessyear[1]==a[:year]endLevenshtein.distance(self.super_cleaner(a[:title]),self.super_cleaner(self.cleaner(b)),@options[:limit])end