diff --git a/app/assets/javascripts/player.coffee b/app/assets/javascripts/player.coffee index b1ce5b3..f660f71 100644 --- a/app/assets/javascripts/player.coffee +++ b/app/assets/javascripts/player.coffee @@ -91,9 +91,9 @@ class window.Player _vk_music.search track.artist, track.name, track.length, (audio) -> if audio is null _session.query '/track/report', { id: track.id }, (r) -> - if r.status is 'success' - $('.playlist li[data-id="'+track.id+'"]').addClass("unavailable") - $($('.album div[data-id="'+track.id+'"]').siblings()[0]).addClass("unavailable") + if r.result is 'success' + $(".playlist li[data-id='#{track.id}']").addClass("unavailable") + $($(".album div[data-id='#{track.id}']").siblings()[0]).addClass("unavailable") _player.setTrack _player.nextTrack() else _player.playSource audio.url @@ -103,18 +103,15 @@ class window.Player s = len - Math.floor(len / 60) * 60 duration = m + ':' + (if s < 10 then '0' else '') + s _session.query '/track/update_length', { track_id: track.id, length: len }, (r) -> - if r.status is 'success' - $('.playlist li[data-id="'+track.id+'"] .song-duration').text(duration) - $($('.album div[data-id="'+track.id+'"]').siblings()[0]).text(duration) + if r.result is 'success' + $(".playlist li[data-id='#{track.id}'] .song-duration").text(duration) + $($(".album div[data-id='#{track.id}']").siblings()[0]).text(duration) _player.updateNowListening track false false getTrackInfo: (id) -> - for track in _player.playlist - if parseInt(track.id, 10) == parseInt(id, 10) - return track - false + @library[id] getAlbumInfo: (id) -> for album in _player.albums diff --git a/app/assets/javascripts/vksearch/vkontakte_search.coffee b/app/assets/javascripts/vksearch/vkontakte_search.coffee index e21d360..240897f 100644 --- a/app/assets/javascripts/vksearch/vkontakte_search.coffee +++ b/app/assets/javascripts/vksearch/vkontakte_search.coffee @@ -59,7 +59,7 @@ class window.VkontakteMusic data prepareQuery: (artist, track) -> - artist+" "+this.trim(/[\w\d\s]+/.exec(track)[0]).replace(/\(.*\)/i, '').split('/')[0] + artist+" "+this.trim(/[a-zA-Zа-яА-Я0-9\s-]+/.exec(track)[0]).replace(/\(.*\)/i, '').split('/')[0] trim: (str) -> while str.indexOf(' ') isnt -1 diff --git a/app/controllers/artist_controller.rb b/app/controllers/artist_controller.rb index 602a069..6a7f6f4 100644 --- a/app/controllers/artist_controller.rb +++ b/app/controllers/artist_controller.rb @@ -32,7 +32,7 @@ class ArtistController < ApplicationController title: @artist.name, status: @artist.status_str, callback: {object: :player, action: :updateLibrary}, - cache_for: 1.day + cache_for: (1.day if @artist.status_str == "ok") ) end diff --git a/app/models/music/album.rb b/app/models/music/album.rb index 1350216..bcf8ad3 100644 --- a/app/models/music/album.rb +++ b/app/models/music/album.rb @@ -5,6 +5,7 @@ class Album < ActiveRecord::Base has_many :release_formats, :through => :album_formats default_scope where(:master => true) + after_save :clear_artist_cache def self.with_format f joins(:release_formats).where(:release_formats => { :hash => f.to_s }) @@ -18,4 +19,10 @@ class Album < ActiveRecord::Base tracks: tracks.map(&:serialize) } end + +private + + def clear_artist_cache + artist.clear_cache + end end diff --git a/app/models/music/artist.rb b/app/models/music/artist.rb index 7c3779c..403a91b 100644 --- a/app/models/music/artist.rb +++ b/app/models/music/artist.rb @@ -6,6 +6,7 @@ class Artist < ActiveRecord::Base has_many :playlists after_initialize :prepare_description + after_save :clear_cache def status_str %w(loading ok fail)[self.status] diff --git a/app/models/music/track.rb b/app/models/music/track.rb index 8ceceb2..007cc4a 100644 --- a/app/models/music/track.rb +++ b/app/models/music/track.rb @@ -4,6 +4,8 @@ class Track < ActiveRecord::Base has_many :artists, :through => :track_artists has_many :playlist_items + after_save :clear_artist_cache + def duration if self.length time = self.length @@ -28,4 +30,10 @@ class Track < ActiveRecord::Base album_pic: album.pic_url } end + +private + + def clear_artist_cache + artists.each(&:clear_cache) + end end diff --git a/lib/discogs.rb b/lib/discogs.rb index a887f79..df2dfc3 100644 --- a/lib/discogs.rb +++ b/lib/discogs.rb @@ -155,7 +155,7 @@ class Discogs } end end - ap albums + albums end def self.search_for_artist name