Skip to content
Browse files

don't limit posters just to ones marked "en"

  • Loading branch information...
1 parent 521be7d commit aec6dd5ce91ab0dd19a5476da5e5f1d105a9026c @mislav committed
Showing with 12 additions and 3 deletions.
  1. +10 −2 app/models/poster_finder.rb
  2. +2 −1 lib/tmdb.rb
View
12 app/models/poster_finder.rb
@@ -6,9 +6,17 @@ def self.call movie
tmdb_config = Tmdb.configuration
tmdb_images = Tmdb.poster_images movie.tmdb_id
- Rails.logger.debug "found %d poster images" % tmdb_images.size
+ # sort by language ("en" and nil first) then average rating
+ tmdb_images.sort! { |a, b|
+ if a.language == b.language
+ a.average_rating <=> b.average_rating
+ else
+ a.language == 'en' || (a.language.nil? && b.language != 'en') ? 1 : -1
+ end
+ }
+ tmdb_images.reverse!
- tmdb_images.sort_by {|image| image.average_rating }.reverse.map do |image|
+ tmdb_images.map do |image|
Poster.new \
tmdb_config.poster_url(medium_width * 2, image.file_path),
tmdb_config.poster_url(small_width * 2, image.file_path)
View
3 lib/tmdb.rb
@@ -177,6 +177,7 @@ class PosterImage < NibblerJSON
element :height
element 'vote_average' => :average_rating
element 'vote_count' => :votes
+ element 'iso_639_1' => :language
end
endpoint(:movie_search, 'search/movie?{-join|&|api_key,query}') do
@@ -209,7 +210,7 @@ def self.configuration
endpoint(:movie_cast, 'movie/{tmdb_id}/casts?api_key={api_key}', Cast)
- endpoint(:movie_images, 'movie/{tmdb_id}/images?language=en&api_key={api_key}') do
+ endpoint(:movie_images, 'movie/{tmdb_id}/images?api_key={api_key}') do
elements :posters, :with => PosterImage
end

0 comments on commit aec6dd5

Please sign in to comment.
Something went wrong with that request. Please try again.