Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Render placeholder art for tracks missing album art. Fixes #13

  • Loading branch information...
commit b014728789ec3879ec0f88fa25ed3998ee90a0c6 1 parent 96ce6de
@smashwilson authored
View
BIN  app/assets/images/missing-album.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
4 app/controllers/application_controller.rb
@@ -9,7 +9,9 @@ def create_player_client
@player.ok?
@status = @player.status
- @status.track = Track.find(@status.track_id) if @status.track_id
+ if @status.track_id
+ @status.track = Track.where(:id => @status.track_id).first
+ end
end
end
View
5 app/controllers/tracks_controller.rb
@@ -36,12 +36,11 @@ def album_art
@track = Track.find(params[:id])
art = @track.album_art
- # TODO use a default album image
-
+ response.headers['x-placeholder-art'] = 'true' if art.default?
if art && art.ok?
send_data art.image, :type => art.mime_type, :disposition => 'inline'
else
- render :text => 'Missing album art', :status => 404, :content_type => 'text/plain'
+ render :text => 'Album art corrupted', :status => 500, :content_type => 'text/plain'
end
end
View
2  app/models/album_art.rb
@@ -23,7 +23,7 @@ def initialize image, default = false
# Return true if the image is non-empty and a mime type was successfully inferred.
def ok?
- @image && @mime_type
+ !@image.nil? && !@mime_type.nil?
end
# Return true if this is the "placeholder" image for albums without album art.
View
4 app/models/track.rb
@@ -16,10 +16,10 @@ def to_s
# can be found.
def album_art
art = AlbumArt.from_directory(File.dirname(path))
- if art.nil?
+ if art.nil? || !art.ok?
Mp3Info.open(path) { |mp3| art = AlbumArt.from_metadata(mp3) }
end
- if art.nil?
+ if art.nil? || !art.ok?
art = AlbumArt.default
end
art
View
BIN  test/fixtures/music/track-with-album-art/folder-album-art.mp3
Binary file not shown
View
BIN  test/fixtures/music/track-with-album-art/folder.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
9 test/functional/players_controller_test.rb
@@ -1,14 +1,5 @@
require 'test_helper'
class PlayersControllerTest < ActionController::TestCase
- test "should get show" do
- get :show
- assert_response :success
- end
-
- test "should get update" do
- get :update
- assert_response :success
- end
end
View
20 test/functional/playlists_controller_test.rb
@@ -1,24 +1,4 @@
require 'test_helper'
class PlaylistsControllerTest < ActionController::TestCase
- test "should get index" do
- get :index
- assert_response :success
- end
-
- test "should get update" do
- get :update
- assert_response :success
- end
-
- test "should get destroy" do
- get :destroy
- assert_response :success
- end
-
- test "should get sort" do
- get :sort
- assert_response :success
- end
-
end
View
20 test/functional/tracks_controller_test.rb
@@ -1,14 +1,26 @@
require 'test_helper'
class TracksControllerTest < ActionController::TestCase
- test "should get index" do
- get :index
+
+ test "should access album art" do
+ t = Track.new
+ t.update_from_path(music_path 'track-with-album-art', 'folder-album-art.mp3')
+ t.save!
+
+ get :album_art, { :id => t.id }
assert_response :success
+ assert_equal 'image/png', @response.header['Content-Type']
end
- test "should get show_album" do
- get :show_album
+ test "should provide placeholder album art" do
+ t = Track.new
+ t.update_from_path(music_path 'full-tags.mp3')
+ t.save!
+
+ get :album_art, { :id => t.id }
assert_response :success
+ assert_equal 'image/png', @response.header['Content-Type']
+ assert_equal 'true', @response.header['x-placeholder-art']
end
end
View
4 test/test_helper.rb
@@ -10,4 +10,8 @@ class ActiveSupport::TestCase
fixtures :all
# Add more helper methods to be used by all tests here...
+
+ def music_path *parts
+ Rails.root.join('test', 'fixtures', 'music', *parts).to_s
+ end
end
View
9 test/unit/track_test.rb
@@ -17,9 +17,10 @@ class TrackTest < ActiveSupport::TestCase
test 'read mp3 info from track' do
t = Track.new
- t.update_from_path 'test/fixtures/music/full-tags.mp3'
+ # t.update_from_path 'test/fixtures/music/full-tags.mp3'
+ t.update_from_path(music_path 'full-tags.mp3')
- assert_equal 'test/fixtures/music/full-tags.mp3', t.path
+ assert_equal music_path('full-tags.mp3'), t.path
assert_equal 'track title', t.title
assert_equal 'artist', t.artist
assert_equal 'artist', t.artist_slug
@@ -61,7 +62,7 @@ class TrackTest < ActiveSupport::TestCase
test 'find album art in same folder' do
t = Track.new
- t.update_from_path 'test/fixtures/music/track-with-album-art/folder-album-art.mp3'
+ t.update_from_path music_path('track-with-album-art', 'folder-album-art.mp3')
a = t.album_art
assert_not_nil a
@@ -72,7 +73,7 @@ class TrackTest < ActiveSupport::TestCase
test 'default to placeholder art' do
t = Track.new
- t.update_from_path 'test/fixtures/music/full-tags.mp3'
+ t.update_from_path music_path('full-tags.mp3')
a = t.album_art
assert_not_nil a
Please sign in to comment.
Something went wrong with that request. Please try again.