diff options
Diffstat (limited to 'apps/media/js')
-rw-r--r-- | apps/media/js/collection.js | 50 | ||||
-rw-r--r-- | apps/media/js/music.js | 25 |
2 files changed, 63 insertions, 12 deletions
diff --git a/apps/media/js/collection.js b/apps/media/js/collection.js index b8fd515ba60..95e5293ea48 100644 --- a/apps/media/js/collection.js +++ b/apps/media/js/collection.js @@ -109,18 +109,8 @@ Collection={ }, registerPlay:function(){ var item=PlayList.items[PlayList.current]; - for(var i=0;i<Collection.artists.length;i++){ - var artist=Collection.artists[i]; - for(var j=0;j<artist.albums.length;j++){ - var album=artist.albums[j] - for(var w=0;w<album.songs.length;w++){ - var song=album.songs[w]; - if(song.song_name==item.name && song.artist_name==item.artist && song.album_name==item.album){ - song.song_playcount++; - } - } - } - } + var song=Collection.findSong(item.artist,item.album,item.name); + song.song_playcount++; }, addButtons:function(parent){ parent.children('button.add').click(function(){ @@ -133,6 +123,42 @@ Collection={ PlayList.add($(this).parent().data(type)); PlayList.play(oldSize); }); + }, + find:function(artistName,albumName,songName){ + if(songName){ + return Collection.findSong(artistName,albumName,songName); + }else if(albumName){ + return Collection.findAlbum(artistName,albumName); + }else{ + return Collection.findArtist(artistName); + } + }, + findArtist:function(name){ + for(var i=0;i<Collection.artists.length;i++){ + if(Collection.artists[i].artist_name==name){ + return Collection.artists[i]; + } + } + }, + findAlbum:function(artistName,albumName){ + var artist=Collection.findArtist(artistName); + if(artist){ + for(var i=0;i<artist.albums.length;i++){ + if(artist.albums[i].album_name==albumName){ + return artist.albums[i]; + } + } + } + }, + findSong:function(artistName,albumName,songName){ + var album=Collection.findAlbum(artistName,albumName); + if(album){ + for(var i=0;i<album.songs.length;i++){ + if(album.songs[i].song_name==songName){ + return album.songs[i]; + } + } + } } } diff --git a/apps/media/js/music.js b/apps/media/js/music.js index b2464c3842f..a9e10b3d40f 100644 --- a/apps/media/js/music.js +++ b/apps/media/js/music.js @@ -16,6 +16,31 @@ $(document).ready(function(){ if(tab=='collection'){ $('#plugins a[href="#collection"]').trigger('click'); } + OC.search.customResults.Music=function(row,item){ + var parts=item.link.substr(item.link.indexOf('#')+1).split('&'); + var data={}; + for(var i=0;i<parts.length;i++){ + var itemParts=parts[i].split('='); + data[itemParts[0]]=decodeURIComponent(itemParts[1]).replace(/\+/g,' '); + } + var media=Collection.find(data.artist,data.album,data.song); + var button=$('<input type="button" class="play"></input>'); + button.css('background-image','url('+OC.imagePath('core','actions/play')+')') + button.click(function(){ + var oldSize=PlayList.items.length; + PlayList.add(media); + PlayList.play(oldSize); + PlayList.render(); + }); + row.find('div.name').append(button); + var button=$('<input type="button" class="add"></input>'); + button.css('background-image','url('+OC.imagePath('core','actions/play-add')+')') + button.click(function(){ + PlayList.add(media); + PlayList.render(); + }); + row.find('div.name').append(button); + } }); |