1
0
Fork 0

Album pics from last.fm

This commit is contained in:
magnolia-fan 2011-04-07 02:02:48 +04:00
parent 2f611742ba
commit a9b4a46c59
3 changed files with 21 additions and 3 deletions

View File

@ -1,5 +1,23 @@
# encoding: UTF-8
class Album < ActiveRecord::Base class Album < ActiveRecord::Base
set_table_name 'musicbrainz.bh_release_group' set_table_name 'musicbrainz.bh_release_group'
belongs_to :artist belongs_to :artist
has_many :releases, :conditions => "release_type = 1", :order => 'date ASC, id ASC' has_many :releases, :conditions => "release_type = 1", :order => 'date ASC, id ASC'
require 'iconv'
def cover artist
q_artist = CGI::escape(artist)
q_album = CGI::escape(name)
#i = Iconv.new('Windows-31J', 'UTF-8')
path = open(
'http://ws.audioscrobbler.com/2.0/' <<
'?method=album.getinfo' <<
'&api_key=b25b959554ed76058ac220b7b2e0a026' <<
'&artist=' << q_artist <<
'&album=' << q_album
).read
path.match(/<image\ssize=\"mega\">(.*)<\/image>/i)[1]
end
end end

View File

@ -2,7 +2,7 @@
<% @artist.albums.each do |album| %> <% @artist.albums.each do |album| %>
<% unless album.releases.empty? %> <% unless album.releases.empty? %>
<div class="album"> <div class="album">
<div class="pic"></div> <div class="pic"><img src="<%= album.cover(@artist.name) %>" width="250" height="250" alt=""/></div>
<h3 class="name"><%= album.name %> <%= (album.year ? album.year : '') %></h3> <h3 class="name"><%= album.name %> <%= (album.year ? album.year : '') %></h3>
<% <%
releases = album.releases releases = album.releases

View File

@ -41,7 +41,7 @@ body {
.album .name { .album .name {
display: block; display: block;
float: left; float: left;
width: 400px; width: 450px;
font-size: 1.5em; font-size: 1.5em;
margin: 0 0 0.5em 0; margin: 0 0 0.5em 0;
/* background-color: yellowgreen;*/ /* background-color: yellowgreen;*/
@ -50,7 +50,7 @@ body {
.album .tracks { .album .tracks {
display: block; display: block;
float: left; float: left;
width: 400px; width: 450px;
margin-bottom: 1em; margin-bottom: 1em;
/* background-color: lightblue;*/ /* background-color: lightblue;*/
} }