diff --git a/app/controllers/artist_controller.rb b/app/controllers/artist_controller.rb index e86edf8..9230afa 100644 --- a/app/controllers/artist_controller.rb +++ b/app/controllers/artist_controller.rb @@ -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 diff --git a/app/models/album.rb b/app/models/album.rb index 46fa309..5633e5e 100644 --- a/app/models/album.rb +++ b/app/models/album.rb @@ -1,2 +1,4 @@ class Album < ActiveRecord::Base + belongs_to :artist + has_many :tracks, :order => 'bonus ASC, position ASC' end diff --git a/app/models/artist.rb b/app/models/artist.rb index de0d924..f8290cb 100644 --- a/app/models/artist.rb +++ b/app/models/artist.rb @@ -1,2 +1,3 @@ class Artist < ActiveRecord::Base + has_many :albums, :conditions => "status = 1", :order => 'year ASC, id ASC' end diff --git a/app/models/track.rb b/app/models/track.rb index 442fed3..c22fba8 100644 --- a/app/models/track.rb +++ b/app/models/track.rb @@ -1,2 +1,3 @@ class Track < ActiveRecord::Base + belongs_to :album end diff --git a/config/routes.rb b/config/routes.rb index fcf8fd8..e0c3bfa 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/db/development.sqlite3 b/db/development.sqlite3 index 42a9744..e7f4f50 100644 Binary files a/db/development.sqlite3 and b/db/development.sqlite3 differ diff --git a/lib/tasks/db_import.rake b/lib/tasks/db_import.rake index 0395105..6b95f2a 100644 --- a/lib/tasks/db_import.rake +++ b/lib/tasks/db_import.rake @@ -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(/<\!\[CDATA\[?(.*)\]\]><\/summary>/m)[0][0] + artist.pic_url = artist_xml.scan(/?(.*)<\/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>/)[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') diff --git a/public/BetaHaven.html b/public/BetaHaven.html index 5ab5eec..66cc8c6 100644 --- a/public/BetaHaven.html +++ b/public/BetaHaven.html @@ -53,7 +53,7 @@ diff --git a/public/javascripts/ajax.js b/public/javascripts/ajax.js index 78e4fd9..5354e1f 100644 --- a/public/javascripts/ajax.js +++ b/public/javascripts/ajax.js @@ -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); } diff --git a/public/javascripts/layout.js b/public/javascripts/layout.js index dc296df..440975a 100644 --- a/public/javascripts/layout.js +++ b/public/javascripts/layout.js @@ -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()); - } } \ No newline at end of file diff --git a/public/jet.json b/public/jet.json deleted file mode 100644 index 49c9084..0000000 --- a/public/jet.json +++ /dev/null @@ -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', - } - ] - } - } - ] -} \ No newline at end of file diff --git a/public/stylesheets/layout.css b/public/stylesheets/layout.css index c650758..e3088bd 100644 --- a/public/stylesheets/layout.css +++ b/public/stylesheets/layout.css @@ -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; } \ No newline at end of file diff --git a/public/stylesheets/player.css b/public/stylesheets/player.css index b461029..06bf1f7 100644 --- a/public/stylesheets/player.css +++ b/public/stylesheets/player.css @@ -49,6 +49,7 @@ } .playlist-tracks li .item { padding: 5px 6px; + overflow: hidden; } .playlist-tracks li .item:hover { background-color: #D0E0F0;