Cache album pics to mongo & listen url & check if track in db
This commit is contained in:
parent
3c96c151bd
commit
63136f8b67
|
@ -0,0 +1,11 @@
|
|||
class TrackController < ApplicationController
|
||||
def listen
|
||||
@track = TrackData.where(id: params[:id])
|
||||
unless @track.empty?
|
||||
out = {:status => 'ok', :data => @track.first.files.first[1]}
|
||||
else
|
||||
out = {:status => 'no_such_track'}
|
||||
end
|
||||
render :json => out
|
||||
end
|
||||
end
|
|
@ -0,0 +1,2 @@
|
|||
module TrackHelper
|
||||
end
|
|
@ -7,17 +7,29 @@ class Album < ActiveRecord::Base
|
|||
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]
|
||||
covers = AlbumPic.where(album_id: id)
|
||||
unless covers.empty?
|
||||
covers.first.extralarge
|
||||
else
|
||||
q_artist = CGI::escape(artist)
|
||||
q_album = CGI::escape(name)
|
||||
path = open(
|
||||
'http://ws.audioscrobbler.com/2.0/' <<
|
||||
'?method=album.getinfo' <<
|
||||
'&api_key=04fda005dbf61a50af5abc3e90f111f2' <<
|
||||
'&artist=' << q_artist <<
|
||||
'&album=' << q_album
|
||||
).read
|
||||
m = path.scan(/<image\ssize=\"(.*)\">(.*)<\/image>/i)
|
||||
AlbumPic.new(
|
||||
album_id: id,
|
||||
small: m[0][1],
|
||||
medium: m[1][1],
|
||||
large: m[2][1],
|
||||
extralarge: m[3][1],
|
||||
mega: m[4][1]
|
||||
)
|
||||
m[3][1]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
class AlbumPic
|
||||
include Mongoid::Document
|
||||
store_in :album_pics
|
||||
|
||||
key :album_id, Integer
|
||||
key :small, String
|
||||
key :medium, String
|
||||
key :large, String
|
||||
key :extralarge, String
|
||||
key :mega, String
|
||||
end
|
|
@ -2,11 +2,7 @@ class Track < ActiveRecord::Base
|
|||
set_table_name 'musicbrainz.bh_track'
|
||||
belongs_to :release
|
||||
|
||||
def clearName
|
||||
name.gsub('&', 'and').gsub(/[^a-z0-9]/, '').downcase
|
||||
end
|
||||
|
||||
def files
|
||||
TrackData(:id => id)
|
||||
def inDb
|
||||
! TrackData.where(id: id.to_s).empty?
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,9 +2,9 @@ class TrackData
|
|||
include Mongoid::Document
|
||||
store_in :track_data
|
||||
|
||||
key :id, Integer
|
||||
key :artist, String
|
||||
key :title, String
|
||||
key :length, Integer
|
||||
key :files, Array
|
||||
key :id, Integer
|
||||
key :artist, String
|
||||
key :title, String
|
||||
key :length, Integer
|
||||
key :files, Array
|
||||
end
|
||||
|
|
|
@ -10,8 +10,8 @@
|
|||
%>
|
||||
<ul class="tracks">
|
||||
<% first_release.tracks.each do |track| %>
|
||||
<li>
|
||||
<span class="play"></span>
|
||||
<li id="<%= track.id %>">
|
||||
<span class="play<%= (track.inDb ? '' : ' disabled') %>"></span>
|
||||
<span class="track-name"><%= track.name %></span>
|
||||
<span class="duration"><%= track.length.toTime %></span>
|
||||
</li>
|
||||
|
|
|
@ -57,4 +57,5 @@ Beathaven::Application.routes.draw do
|
|||
# match ':controller(/:action(/:id(.:format)))'
|
||||
|
||||
match 'artist/:name' => 'artist#view'
|
||||
match 'listen/:id' => 'track#listen'
|
||||
end
|
||||
|
|
|
@ -21,7 +21,7 @@ body {
|
|||
display: block;
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
margin: 0 0 0.5em 0;
|
||||
margin: 2em 0 0.5em 0;
|
||||
font-size: 3em;
|
||||
}
|
||||
|
||||
|
@ -74,4 +74,9 @@ body {
|
|||
background-image: url(/images/play.png);
|
||||
width: 31px;
|
||||
height: 30px;
|
||||
margin: 0 0.3em 0 0;
|
||||
margin: 0 0.3em 0 0;
|
||||
}
|
||||
|
||||
.album .tracks li .play.disabled {
|
||||
background-image: none;
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
|
||||
|
||||
# This model initially had no columns defined. If you add columns to the
|
||||
# model remove the '{}' from the fixture names and add the columns immediately
|
||||
# below each fixture, per the syntax in the comments below
|
||||
#
|
||||
one: {}
|
||||
# column: value
|
||||
#
|
||||
two: {}
|
||||
# column: value
|
|
@ -0,0 +1,8 @@
|
|||
require 'test_helper'
|
||||
|
||||
class TrackControllerTest < ActionController::TestCase
|
||||
# Replace this with your real tests.
|
||||
test "the truth" do
|
||||
assert true
|
||||
end
|
||||
end
|
|
@ -0,0 +1,8 @@
|
|||
require 'test_helper'
|
||||
|
||||
class AlbumPicTest < ActiveSupport::TestCase
|
||||
# Replace this with your real tests.
|
||||
test "the truth" do
|
||||
assert true
|
||||
end
|
||||
end
|
|
@ -0,0 +1,4 @@
|
|||
require 'test_helper'
|
||||
|
||||
class TrackHelperTest < ActionView::TestCase
|
||||
end
|
|
@ -1 +0,0 @@
|
|||
2408
|
Loading…
Reference in New Issue