Permalink
Browse files

search through TheMovieDB

1 parent 1d215d5 commit ade8a2838d7ad62f11e03ea5a7d0ed2b006ca944 @mislav committed Aug 16, 2010
View
1 .rspec
@@ -0,0 +1 @@
+--colour
View
@@ -1,6 +1,6 @@
source :rubygems
-gem 'rails', '3.0.0.rc'
+gem 'rails', '3.0.0.rc', :path => '/Users/mislav/.coral/rails-3-0-stable'
gem 'mongo_mapper', '~> 0.8.3'
gem 'mongo_ext', '0.19.3', :require => nil
@@ -11,5 +11,6 @@ gem 'oauth', '~> 0.4.0', :require => nil
gem 'twitter-login', '~> 0.2.3', :require => 'twitter/login' #, :path => '/Users/mislav/Projects/twitter-login'
gem 'will_paginate', '3.0.pre2' #, :path => '/Users/mislav/.coral/will_paginate-mislav'
gem 'facebook-login', '~> 0.2.0', :require => 'facebook/login' #, :path => '/Users/mislav/Projects/facebook'
-gem 'nibbler', '~> 1.0', :require => 'nibbler/json' #, :path => '/Users/mislav/Projects/scraper'
-gem 'yajl-ruby', '~> 0.7.7', :require => 'yajl/json_gem'
+gem 'nibbler', '~> 1.0' #, :path => '/Users/mislav/Projects/scraper'
+gem 'yajl-ruby', '~> 0.7.7', :require => nil
+gem 'rspec-rails', '~> 2.0.0.beta.19'
View
@@ -1,7 +1,6 @@
-GEM
- remote: http://rubygems.org/
+PATH
+ remote: /Users/mislav/.coral/rails-3-0-stable
specs:
- abstract (1.0.0)
actionmailer (3.0.0.rc)
actionpack (= 3.0.0.rc)
mail (~> 2.2.5)
@@ -12,9 +11,9 @@ GEM
erubis (~> 2.6.6)
i18n (~> 0.4.1)
rack (~> 1.2.1)
- rack-mount (~> 0.6.9)
+ rack-mount (~> 0.6.12)
rack-test (~> 0.5.4)
- tzinfo (~> 0.3.22)
+ tzinfo (~> 0.3.23)
activemodel (3.0.0.rc)
activesupport (= 3.0.0.rc)
builder (~> 2.1.2)
@@ -23,18 +22,37 @@ GEM
activemodel (= 3.0.0.rc)
activesupport (= 3.0.0.rc)
arel (~> 0.4.0)
- tzinfo (~> 0.3.22)
+ tzinfo (~> 0.3.23)
activeresource (3.0.0.rc)
activemodel (= 3.0.0.rc)
activesupport (= 3.0.0.rc)
activesupport (3.0.0.rc)
+ rails (3.0.0.rc)
+ actionmailer (= 3.0.0.rc)
+ actionpack (= 3.0.0.rc)
+ activerecord (= 3.0.0.rc)
+ activeresource (= 3.0.0.rc)
+ activesupport (= 3.0.0.rc)
+ bundler (>= 1.0.0.rc.2)
+ railties (= 3.0.0.rc)
+ railties (3.0.0.rc)
+ actionpack (= 3.0.0.rc)
+ activesupport (= 3.0.0.rc)
+ rake (>= 0.8.3)
+ thor (~> 0.14.0)
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+ abstract (1.0.0)
addressable (2.1.2)
arel (0.4.0)
activesupport (>= 3.0.0.beta)
bson (1.0.4)
bson_ext (1.0.4)
builder (2.1.2)
crack (0.1.6)
+ diff-lcs (1.1.2)
erubis (2.6.6)
abstract (>= 1.0.0)
facebook-login (0.2.1)
@@ -75,24 +93,22 @@ GEM
mongo (~> 1.0.7)
polyglot (0.3.1)
rack (1.2.1)
- rack-mount (0.6.9)
+ rack-mount (0.6.12)
rack (>= 1.0.0)
rack-test (0.5.4)
rack (>= 1.0)
- rails (3.0.0.rc)
- actionmailer (= 3.0.0.rc)
- actionpack (= 3.0.0.rc)
- activerecord (= 3.0.0.rc)
- activeresource (= 3.0.0.rc)
- activesupport (= 3.0.0.rc)
- bundler (>= 1.0.0.rc.1)
- railties (= 3.0.0.rc)
- railties (3.0.0.rc)
- actionpack (= 3.0.0.rc)
- activesupport (= 3.0.0.rc)
- rake (>= 0.8.3)
- thor (~> 0.14.0)
rake (0.8.7)
+ rspec (2.0.0.beta.19)
+ rspec-core (= 2.0.0.beta.19)
+ rspec-expectations (= 2.0.0.beta.19)
+ rspec-mocks (= 2.0.0.beta.19)
+ rspec-core (2.0.0.beta.19)
+ rspec-expectations (2.0.0.beta.19)
+ diff-lcs (>= 1.1.2)
+ rspec-mocks (2.0.0.beta.19)
+ rspec-rails (2.0.0.beta.19)
+ rspec (= 2.0.0.beta.19)
+ webrat (>= 0.7.2.beta.1)
thor (0.14.0)
treetop (1.4.8)
polyglot (>= 0.3.1)
@@ -103,7 +119,11 @@ GEM
yajl-ruby (~> 0.7.0)
twitter-login (0.2.3)
twitter (~> 0.9.5)
- tzinfo (0.3.22)
+ tzinfo (0.3.23)
+ webrat (0.7.2.beta.1)
+ nokogiri (>= 1.2.0)
+ rack (>= 1.0)
+ rack-test (>= 0.5.3)
will_paginate (3.0.pre2)
yajl-ruby (0.7.7)
@@ -119,7 +139,8 @@ DEPENDENCIES
nibbler (~> 1.0)
nokogiri (~> 1.4.1)
oauth (~> 0.4.0)
- rails (= 3.0.0.rc)
+ rails (= 3.0.0.rc)!
+ rspec-rails (~> 2.0.0.beta.19)
twitter-login (~> 0.2.3)
will_paginate (= 3.0.pre2)
yajl-ruby (~> 0.7.7)
View
@@ -7,4 +7,4 @@ require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
-Rails::Application.load_tasks
+Movies::Application.load_tasks
@@ -4,7 +4,7 @@ class MoviesController < ApplicationController
def index
if @query = params[:q]
- @movies = Movie.netflix_search(@query, params[:page])
+ @movies = Movie.tmdb_search(@query)
else
@movies = Movie.paginate(:order => 'title', :page => params[:page], :per_page => 10)
end
View
@@ -1,4 +1,5 @@
-require_dependency 'netflix'
+require 'netflix'
+require 'tmdb'
class Movie
include MongoMapper::Document
@@ -17,6 +18,29 @@ class Movie
key :netflix_id, String
key :netflix_url, String
+ key :tmdb_id, String
+
+ def self.tmdb_search(term)
+ result = Tmdb.search(term)
+
+ result.movies.map { |movie|
+ find_or_create_from_tmdb(movie)
+ }
+ end
+
+ def self.find_or_create_from_tmdb(movie)
+ first(:tmdb_id => movie.id) || create(
+ :title => movie.name,
+ :original_title => movie.original_name,
+ :year => movie.year,
+ # :poster_small_url => movie.poster_medium,
+ # :poster_medium_url => movie.poster_large,
+ :plot => movie.synopsis,
+ :tmdb_id => movie.id,
+ :tmdb_url => movie.url
+ )
+ end
+
def self.netflix_search(term, page = 1)
page ||= 1
catalog = Netflix.search(term, page)
@@ -11,9 +11,9 @@
</div>
<% end %>
-<ol class="movies" style="counter-reset: item <%= @movies.offset %>">
+<ol class="movies" style="counter-reset: item <%#= @movies.offset %>">
<% for movie in @movies %>
- <li style="background-image:url(<%= movie.poster_small_url %>)">
+ <li style="background-image:url(<%#= movie.poster_small_url %>)">
<dl>
<dt><%= link_to(title_for_movie(movie), movie) %> <span>(<%= movie.year %>)</span></dt>
<dd><% unless movie.directors.empty? %>by <em><%= movie.directors.to_sentence %></em><% end %></dd>
@@ -27,4 +27,4 @@
<% end %>
</ol>
-<%= will_paginate @movies %>
+<%#= will_paginate @movies %>
View
@@ -54,56 +54,3 @@ def self.autocomplete(name)
Autocomplete.parse response.body
end
end
-
-if $0 == __FILE__
- require 'spec/autorun'
-
- describe Netflix::Title do
-
- CATALOG = Netflix.parse(DATA.read)
-
- subject { CATALOG.titles.first }
-
- its(:id) { should == 'http://api.netflix.com/catalog/titles/movies/70018295' }
- its(:name) { should == 'The Sea Inside' }
- its(:poster_medium) { should == 'http://cdn-5.nflximg.com/us/boxshots/small/70018295.jpg' }
- its(:year) { should == '2004' }
- its(:runtime) { should == '7500' }
- its(:directors) { should == ["Alejandro Amenábar"] }
- its(:cast) { should == ["Javier Bardem", "Belén Rueda", "Lola Dueñas"] }
- its(:official_url) { should == 'http://www.mar-adentro.com/' }
- its(:synopsis) { should include("this moving film based on a true story as Ramon Sampedro") }
-
- end
-end
-
-__END__
-<catalog_titles>
-<catalog_title>
- <id>http://api.netflix.com/catalog/titles/movies/70018295</id><title short="The Sea Inside" regular="The Sea Inside"/>
-<box_art small="http://cdn-5.nflximg.com/us/boxshots/tiny/70018295.jpg" medium="http://cdn-5.nflximg.com/us/boxshots/small/70018295.jpg" large="http://cdn-5.nflximg.com/us/boxshots/large/70018295.jpg"/>
-<link href="http://api.netflix.com/catalog/titles/movies/70018295/synopsis" rel="http://schemas.netflix.com/catalog/titles/synopsis" title="synopsis"><synopsis><![CDATA[<a href="http://www.netflix.com/RoleDisplay/Javier_Bardem/20001338">Javier Bardem</a> stars in this moving film based on a true story as Ramon Sampedro, a Spaniard who's condemned to life as a quadriplegic. Determined to die with dignity, Sampedro leads a 30-year campaign to win the right to end his life. His extraordinary example even inspires his lawyer, Julia (<a href="http://www.netflix.com/RoleDisplay/Bel_n_Rueda/30009945">Belen Rueda</a>), and a local woman (<a href="http://www.netflix.com/RoleDisplay/Lola_Due_as/20042060">Lola Duenas</a>) to reach for the heavens, with both women achieving far beyond their wildest dreams.]]></synopsis></link>
-<release_year>2004</release_year>
-<category scheme="http://api.netflix.com/categories/mpaa_ratings" label="PG-13" term="PG-13"/>
-<category scheme="http://api.netflix.com/categories/genres" label="Foreign" term="Foreign"/>
-<category scheme="http://api.netflix.com/categories/genres" label="Foreign Dramas" term="Foreign Dramas"/>
-<category scheme="http://api.netflix.com/categories/genres" label="Spain" term="Spain"/>
-<category scheme="http://api.netflix.com/categories/genres" label="Foreign Must-See" term="Foreign Must-See"/>
-<category scheme="http://api.netflix.com/categories/genres" label="Spanish Language" term="Spanish Language"/>
-<category scheme="http://api.netflix.com/categories/genres" label="Foreign Languages" term="Foreign Languages"/>
-<category scheme="http://api.netflix.com/categories/genres" label="Foreign Regions" term="Foreign Regions"/>
-<category scheme="http://api.netflix.com/categories/genres" label="Warner Home Video" term="Warner Home Video"/>
-<runtime>7500</runtime>
-<link href="http://api.netflix.com/catalog/titles/movies/70018295/awards" rel="http://schemas.netflix.com/catalog/titles/awards" title="awards"/>
-<link href="http://api.netflix.com/catalog/titles/movies/70018295/format_availability" rel="http://schemas.netflix.com/catalog/titles/format_availability" title="formats"/>
-<link href="http://api.netflix.com/catalog/titles/movies/70018295/screen_formats" rel="http://schemas.netflix.com/catalog/titles/screen_formats" title="screen formats"/>
-<link href="http://api.netflix.com/catalog/titles/movies/70018295/cast" rel="http://schemas.netflix.com/catalog/people.cast" title="cast"><people><link href="http://api.netflix.com/catalog/people/20001338" rel="http://schemas.netflix.com/catalog/person" title="Javier Bardem"/><link href="http://api.netflix.com/catalog/people/30009945" rel="http://schemas.netflix.com/catalog/person" title="Bel&#xE9;n Rueda"/><link href="http://api.netflix.com/catalog/people/20042060" rel="http://schemas.netflix.com/catalog/person" title="Lola Due&#xF1;as"/></people></link>
-<link href="http://api.netflix.com/catalog/titles/movies/70018295/directors" rel="http://schemas.netflix.com/catalog/people.directors" title="directors"><people><link href="http://api.netflix.com/catalog/people/20004974" rel="http://schemas.netflix.com/catalog/person" title="Alejandro Amen&#xE1;bar"/></people></link>
-<link href="http://api.netflix.com/catalog/titles/movies/70018295/languages_and_audio" rel="http://schemas.netflix.com/catalog/titles/languages_and_audio" title="languages and audio"/>
-<average_rating>3.9</average_rating>
-<link href="http://api.netflix.com/catalog/titles/movies/70018295/similars" rel="http://schemas.netflix.com/catalog/titles.similars" title="similars"/>
-<link href="http://www.mar-adentro.com/" rel="http://schemas.netflix.com/catalog/titles/official_url" title="official webpage"/>
-<link href="http://www.netflix.com/Movie/The_Sea_Inside/70018295" rel="alternate" title="web page"/>
-
- </catalog_title>
-</catalog_titles>
Oops, something went wrong.

0 comments on commit ade8a28

Please sign in to comment.