Class: Cain::Movies::Identifier
- Inherits:
-
Object
- Object
- Cain::Movies::Identifier
- Defined in:
- lib/cain/movies/identifier.rb
Constant Summary collapse
- IMDB_TT_URI =
"http://www.imdb.com/title/tt"
- IMDB_TT_RE =
/#{Regexp.escape(IMDB_TT_URI)}(\d+)/
Instance Attribute Summary collapse
-
#path ⇒ Object
Returns the value of attribute path.
-
#tmdb_api_key ⇒ Object
Returns the value of attribute tmdb_api_key.
Instance Method Summary collapse
- #get_imdb_tt_from_nfo(nfo) ⇒ Object
- #get_metadata_by_imdb_tt(tt) ⇒ Object
- #identify ⇒ Object
- #identify_folder(folder) ⇒ Object
-
#initialize(path, tmdb_api_key) ⇒ Identifier
constructor
A new instance of Identifier.
- #mk_tmdb(api_key) ⇒ Object
- #nfo_in(folder) ⇒ Object
- #tmdb ⇒ Object
Constructor Details
#initialize(path, tmdb_api_key) ⇒ Identifier
Returns a new instance of Identifier.
13 14 15 16 |
# File 'lib/cain/movies/identifier.rb', line 13 def initialize(path, tmdb_api_key) self.path = path self.tmdb_api_key = tmdb_api_key end |
Instance Attribute Details
#path ⇒ Object
Returns the value of attribute path.
10 11 12 |
# File 'lib/cain/movies/identifier.rb', line 10 def path @path end |
#tmdb_api_key ⇒ Object
Returns the value of attribute tmdb_api_key.
11 12 13 |
# File 'lib/cain/movies/identifier.rb', line 11 def tmdb_api_key @tmdb_api_key end |
Instance Method Details
#get_imdb_tt_from_nfo(nfo) ⇒ Object
54 55 56 57 58 |
# File 'lib/cain/movies/identifier.rb', line 54 def get_imdb_tt_from_nfo(nfo) if (m = nfo.match(IMDB_TT_RE)) m[1] end end |
#get_metadata_by_imdb_tt(tt) ⇒ Object
44 45 46 |
# File 'lib/cain/movies/identifier.rb', line 44 def (tt) tmdb.imdb_lookup("tt#{tt}") end |
#identify ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/cain/movies/identifier.rb', line 27 def identify case File.directory?(path) when true identify_folder(path) else identify_file(path) end end |
#identify_folder(folder) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/cain/movies/identifier.rb', line 36 def identify_folder(folder) if (nfo = nfo_in(folder)) if (tt = get_imdb_tt_from_nfo(nfo)) return (tt) end end end |
#mk_tmdb(api_key) ⇒ Object
23 24 25 |
# File 'lib/cain/movies/identifier.rb', line 23 def mk_tmdb(api_key) TMDBParty::Base.new(api_key) end |
#nfo_in(folder) ⇒ Object
48 49 50 51 52 |
# File 'lib/cain/movies/identifier.rb', line 48 def nfo_in(folder) if (file = Dir[File.join(folder, "*.nfo")].first) File.read(file) end end |
#tmdb ⇒ Object
19 20 21 |
# File 'lib/cain/movies/identifier.rb', line 19 def tmdb @tmdb ||= mk_tmdb(tmdb_api_key) end |