From 6a3a06bed2948ad4a3e3d120d7f01a2a34ca62f3 Mon Sep 17 00:00:00 2001 From: David Collinson Date: Wed, 16 Oct 2013 02:49:01 +0100 Subject: [PATCH 01/39] Attempt to make the stream buffer and play properly --- app/views/default/home.blade.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/views/default/home.blade.php b/app/views/default/home.blade.php index e3c98b8..2642ab3 100644 --- a/app/views/default/home.blade.php +++ b/app/views/default/home.blade.php @@ -173,12 +173,12 @@ @section('script') @stop From f3eca66995dc9c1302d14916002dab8d04f0de2e Mon Sep 17 00:00:00 2001 From: David Collinson Date: Sat, 19 Oct 2013 14:11:46 +0100 Subject: [PATCH 02/39] Change default stream URI --- app/views/default/home.blade.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/views/default/home.blade.php b/app/views/default/home.blade.php index 2642ab3..ef11182 100644 --- a/app/views/default/home.blade.php +++ b/app/views/default/home.blade.php @@ -178,7 +178,7 @@ function createStream() { console.log('creating new element'); // the only way to flush the audio buffer is to re-create the element. - $('').appendTo('#stream-container'); + $('').appendTo('#stream-container'); // event handler for audio loading $('#stream').on('loadeddata', function() { @@ -186,11 +186,20 @@ function createStream() { $('#stream-player').html('Stop Stream'); }); + $('#stream').on('canplay', function() { + console.log('attempting to play the stream...'); + document.getElementById('stream').play(); + }); + // error logging $('#stream').on('error', function(event) { console.log(event); }); + $('#stream').on('waiting', function(event) { + console.log('waiting... ' + event); + }); + // Show the volume slider $('#stream-volume').show(); @@ -199,6 +208,8 @@ function createStream() { function stopStream() { // initially pause the element to stop audio document.getElementById('stream').pause(); + document.getElementById('stream').currentTime = 0; + document.getElementById('stream').load(); // Hide the volume slider now that we're done with it. $('#stream-volume').hide(); From 04c48ac4bd51b8d618674004000a4005b74ece3b Mon Sep 17 00:00:00 2001 From: David Collinson Date: Sat, 19 Oct 2013 14:12:30 +0100 Subject: [PATCH 03/39] Add search functions! --- app/controllers/Player.php | 16 ++++++ app/controllers/Search.php | 54 ++++++++++++++++++ app/routes.php | 4 ++ app/views/default/search.blade.php | 89 ++++++++++++++++++++++++++++++ public/css/base.css | 30 +++++++++- 5 files changed, 192 insertions(+), 1 deletion(-) create mode 100644 app/controllers/Search.php create mode 100644 app/views/default/search.blade.php diff --git a/app/controllers/Player.php b/app/controllers/Player.php index 4573a6a..286ed5d 100644 --- a/app/controllers/Player.php +++ b/app/controllers/Player.php @@ -15,6 +15,22 @@ class Player extends BaseController { | */ + /** + * + */ + protected function getSongDelay($priority) { + // priority is 30 max + if ($priority > 30) + $priority = 30; + + // between 0 and 7 return magic + if ($priority >= 0 and $priority <= 7) + return -11057 * $priority * $priority + 172954 * $priority + 81720; + // if above that, return magic crazy numbers + else + return (int) (599955 * exp(0.0372 * $priority) + 0.5); + } + /** * Retrieve the current queue. * diff --git a/app/controllers/Search.php b/app/controllers/Search.php new file mode 100644 index 0000000..bb5f258 --- /dev/null +++ b/app/controllers/Search.php @@ -0,0 +1,54 @@ +where('usable', '=', 1) + ->where('need_reupload', '=', 0) + ->whereRaw('match (artist, track, album, tags) against (?)', [$search]) + ->select("id", "track", "artist", "album", "tags", "lastplayed", "lastrequested", "requestcount", "priority") + ->get(); + + $count = 0; + + foreach ($results as &$result) { + + + $result["break"] = $count; + if ($count == 2) + $count = 0; + else + $count++; + + $delay = $this->getSongDelay((int) $result["requestcount"]); + + if ((time() - strtotime($result["lastrequested"])) > $delay) + $result["cooldown"] = false; + else + $result["cooldown"] = true; + + // lets us ->format() the resulting time + $result["lastplayed"] = new DateTime($result["lastplayed"]); + $result["lastrequested"] = new DateTime($result["lastrequested"]); + } + return $results; + } else { + return []; + } + } + + public function showResults($search = false) { + + if (Input::has('q')) + $search = Input::get("q", false); + + $this->layout->content = View::make($this->getTheme() . '.search') + ->with("search", $this->getSearchResults($search)) + ->with("base", Config::get("app.base", "")); + } + +} \ No newline at end of file diff --git a/app/routes.php b/app/routes.php index ba92955..7fb880e 100644 --- a/app/routes.php +++ b/app/routes.php @@ -26,5 +26,9 @@ # IRC Route::get('/irc', 'IRC@show'); +# Search +Route::any('/search/{search?}', 'Search@showResults'); + + # Admin controller; adds extra auth + security Route::controller('/admin', 'Admin'); diff --git a/app/views/default/search.blade.php b/app/views/default/search.blade.php new file mode 100644 index 0000000..e483975 --- /dev/null +++ b/app/views/default/search.blade.php @@ -0,0 +1,89 @@ +@section('content') + +
+ +
+
+

Search for a song.

+ {{ Form::open(['url' => $base . "/search" ]) }} +
+ +
+ +
+
+ {{ Form::close() }} + +
+
+
+

Click on a song for options

+
+
+ + +
+
+{{ var_dump($search) }}
+		
+ + @foreach ($search as $result) + + @if ($result["break"] == 0) +
+ @endif + +
+ + @if ($result["cooldown"]) +
+ @else +
+ @endif +

{{{ $result["track"] }}} - {{{ $result["artist"] }}}

+

+ Plays: ?? + | + Faves: ?? + | + @if ($result["cooldown"]) + On Cooldown + @else + Requestable + @endif +

+
+ +
+ + @if ($result["break"] == 2) +
+ @endif + + @endforeach + + + + +
+ + + +
+ +@stop + +@section('script') + +@stop \ No newline at end of file diff --git a/public/css/base.css b/public/css/base.css index 485a3f2..0ebe3bf 100644 --- a/public/css/base.css +++ b/public/css/base.css @@ -26,4 +26,32 @@ .pending { background: #463265; color: #fff; -} \ No newline at end of file +} + +.centered { + float: none; + margin: 0 auto; +} + +.search-result:hover, +.search-result:focus { + border-color: #66afe9; + outline: 0; + -webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(102, 175, 233, 0.6); + box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(102, 175, 233, 0.6); + cursor: pointer; +} + + +.search-result h4 { + margin-top: 0; + margin-bottom: 0; +} + +.search-result p { + margin: 0; +} + +.cooldown { + opacity: 0.7; +} From b84ea6b858ca1dcd85d0d6ea87bd8b5dbe5bf370 Mon Sep 17 00:00:00 2001 From: David Collinson Date: Sat, 19 Oct 2013 14:12:52 +0100 Subject: [PATCH 04/39] Add CSRF protection as default in all routes. --- app/controllers/BaseController.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/controllers/BaseController.php b/app/controllers/BaseController.php index 3791d75..1dc9776 100644 --- a/app/controllers/BaseController.php +++ b/app/controllers/BaseController.php @@ -2,6 +2,16 @@ class BaseController extends Controller { + public function __construct() { + + // Auth, naturally. + //$this->beforeFilter('auth'); + + // ALL POST/PUT/DELETE REQUIRE CSRF TOKENS. + $this->beforeFilter('csrf', ['on' => ['post', 'put', 'delete']]); + + } + /** * Retrieve the current theme's identifier. * From 91aa3ebfdcaadb65152e5cd65581f2acfaf6a533 Mon Sep 17 00:00:00 2001 From: David Collinson Date: Sat, 19 Oct 2013 14:14:29 +0100 Subject: [PATCH 05/39] Remove debug print in search --- app/views/default/search.blade.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/views/default/search.blade.php b/app/views/default/search.blade.php index e483975..c88699b 100644 --- a/app/views/default/search.blade.php +++ b/app/views/default/search.blade.php @@ -25,9 +25,6 @@
-
-{{ var_dump($search) }}
-		
@foreach ($search as $result) From fa971ecfadf9b27ae797b3aa6913378de74dc01c Mon Sep 17 00:00:00 2001 From: David Collinson Date: Sat, 19 Oct 2013 14:19:19 +0100 Subject: [PATCH 06/39] Make routing work properly this time. --- app/routes.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/app/routes.php b/app/routes.php index 7fb880e..0cb88a1 100644 --- a/app/routes.php +++ b/app/routes.php @@ -10,25 +10,25 @@ | and give it the Closure to execute when that URI is requested. | */ - +$base = Config::get("app.base", ""); # Index. -Route::get('/', 'Home@showHome'); +Route::get($base . '/', 'Home@showHome'); # News - aggregate + single -Route::get('/news', 'News@showNews'); -Route::get('/news/{id}', 'News@showSingleNews') +Route::get($base . '/news', 'News@showNews'); +Route::get($base . '/news/{id}', 'News@showSingleNews') ->where('id', '[0-9]+'); # Stats -Route::get('/stats', 'Stats@showGraphs'); -Route::get('/stats.json', 'Stats@getGraphsAjax'); +Route::get($base . '/stats', 'Stats@showGraphs'); +Route::get($base . '/stats.json', 'Stats@getGraphsAjax'); # IRC -Route::get('/irc', 'IRC@show'); +Route::get($base . '/irc', 'IRC@show'); # Search -Route::any('/search/{search?}', 'Search@showResults'); +Route::any($base . '/search/{search?}', 'Search@showResults'); # Admin controller; adds extra auth + security -Route::controller('/admin', 'Admin'); +Route::controller($base . '/admin', 'Admin'); From 1fec1511276e13d3ce4e6549b5c26993678fa41e Mon Sep 17 00:00:00 2001 From: David Collinson Date: Sat, 19 Oct 2013 14:23:37 +0100 Subject: [PATCH 07/39] Revert "Make routing work properly this time." This reverts commit fa971ecfadf9b27ae797b3aa6913378de74dc01c. --- app/routes.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/app/routes.php b/app/routes.php index 0cb88a1..7fb880e 100644 --- a/app/routes.php +++ b/app/routes.php @@ -10,25 +10,25 @@ | and give it the Closure to execute when that URI is requested. | */ -$base = Config::get("app.base", ""); + # Index. -Route::get($base . '/', 'Home@showHome'); +Route::get('/', 'Home@showHome'); # News - aggregate + single -Route::get($base . '/news', 'News@showNews'); -Route::get($base . '/news/{id}', 'News@showSingleNews') +Route::get('/news', 'News@showNews'); +Route::get('/news/{id}', 'News@showSingleNews') ->where('id', '[0-9]+'); # Stats -Route::get($base . '/stats', 'Stats@showGraphs'); -Route::get($base . '/stats.json', 'Stats@getGraphsAjax'); +Route::get('/stats', 'Stats@showGraphs'); +Route::get('/stats.json', 'Stats@getGraphsAjax'); # IRC -Route::get($base . '/irc', 'IRC@show'); +Route::get('/irc', 'IRC@show'); # Search -Route::any($base . '/search/{search?}', 'Search@showResults'); +Route::any('/search/{search?}', 'Search@showResults'); # Admin controller; adds extra auth + security -Route::controller($base . '/admin', 'Admin'); +Route::controller('/admin', 'Admin'); From 32bbbe96fdc982922483557f33e1934d930f8143 Mon Sep 17 00:00:00 2001 From: David Collinson Date: Sat, 19 Oct 2013 19:38:10 +0100 Subject: [PATCH 08/39] Start caching everything in sight. --- app/config/cache.php | 7 +++- app/controllers/Search.php | 67 +++++++++++++++++------------- app/views/default/search.blade.php | 2 +- 3 files changed, 45 insertions(+), 31 deletions(-) diff --git a/app/config/cache.php b/app/config/cache.php index ce89842..cee6746 100644 --- a/app/config/cache.php +++ b/app/config/cache.php @@ -2,6 +2,11 @@ return array( + 'times' => [ + 'search' => 3, + 'api' => '1' + ], + /* |-------------------------------------------------------------------------- | Default Cache Driver @@ -15,7 +20,7 @@ | */ - 'driver' => 'file', + 'driver' => 'redis', /* |-------------------------------------------------------------------------- diff --git a/app/controllers/Search.php b/app/controllers/Search.php index bb5f258..fdb2c4b 100644 --- a/app/controllers/Search.php +++ b/app/controllers/Search.php @@ -6,39 +6,48 @@ class Search extends Player { protected function getSearchResults($search) { if ($search) { - $results = DB::table('tracks') - ->where('usable', '=', 1) - ->where('need_reupload', '=', 0) - ->whereRaw('match (artist, track, album, tags) against (?)', [$search]) - ->select("id", "track", "artist", "album", "tags", "lastplayed", "lastrequested", "requestcount", "priority") - ->get(); - - $count = 0; - - foreach ($results as &$result) { - - - $result["break"] = $count; - if ($count == 2) - $count = 0; - else - $count++; - - $delay = $this->getSongDelay((int) $result["requestcount"]); - - if ((time() - strtotime($result["lastrequested"])) > $delay) - $result["cooldown"] = false; - else - $result["cooldown"] = true; - - // lets us ->format() the resulting time - $result["lastplayed"] = new DateTime($result["lastplayed"]); - $result["lastrequested"] = new DateTime($result["lastrequested"]); + if (Cache::section('search')->has($search)) { + + return Cache::section('search')->get($search); + + } else { + + $results = DB::table('tracks') + ->where('usable', '=', 1) + ->where('need_reupload', '=', 0) + ->whereRaw('match (artist, track, album, tags) against (?)', [$search]) + ->select("id", "track", "artist", "album", "tags", "lastplayed", "lastrequested", "requestcount", "priority") + ->get(); + + $count = 0; + + foreach ($results as &$result) { + + + $result["break"] = $count; + if ($count == 2) + $count = 0; + else + $count++; + + $delay = $this->getSongDelay((int) $result["requestcount"]); + + if ((time() - strtotime($result["lastrequested"])) > $delay) + $result["cooldown"] = false; + else + $result["cooldown"] = true; + + // lets us ->format() the resulting time + $result["lastplayed"] = new DateTime($result["lastplayed"]); + $result["lastrequested"] = new DateTime($result["lastrequested"]); + } + Cache::section('search')->put($search, $results, Config::get('cache.times.search')); + return $results; } - return $results; } else { return []; } + } public function showResults($search = false) { diff --git a/app/views/default/search.blade.php b/app/views/default/search.blade.php index c88699b..567b8c5 100644 --- a/app/views/default/search.blade.php +++ b/app/views/default/search.blade.php @@ -7,7 +7,7 @@

Search for a song.

{{ Form::open(['url' => $base . "/search" ]) }}
- +
- +