diff options
-rw-r--r-- | apps/media/css/music.css | 3 | ||||
-rw-r--r-- | apps/media/js/collection.js | 50 | ||||
-rw-r--r-- | apps/media/js/music.js | 25 | ||||
-rw-r--r-- | apps/media/lib_media.php | 10 | ||||
-rw-r--r-- | core/js/js.js | 1 | ||||
-rw-r--r-- | search/js/result.js | 6 |
6 files changed, 77 insertions, 18 deletions
diff --git a/apps/media/css/music.css b/apps/media/css/music.css index 067da79446d..3637234ab13 100644 --- a/apps/media/css/music.css +++ b/apps/media/css/music.css @@ -14,4 +14,5 @@ li button.right.prettybutton{font-size:1em;} #collection{display:none}/*hide the collection initially*/ #collection li{padding-right:10px;} -img.remove{float:right;}; +img.remove{float:right;} +#searchresults input.play, #searchresults input.add{float:right; height:16px; width:16px;} 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); + } }); diff --git a/apps/media/lib_media.php b/apps/media/lib_media.php index 67d111936f1..062672b91e8 100644 --- a/apps/media/lib_media.php +++ b/apps/media/lib_media.php @@ -93,15 +93,15 @@ class OC_MediaSearchProvider extends OC_Search_Provider{ $results[]=new OC_Search_Result($artist['artist_name'],'',OC_Helper::linkTo( 'apps/media', 'index.php#artist='.urlencode($artist['artist_name']) ),'Music'); } foreach($albums as $album){ - $artist=urlencode(OC_MEDIA_COLLECTION::getArtistName($album['album_artist'])); - $results[]=new OC_Search_Result($album['album_name'],'',OC_Helper::linkTo( 'apps/media', 'index.php#artist='.$artist.'&album='.urlencode($album['album_name']) ),'Music'); + $artist=OC_MEDIA_COLLECTION::getArtistName($album['album_artist']); + $results[]=new OC_Search_Result($album['album_name'],'by '.$artist,OC_Helper::linkTo( 'apps/media', 'index.php#artist='.urlencode($artist).'&album='.urlencode($album['album_name']) ),'Music'); } foreach($songs as $song){ $minutes=floor($song['song_length']/60); $secconds=$song['song_length']%60; - $artist=urlencode(OC_MEDIA_COLLECTION::getArtistName($song['song_artist'])); - $album=urlencode(OC_MEDIA_COLLECTION::getalbumName($song['song_album'])); - $results[]=new OC_Search_Result($song['song_name'],"$minutes:$secconds",OC_Helper::linkTo( 'apps/media', 'index.php#artist='.$artist.'&album='.$album.'&song='.urlencode($song['song_name']) ),'Music'); + $artist=OC_MEDIA_COLLECTION::getArtistName($song['song_artist']); + $album=OC_MEDIA_COLLECTION::getalbumName($song['song_album']); + $results[]=new OC_Search_Result($song['song_name'],"by $artist, in $album $minutes:$secconds",OC_Helper::linkTo( 'apps/media', 'index.php#artist='.urlencode($artist).'&album='.urlencode($album).'&song='.urlencode($song['song_name']) ),'Music'); } return $results; } diff --git a/core/js/js.js b/core/js/js.js index f85331db60a..99372c5f241 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -77,6 +77,7 @@ OC={ } } } +OC.search.customResults={}; OC.addStyle.loaded=[]; OC.addScript.loaded=[]; diff --git a/search/js/result.js b/search/js/result.js index b550d4d314d..cb5ec31cd31 100644 --- a/search/js/result.js +++ b/search/js/result.js @@ -43,6 +43,9 @@ OC.search.showResults=function(results){ row.find('td.result a').attr('href',type[0].link); row.find('td.result div.name').text(type[0].name); row.find('td.result div.text').text(type[0].text); + if(OC.search.customResults[name]){//give plugins the ability to customize the entries in here + OC.search.customResults[name](row,type[0]); + } $('#searchresults tbody').append(row); for(var i=1;i<type.length;i++){ var row=$('#searchresults tr.template').clone(); @@ -51,6 +54,9 @@ OC.search.showResults=function(results){ row.find('td.result a').attr('href',type[i].link); row.find('td.result div.name').text(type[i].name); row.find('td.result div.text').text(type[i].text); + if(OC.search.customResults[name]){//give plugins the ability to customize the entries in here + OC.search.customResults[name](row,type[i]); + } $('#searchresults tbody').append(row); } } |