diff --git a/rails/app/controllers/track_controller.rb b/rails/app/controllers/track_controller.rb new file mode 100644 index 0000000..2867087 --- /dev/null +++ b/rails/app/controllers/track_controller.rb @@ -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 diff --git a/rails/app/helpers/track_helper.rb b/rails/app/helpers/track_helper.rb new file mode 100644 index 0000000..3e73cce --- /dev/null +++ b/rails/app/helpers/track_helper.rb @@ -0,0 +1,2 @@ +module TrackHelper +end diff --git a/rails/app/models/album.rb b/rails/app/models/album.rb index b690e06..1c3a3d2 100644 --- a/rails/app/models/album.rb +++ b/rails/app/models/album.rb @@ -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>/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>/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 diff --git a/rails/app/models/album_pic.rb b/rails/app/models/album_pic.rb new file mode 100644 index 0000000..fb818d6 --- /dev/null +++ b/rails/app/models/album_pic.rb @@ -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 diff --git a/rails/app/models/track.rb b/rails/app/models/track.rb index 25ab14d..8fdf4d4 100644 --- a/rails/app/models/track.rb +++ b/rails/app/models/track.rb @@ -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 diff --git a/rails/app/models/track_data.rb b/rails/app/models/track_data.rb index c4fd87a..1568c18 100644 --- a/rails/app/models/track_data.rb +++ b/rails/app/models/track_data.rb @@ -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 diff --git a/rails/app/views/artist/view.rhtml b/rails/app/views/artist/view.rhtml index 8b775e9..e1ba6cd 100644 --- a/rails/app/views/artist/view.rhtml +++ b/rails/app/views/artist/view.rhtml @@ -10,8 +10,8 @@ %>