From acfc4706811367edb6e5b561207d6b2bc3c74382 Mon Sep 17 00:00:00 2001 From: Patrick Speiser Date: Sun, 30 Sep 2012 19:36:54 +0200 Subject: [PATCH] Changed the artists page to use the /artwork/artist|album/id path for retrieving artwork instead of doing an ajax call --- data/interfaces/default/artist.html | 6 ++-- data/interfaces/default/index.html | 2 +- headphones/webserve.py | 48 +++++++++++++++++++++++------ 3 files changed, 42 insertions(+), 14 deletions(-) diff --git a/data/interfaces/default/artist.html b/data/interfaces/default/artist.html index 31299d6e..5e0f5402 100644 --- a/data/interfaces/default/artist.html +++ b/data/interfaces/default/artist.html @@ -40,7 +40,7 @@ <%def name="body()">
- +

%if artist['Status'] == 'Loading': @@ -122,7 +122,7 @@ %> - + ${album['AlbumTitle']} ${album['ReleaseDate']} ${album['Type']} @@ -202,8 +202,6 @@ %if artist['Status'] == 'Loading': showMsg("Getting artist information",true); %endif - getArtistArt(); - getAlbumArt(); $('#album_table').dataTable({ "bDestroy": true, "aoColumns": [ diff --git a/data/interfaces/default/index.html b/data/interfaces/default/index.html index 09e09b00..65a2e670 100644 --- a/data/interfaces/default/index.html +++ b/data/interfaces/default/index.html @@ -46,7 +46,7 @@ "aTargets": [ 0 ], "mData":"ArtistID", "mRender": function ( data, type, full ) { - return '
'; + return '
'; } }, { diff --git a/headphones/webserve.py b/headphones/webserve.py index e5ef3778..e33801e6 100644 --- a/headphones/webserve.py +++ b/headphones/webserve.py @@ -894,10 +894,11 @@ class WebInterface(object): getImageLinks.exposed = True -class Thumbs(object): +class Artwork(object): def index(self): - return "Here be thumbs" + return "Artwork" index.exposed = True + def default(self,ArtistOrAlbum="",ID=None): from headphones import cache ArtistID = None @@ -905,15 +906,12 @@ class Thumbs(object): if ArtistOrAlbum == "artist": ArtistID = ID elif ArtistOrAlbum == "album": - AlbumID = None + AlbumID = ID - relpath = cache.getThumb(ArtistID,AlbumID) + relpath = cache.getArtwork(ArtistID,AlbumID) if not relpath: - if ArtistOrAlbum == "artist": - relpath = "data/interfaces/default/images/no-cover-artist.png" - elif ArtistOrAlbum == "album": - relpath = "data/interfaces/default/images/no-cover-art.png" + relpath = "data/interfaces/default/images/no-cover-art.png" cherrypy.response.headers['Content-type'] = 'image/png' cherrypy.response.headers['Cache-Control'] = 'no-cache' else: @@ -925,5 +923,37 @@ class Thumbs(object): f = open(path,'rb') return f.read() default.exposed = True + + class Thumbs(object): + def index(self): + return "Here be thumbs" + index.exposed = True + def default(self,ArtistOrAlbum="",ID=None): + from headphones import cache + ArtistID = None + AlbumID = None + if ArtistOrAlbum == "artist": + ArtistID = ID + elif ArtistOrAlbum == "album": + AlbumID = ID -WebInterface.thumbs = Thumbs() + relpath = cache.getThumb(ArtistID,AlbumID) + + if not relpath: + relpath = "data/interfaces/default/images/no-cover-artist.png" + cherrypy.response.headers['Content-type'] = 'image/png' + cherrypy.response.headers['Cache-Control'] = 'no-cache' + else: + fileext = os.path.splitext(relpath)[1][1::] + cherrypy.response.headers['Content-type'] = 'image/' + fileext + cherrypy.response.headers['Cache-Control'] = 'max-age=31556926' + + path = os.path.abspath(relpath) + f = open(path,'rb') + return f.read() + default.exposed = True + + thumbs = Thumbs() + + +WebInterface.artwork = Artwork()