|
|
|
@@ -57,8 +57,9 @@ class window.Player
|
|
|
|
|
m = Math.floor(len / 60)
|
|
|
|
|
s = len - Math.floor(len / 60) * 60
|
|
|
|
|
duration = m + ':' + (if s < 10 then '0' else '') + s
|
|
|
|
|
item_class = (if item.available == false then 'unavailable' else '')
|
|
|
|
|
$('.playlist').append '
|
|
|
|
|
<li id="i' +Math.round(Math.random() * 999999)+ '" data-id="'+item.id+'">
|
|
|
|
|
<li id="i' +Math.round(Math.random() * 999999)+ '" data-id="'+item.id+'" class="'+item_class+'">
|
|
|
|
|
<div class="song-duration">' +duration+ '</div>
|
|
|
|
|
<div class="remove">remove</div>
|
|
|
|
|
<div class="artist-name">' +item.artist+ '</div>
|
|
|
|
@@ -85,10 +86,13 @@ class window.Player
|
|
|
|
|
$('.player .now-playing').html query
|
|
|
|
|
$('.playlist li').removeClass 'now'
|
|
|
|
|
$obj.addClass 'now'
|
|
|
|
|
_vk_music.search track.artist, track.name, track.duration, (audio) ->
|
|
|
|
|
_vk_music.search track.artist, track.name, track.length, (audio) ->
|
|
|
|
|
if audio is null
|
|
|
|
|
console.log audio
|
|
|
|
|
_player.setTrack _player.nextTrack(true)
|
|
|
|
|
_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")
|
|
|
|
|
_player.setTrack _player.nextTrack()
|
|
|
|
|
else
|
|
|
|
|
_player.playSource audio.url
|
|
|
|
|
if track.length == 0
|
|
|
|
@@ -97,7 +101,7 @@ 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.result is 'success'
|
|
|
|
|
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)
|
|
|
|
|
_player.updateNowListening track
|
|
|
|
@@ -110,6 +114,12 @@ class window.Player
|
|
|
|
|
return track
|
|
|
|
|
false
|
|
|
|
|
|
|
|
|
|
getAlbumInfo: (id) ->
|
|
|
|
|
for album in _player.albums
|
|
|
|
|
if parseInt(album.id, 10) == parseInt(id, 10)
|
|
|
|
|
return album
|
|
|
|
|
false
|
|
|
|
|
|
|
|
|
|
hasTrack: ->
|
|
|
|
|
if $('#jplayer audio').length > 0
|
|
|
|
|
return $('#jplayer audio').attr('src')? and $('#jplayer audio').attr('src') != ''
|
|
|
|
@@ -240,21 +250,19 @@ $('.playlist li').live 'click', ->
|
|
|
|
|
# Adding To Playlist actions
|
|
|
|
|
|
|
|
|
|
$('.add-album').live 'click', ->
|
|
|
|
|
artist = $('.artist-info h2').text()
|
|
|
|
|
album = _player.albums[$(this).attr('data-album-id')]
|
|
|
|
|
album = _player.getAlbumInfo($(this).attr('data-album-id'))
|
|
|
|
|
for item in album.tracks
|
|
|
|
|
item['artist'] = artist
|
|
|
|
|
item['artist'] = album.artist
|
|
|
|
|
item['album'] = album.name
|
|
|
|
|
_player.addTracks album.tracks
|
|
|
|
|
false
|
|
|
|
|
|
|
|
|
|
$('.s-add').live 'click', ->
|
|
|
|
|
artist = $('.artist-info h2').text()
|
|
|
|
|
album = _player.albums[$(this).attr('data-album-id')]
|
|
|
|
|
album = _player.getAlbumInfo($(this).attr('data-album-id'))
|
|
|
|
|
item = album.tracks[$(this).attr('data-id')]
|
|
|
|
|
for item in album.tracks
|
|
|
|
|
if item.id == parseInt($(this).attr('data-id'), 10)
|
|
|
|
|
item['artist'] = artist
|
|
|
|
|
item['artist'] = album.artist
|
|
|
|
|
item['album'] = album.name
|
|
|
|
|
_player.addTracks [item]
|
|
|
|
|
return false
|
|
|
|
|