1
0
Fork 0

Import w/ desc and pics

This commit is contained in:
magnolia-fan 2011-06-15 00:01:42 +04:00
parent cb42a55f9d
commit 38e4d2496f
13 changed files with 43 additions and 243 deletions

View File

@ -1,2 +1,25 @@
class ArtistController < ApplicationController
def data
data = {}
artist = Artist.find_by_name(params[:name])
data['artist'] = {name: artist.name, desc: artist.desc, pic: artist.pic_url}
data['albums'] = []
albums = artist.albums
albums.each do |album|
tmp_album = {name: album.name, year: album.year, pic: album.pic_url}
album_tracks = []
bonus_tracks = []
album.tracks.each do |track|
tmp_track = {name: track.name, live: track.live, acoustic: track.acoustic}
time = (track.length / 1000).round
time_m = (time / 60).floor
time_s = time - time_m * 60
tmp_track['duration'] = time_m.to_s + ':' + (time_s < 10 ? '0' : '') + time_s.to_s
(track.bonus == 0 ? album_tracks : bonus_tracks) << tmp_track
end
tmp_album['tracks'] = {album: album_tracks, bonus: bonus_tracks}
data['albums'] << tmp_album
end
render :json => data
end
end

View File

@ -1,2 +1,4 @@
class Album < ActiveRecord::Base
belongs_to :artist
has_many :tracks, :order => 'bonus ASC, position ASC'
end

View File

@ -1,2 +1,3 @@
class Artist < ActiveRecord::Base
has_many :albums, :conditions => "status = 1", :order => 'year ASC, id ASC'
end

View File

@ -1,2 +1,3 @@
class Track < ActiveRecord::Base
belongs_to :album
end

View File

@ -55,4 +55,6 @@ Beathaven::Application.routes.draw do
# This is a legacy wild controller route that's not recommended for RESTful applications.
# Note: This route will make all actions in every controller accessible via GET requests.
# match ':controller(/:action(/:id(.:format)))'
match 'artist(/:name)' => 'artist#data'
end

Binary file not shown.

View File

@ -1,3 +1,5 @@
require 'uri'
require 'open-uri'
namespace :db do
desc 'Imports data from MusicBrainz database'
task :import => :environment do
@ -5,21 +7,24 @@ namespace :db do
ati.each do |name|
# Get artist from MB
mb_artist = MusicBrainzArtist.getByName(name)
# Save artist
# # Save artist
artist_xml = open('http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&api_key=04fda005dbf61a50af5abc3e90f111f2&artist='+ URI.escape(name)).read
artist = Artist.new
artist.name = mb_artist.name
artist.desc = 'test import desc'
artist.pic_url = '/images/dummy.png'
artist.desc = artist_xml.scan(/<summary><\!\[CDATA\[?(.*)\]\]><\/summary>/m)[0][0]
artist.pic_url = artist_xml.scan(/<image\ssize=\"extralarge\">?(.*)<\/image>/)[0][0]
artist.save
# Get albums from MB
mb_albums = MusicBrainzAlbum.where('artist_id = ? AND release_type = 1', mb_artist.id).order('year ASC, id ASC')
mb_albums.each do |mb_album|
# Saving album
album_xml = open('http://ws.audioscrobbler.com/2.0/?method=album.getinfo&api_key=04fda005dbf61a50af5abc3e90f111f2&artist='+ URI.escape(name) +'&album='+ URI.escape(mb_album.name)).read
album = Album.new
album.name = mb_album.name
album.year = mb_album.year
album.artist_id = artist.id
album.status = 1
album.pic_url = '/images/dummy.png'
album.pic_url = album_xml.scan(/<image\ssize=\"extralarge\">?(.*)<\/image>/)[0][0]
album.save
# Get album releases from MB
mb_releases = MusicBrainzRelease.where('album_id = ? AND release_type = 1', mb_album.id).order('date ASC, id ASC')

View File

@ -53,7 +53,7 @@
<!-- START DATA -->
<div id="data-container">
<a href="/Jet.json" class="data artist">Jet</a>
<a href="/artist/Kasabian" class="data artist">Kasabian</a>
</div>
<!-- END DATA -->

View File

@ -2,7 +2,6 @@ $(function(){
$('a.data').live('click', function(){
var button = this;
$.get(this.href, function(data){
data = eval('('+ data +')');
if ($(button).hasClass('artist')) {
Pages.renderArtist(data);
}

View File

@ -12,8 +12,8 @@ var beathaven = {
},
adjustSizes: function() {
$('#data-container').height($(window).height() - $('#header-container').height());
$('#data-container').width($(window).width() - $('#player').width())
$('#player-container').height($(window).height());
$('#playlist').height($(window).height() - $('#player').height());
}
}

View File

@ -1,236 +0,0 @@
{
'artist': {
'name': 'Jet',
'desc': 'Jet is an Australian rock band formed in 2001 in Melbourne, Australia, consisting of lead guitarist Cameron Muncey, bassist Mark Wilson, and brothers Nic and Chris Cester on vocals/rhythm guitar and drums respectively. The group has sold 6.5 million records worldwide, with their debut album Get Born, released in 2003, accounting for about 3.5 million of that figure. The band\'s most recent album, Shaka Rock, was released on 19 August 2009.',
'pic': 'pics/jet.jpg'
},
'albums': [
{
'name': 'Get Born',
'year': 2003,
'pic': '/images/getborn.jpg',
'tracks': {
'album': [
{
'name': 'Last Chance',
'duration': '1:52',
},
{
'name': 'Are You Gonna Be My Girl',
'duration': '3:34',
},
{
'name': 'Rollover DJ',
'duration': '3:17',
},
{
'name': 'Look What You\'ve Done',
'duration': '3:51',
},
{
'name': 'Get What You Need',
'duration': '4:08',
},
{
'name': 'Move On',
'duration': '4:21',
},
{
'name': 'Radio Song',
'duration': '4:32',
},
{
'name': 'Get Me Outta Here',
'duration': '2:56',
},
{
'name': 'Cold Hard Bitch',
'duration': '4:03',
},
{
'name': 'Come Around Again',
'duration': '4:30',
},
{
'name': 'Take It or Leave It',
'duration': '2:23',
},
{
'name': 'Lazy Gun',
'duration': '4:42',
},
{
'name': 'Timothy',
'duration': '4:30',
},
{
'name': 'Sgt. Major',
'duration': '4:05',
},
{
'name': 'Are You Gonna Be My Girl (Acoustic)',
'duration': '3:50',
},
{
'name': 'Bruises (Demo)',
'duration': '2:37',
},
{
'name': 'Hey Kids (Non-Album Track)',
'duration': '3:00',
},
{
'name': 'Move On (Live)',
'duration': '4:05',
},
{
'name': 'Cold Hard Bitch (Live)',
'duration': '5:01',
},
{
'name': 'You Don\'t Look The Same (Demo)',
'duration': '4:40',
},
{
'name': 'Look What You\'ve Done (Live)',
'duration': '4:07',
}
]
}
},
{
'name': 'Shine On',
'year': 2006,
'pic': '/images/shineon.jpg',
'tracks': {
'album': [
{
'name': 'Espirit d\'Escalier',
'duration': '0:23',
},
{
'name': 'Holiday',
'duration': '3:26',
},
{
'name': 'Put Your Money Where Your Mouth Is',
'duration': '2:33',
},
{
'name': 'Bring It on Back',
'duration': '4:09',
},
{
'name': 'That\'s All Lies',
'duration': '2:44',
},
{
'name': 'Hey Kids',
'duration': '3:13',
},
{
'name': 'Kings Horses',
'duration': '3:20',
},
{
'name': 'Shine On',
'duration': '4:37',
},
{
'name': 'Come On Come On',
'duration': '4:24',
},
{
'name': 'Stand Up',
'duration': '4:33',
},
{
'name': 'Rip It Up',
'duration': '3:20',
},
{
'name': 'Skin and Bones',
'duration': '3:17',
},
{
'name': 'Shiny Magazine',
'duration': '3:28',
},
{
'name': 'Eleanor',
'duration': '3:34',
},
{
'name': 'All You Have to Do',
'duration': '4:39',
},
{
'name': 'Snap Your Fingers (Barbados Demo)',
'duration': '1:29',
},
{
'name': 'This Night is Yours',
'duration': '1:57',
}
]
}
},
{
'name': 'Shaka Rock',
'year': 2009,
'pic': '/images/shakarock.jpg',
'tracks': {
'album': [
{
'name': 'K.I.A. (Killed In Action)',
'duration': '3:29',
},
{
'name': 'Beat On Repeat',
'duration': '2:30',
},
{
'name': 'She\'s A Genius',
'duration': '2:59',
},
{
'name': 'Black Hearts (On Fire)',
'duration': '3:14',
},
{
'name': 'Seventeen',
'duration': '3:41',
},
{
'name': 'La Di Da',
'duration': '2:53',
},
{
'name': 'Goodbye Hollywood',
'duration': '4:13',
},
{
'name': 'Walk',
'duration': '3:07',
},
{
'name': 'Times Like This',
'duration': '3:20',
},
{
'name': 'Let Me Out',
'duration': '3:12',
},
{
'name': 'Start the Show',
'duration': '3:59',
},
{
'name': 'She Holds a Grudge',
'duration': '4:18',
}
]
}
}
]
}

View File

@ -21,6 +21,7 @@ body {
#data-container {
width: auto;
margin-right: 350px;
overflow-y: scroll;
}
#player {
@ -29,4 +30,5 @@ body {
}
#playlist {
width: 100%;
overflow-y: scroll;
}

View File

@ -49,6 +49,7 @@
}
.playlist-tracks li .item {
padding: 5px 6px;
overflow: hidden;
}
.playlist-tracks li .item:hover {
background-color: #D0E0F0;