diff --git a/apps/media/ajax/api.php b/apps/media/ajax/api.php index e0183ff05d..6014e4976c 100644 --- a/apps/media/ajax/api.php +++ b/apps/media/ajax/api.php @@ -53,6 +53,7 @@ if(!isset($arguments['search'])){ $arguments['search']=''; } OC_MEDIA_COLLECTION::$uid=OC_User::getUser(); +unset($_SESSION['collection']); if($arguments['action']){ switch($arguments['action']){ case 'delete': @@ -83,13 +84,6 @@ if($arguments['action']){ OC_DB::beginTransaction(); set_time_limit(0); //recursive scan can take a while $path=$arguments['path']; - if(OC_Filesystem::is_dir($path)){ - $paths=explode(PATH_SEPARATOR,OC_Preferences::getValue(OC_User::getUser(),'media','paths','')); - if(array_search($path,$paths)===false){ - $paths[]=$path; - OC_Preferences::setValue(OC_User::getUser(),'media','paths',implode(PATH_SEPARATOR,$paths)); - } - } echo OC_MEDIA_SCANNER::scanFolder($path); OC_DB::commit(); flush(); @@ -108,16 +102,18 @@ if($arguments['action']){ echo json_encode(OC_MEDIA_COLLECTION::getSongs($arguments['artist'],$arguments['album'],$arguments['search'])); break; case 'get_path_info': - $songId=OC_MEDIA_COLLECTION::getSongByPath($arguments['path']); - if($songId==0){ - unset($_SESSION['collection']); - $songId= OC_MEDIA_SCANNER::scanFile($arguments['path']); - } - if($songId>0){ - $song=OC_MEDIA_COLLECTION::getSong($songId); - $song['artist']=OC_MEDIA_COLLECTION::getArtistName($song['song_artist']); - $song['album']=OC_MEDIA_COLLECTION::getAlbumName($song['song_album']); - echo json_encode($song); + if(OC_Filesystem::file_exists($arguments['path'])){ + $songId=OC_MEDIA_COLLECTION::getSongByPath($arguments['path']); + if($songId==0){ + unset($_SESSION['collection']); + $songId= OC_MEDIA_SCANNER::scanFile($arguments['path']); + } + if($songId>0){ + $song=OC_MEDIA_COLLECTION::getSong($songId); + $song['artist']=OC_MEDIA_COLLECTION::getArtistName($song['song_artist']); + $song['album']=OC_MEDIA_COLLECTION::getAlbumName($song['song_album']); + echo json_encode($song); + } } break; case 'play': @@ -129,14 +125,46 @@ if($arguments['action']){ OC_MEDIA_COLLECTION::registerPlay($songId); header('Content-Type:'.$ftype); + // calc an offset of 24 hours + $offset = 3600 * 24; + // calc the string in GMT not localtime and add the offset + $expire = "Expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT"; + //output the HTTP header + Header($expire); header('Expires: 0'); - header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); + header('Cache-Control: max-age=3600, must-revalidate'); header('Pragma: public'); + header('Accept-Ranges: bytes'); header('Content-Length: '.OC_Filesystem::filesize($arguments['path'])); + $gmt_mtime = gmdate('D, d M Y H:i:s', OC_Filesystem::filemtime($arguments['path']) ) . ' GMT'; + header("Last-Modified: " . $gmt_mtime ); OC_Filesystem::readfile($arguments['path']); exit; + case 'find_music': + echo json_encode(findMusic()); + exit; } } +function findMusic($path='/'){ + $music=array(); + $dh=OC_Filesystem::opendir($path); + if($dh){ + while($filename=readdir($dh)){ + if($filename[0]!='.'){ + $file=$path.'/'.$filename; + if(OC_Filesystem::is_dir($file)){ + $music=array_merge($music,findMusic($file)); + }else{ + if(OC_MEDIA_SCANNER::isMusic($filename)){ + $music[]=$file; + } + } + } + } + } + return $music; +} + ?> \ No newline at end of file diff --git a/apps/media/appinfo/app.php b/apps/media/appinfo/app.php index 20c58689f0..4cdb36d450 100644 --- a/apps/media/appinfo/app.php +++ b/apps/media/appinfo/app.php @@ -26,8 +26,7 @@ OC_Util::addScript('media','loader'); OC_App::register( array( 'order' => 3, 'id' => 'media', 'name' => 'Media' )); -OC_App::addNavigationEntry( array( 'id' => 'media_index', 'order' => 2, 'href' => OC_Helper::linkTo( 'media', 'index.php' ), 'icon' => OC_Helper::imagePath( 'media', 'media.png' ), 'name' => 'Media' )); -OC_App::addSettingsPage( array( 'id' => 'media_settings', 'order' => 5, 'href' => OC_Helper::linkTo( 'media', 'settings.php' ), 'name' => 'Media', 'icon' => OC_Helper::imagePath( 'media', 'media.png' ))); +OC_App::addNavigationEntry( array( 'id' => 'media_index', 'order' => 2, 'href' => OC_Helper::linkTo( 'media', 'index.php' ), 'icon' => OC_Helper::imagePath( 'media', 'media.png' ), 'name' => 'Music' )); // add subnavigations $entry = array( diff --git a/apps/media/index.php b/apps/media/index.php index 43423d27de..a7128aaad4 100644 --- a/apps/media/index.php +++ b/apps/media/index.php @@ -37,6 +37,7 @@ OC_Util::addScript('media','player'); OC_Util::addScript('media','music'); OC_Util::addScript('media','playlist'); OC_Util::addScript('media','collection'); +OC_Util::addScript('media','scanner'); OC_Util::addScript('media','jquery.jplayer.min'); OC_Util::addStyle('media','player'); OC_Util::addStyle('media','music'); diff --git a/apps/media/js/collection.js b/apps/media/js/collection.js index 95e5293ea4..42d249112b 100644 --- a/apps/media/js/collection.js +++ b/apps/media/js/collection.js @@ -32,6 +32,10 @@ Collection={ for(var i=0;i=PlayList.items.length){ @@ -19,7 +20,7 @@ var PlayList={ PlayList.play(next); PlayList.render(); }, - play:function(index,ready){ + play:function(index,time,ready){ if(index==null){ index=PlayList.current; } @@ -28,11 +29,11 @@ var PlayList={ if(PlayList.player){ if(PlayList.player.data('jPlayer').options.supplied!=PlayList.items[index].type){//the the audio type changes we need to reinitialize jplayer PlayList.player.jPlayer("destroy"); - PlayList.init(PlayList.items[index].type,function(){PlayList.play(null,ready)}); + PlayList.init(PlayList.items[index].type,function(){PlayList.play(null,time,eady)}); }else{ PlayList.player.jPlayer("setMedia", PlayList.items[PlayList.current]); PlayList.items[index].playcount++; - PlayList.player.jPlayer("play"); + PlayList.player.jPlayer("play",time); localStorage.setItem(oc_current_user+'oc_playlist_current',index); if(index>0){ var previous=index-1; @@ -82,6 +83,14 @@ var PlayList={ play:function(){ localStorage.setItem(oc_current_user+'oc_playlist_playing','true'); }, + timeupdate:function(){ + var time=Math.round(PlayList.player.data('jPlayer').status.currentTime); + localStorage.setItem(oc_current_user+'oc_playlist_time',time); + }, + volumechange:function(){ + var volume=PlayList.player.data('jPlayer').options.volume*100; + localStorage.setItem(oc_current_user+'oc_playlist_volume',volume); + }, supplied:type, ready:function(){ PlayList.load(); @@ -89,6 +98,7 @@ var PlayList={ ready(); } }, + volume:PlayList.volume, cssSelectorAncestor:'#jp-interface', swfPath:OC.linkTo('media','js'), }); @@ -150,11 +160,20 @@ var PlayList={ if(typeof localStorage !== 'undefined'){ if(localStorage.hasOwnProperty(oc_current_user+'oc_playlist_items')){ PlayList.items=JSON.parse(localStorage.getItem(oc_current_user+'oc_playlist_items')); - PlayList.current=parseInt((localStorage.getItem(oc_current_user+'oc_playlist_current'))); + PlayList.current=parseInt(localStorage.getItem(oc_current_user+'oc_playlist_current')); + var time=parseInt(localStorage.getItem(oc_current_user+'oc_playlist_time')); + if(localStorage.hasOwnProperty(oc_current_user+'oc_playlist_volume')){ + var volume=localStorage.getItem(oc_current_user+'oc_playlist_volume'); + PlayList.volume=volume/100; + $('.jp-volume-bar-value').css('width',volume+'%'); + if(PlayList.player.data('jPlayer')){ + PlayList.player.jPlayer("option",'volume',volume/100); + } + } if(JSON.parse(localStorage.getItem(oc_current_user+'oc_playlist_playing'))){ - PlayList.play(); + PlayList.play(null,time); }else{ - PlayList.play(null,function(){ + PlayList.play(null,time,function(){ PlayList.player.jPlayer("pause"); }); } diff --git a/apps/media/js/scanner.js b/apps/media/js/scanner.js new file mode 100644 index 0000000000..de67c7c993 --- /dev/null +++ b/apps/media/js/scanner.js @@ -0,0 +1,76 @@ +Scanner={ + songsFound:0, + songsScanned:0, + songsChecked:0, + startTime:null, + endTime:null, + stopScanning:false, + currentIndex:-1, + songs:[], + findSongs:function(ready){ + $.getJSON(OC.linkTo('media','ajax/api.php')+'?action=find_music',function(songs){ + Scanner.songsFound=songs.length; + Scanner.currentIndex=-1 + if(ready){ + ready(songs) + } + }); + }, + scanFile:function(path,ready){ + path=encodeURIComponent(path); + $.getJSON(OC.linkTo('media','ajax/api.php')+'?action=get_path_info&path='+path,function(song){ + Scanner.songsChecked++; + if(ready){ + ready(song); + } + if(song){//do this after the ready call so we dont hold up the next ajax call + var artistId=song.song_artist; + Scanner.songsScanned++; + $('#scan span.songCount').text(Scanner.songsScanned); + var progress=(Scanner.songsChecked/Scanner.songsFound)*100; + $('#scanprogressbar').progressbar('value',progress) + Collection.addSong(song); + } + }); + }, + scanCollection:function(ready){ + $('#scanprogressbar').progressbar({ + value:0, + }); + Scanner.songsChecked=0; + Scanner.songsScanned=0; + Scanner.startTime=new Date().getTime()/1000; + Scanner.findSongs(function(songs){ + Scanner.songs=songs; + Scanner.start(); + }); + }, + stop:function(){ + Scanner.stopScanning=true; + }, + start:function(ready){ + Scanner.stopScanning=false; + var scanSong=function(){ + Scanner.currentIndex++; + if(!Scanner.stopScanning && Scanner.currentIndex. -* -*/ - - -require_once('../../lib/base.php'); - -if( !OC_User::isLoggedIn()){ - header( "Location: ".OC_Helper::linkTo( "index.php" )); - exit(); -} - -require( 'lib_collection.php' ); - -OC_Util::addStyle('media','style'); -OC_Util::addScript('media','settings'); - -OC_App::setActiveNavigationEntry( 'media_settings' ); - -$folderNames=explode(PATH_SEPARATOR,OC_Preferences::getValue($_SESSION['user_id'],'media','paths','')); -$folders=array(); -foreach($folderNames as $folder){ - if($folder){ - $folders[]=array('name'=>$folder,'songs'=>OC_MEDIA_COLLECTION::getSongCountByPath($folder)); - } -} - -$tmpl = new OC_Template( 'media', 'settings', 'admin' ); -$tmpl->assign('folders',$folders); -$tmpl->assign('autoupdate',OC_Preferences::getValue($_SESSION['user_id'],'media','autoupdate',false)); -$tmpl->printPage(); -?> - diff --git a/apps/media/templates/collection.php b/apps/media/templates/collection.php index e2c256a648..fe50bf5ebd 100644 --- a/apps/media/templates/collection.php +++ b/apps/media/templates/collection.php @@ -1,3 +1,9 @@ +
+

0 Songs scanned

+
+ + +
\ No newline at end of file + + diff --git a/core/css/styles.css b/core/css/styles.css index ff2aa98dda..fa7421e094 100644 --- a/core/css/styles.css +++ b/core/css/styles.css @@ -1,6 +1,6 @@ * { margin:0; padding:0; border:0; cursor:default; } body { background:#fefefe; font:normal 80%/1.6em "Lucida Grande", Arial, Verdana, sans-serif; color:#000; } -#header { position:fixed; top:0; z-index:100; width:100%; height:2.5em; padding:0.5em 1.5em; background:#1d2d44; -moz-box-shadow:0 0 10px #000, inset 0 -2px 10px #222; -webkit-box-shadow:0 0 10px #000, inset 0 -2px 10px #222; box-shadow:0 0 10px #000, inset 0 -2px 10px #222; } +#header { position:fixed; top:0; z-index:100; width:100%; height:2.5em; padding:.5em; background:#1d2d44; -moz-box-shadow:0 0 10px #000, inset 0 -2px 10px #222; -webkit-box-shadow:0 0 10px #000, inset 0 -2px 10px #222; box-shadow:0 0 10px #000, inset 0 -2px 10px #222; } #body-settings #header { background:#313131; } #owncloud { float:left; } h1 { margin:1em 3em 1em 0; border-bottom:1px solid #666; text-transform:uppercase; font-weight:normal; font-style:italic; color:#666; } @@ -72,7 +72,7 @@ filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#35537a', end .prettybutton:hover, .prettybutton:focus { background-color:#ccc; outline:0; } /* META NAVIGATION (Settings, Log out) ---------------------------------------------------------------- */ -#metanav { float:right; position:relative; top:0.5em; right:2.5em; list-style:none; margin:0; padding:0; } +#metanav { float:right; position:relative; top:.5em; right:1em; list-style:none; margin:0; padding:0; } #metanav li { display:inline; } #metanav li a { margin:.2em; padding:.7em; } #metanav li a:hover, #metanav li a:focus { background:rgba(0,0,0,.5); -moz-border-radius:5px; -webkit-border-radius:5px; border-radius:5px; box-shadow:#555 0 1px 0; -moz-box-shadow:#555 0 1px 0; -webkit-box-shadow:#555 0 1px 0; } @@ -83,17 +83,16 @@ form.searchbox { display:inline; position:fixed; top:.9em; right:9em; margin:0; input[type="search"] { font-size:1em; padding-left:2em; background:#eee url('../img/actions/search.png') .5em center no-repeat; } /* NAVIGATION ------------------------------------------------------------- */ -#plugins { position:fixed; top:3.5em; float:left; width:15.7em; padding:0; z-index:50; height:100%; background:#eee; border-right: 1px #ccc solid; -moz-box-shadow: -3px 0 7px #000; -webkit-box-shadow: -3px 0 7px #000; box-shadow: -3px 0 7px #000; } } -#plugins ul { list-style-type:none; border-top:1px solid #ccc; } -#plugins a { display:block; padding:0.5em 0.5em 0.5em 3em; background-position:1.5em center; background-repeat:no-repeat; border-bottom:1px solid #ddd; border-top:1px solid #fff; text-decoration:none; font-size:1.2em; color:#666; } -#plugins a.active, #plugins a:hover, #plugins a:focus, #plugins a.selected { background-color:#ccc; border-top:1px solid #ccc; border-bottom:1px solid #ccc; color:#000; outline:0; } -#plugins a:active { outline:0; } -#plugins .subentry { background-color:#ddd; border-top:1px solid #aaa; color:#000; outline:0; } -#plugins .subentry.active { background-color:#bbb; border-top:1px solid #aaa; color:#000; outline:0; } -#plugins li.subentry a { padding-left:3.7em; font-size:1em; } +#navigation { position:fixed; top:3.5em; float:left; width:12.5em; padding:0; z-index:50; height:100%; background:#eee; border-right: 1px #ccc solid; -moz-box-shadow: -3px 0 7px #000; -webkit-box-shadow: -3px 0 7px #000; box-shadow: -3px 0 7px #000; } } +#navigation ul { list-style-type:none; border-top:1px solid #ccc; } +#navigation a { display:block; padding:.5em .5em .5em 2.5em; background-position:1em center; background-repeat:no-repeat; border-bottom:1px solid #ddd; border-top:1px solid #fff; text-decoration:none; font-size:1.2em; color:#666; } +#navigation a.active, #navigation a:hover, #navigation a:focus, #navigation a.selected { background-color:#ccc; border-top:1px solid #c8c8c8; border-bottom:1px solid #ccc; color:#000; outline:0; } +#navigation .subentry { background-color:#ddd; border-top:1px solid #aaa; color:#555; outline:0; } +#navigation .subentry.active { background-color:#bbb; border-top:1px solid #888; border-bottom:1px solid #bbb; outline:0; } +#navigation li.subentry a { padding-left:3.1em; font-size:1em; } /* CONTENT ------------------------------------------------------------------ */ -#content { margin:3.5em 0 0 15.7em; } +#content { margin:3.5em 0 0 12.5em; } /* USER SETTINGS ------------------------------------------------------------ */ #quota_indicator { margin:0 4em 1em 0; padding:0; border:1px solid #ddd; border-radius:10px; -webkit-border-radius:10px; -moz-border-radius:10px; } diff --git a/core/templates/layout.admin.php b/core/templates/layout.admin.php index be4419af84..d70c54f7b1 100644 --- a/core/templates/layout.admin.php +++ b/core/templates/layout.admin.php @@ -37,7 +37,7 @@
-
+