-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
An Phan
committed
Dec 23, 2015
1 parent
5e79a27
commit a083696
Showing
8 changed files
with
151 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace App\Events; | ||
|
||
use App\Models\Song; | ||
use App\Models\User; | ||
use Illuminate\Queue\SerializesModels; | ||
|
||
class SongStartedPlaying extends Event | ||
{ | ||
use SerializesModels; | ||
|
||
/** | ||
* The now playing song. | ||
* | ||
* @var Song | ||
*/ | ||
public $song; | ||
|
||
/** | ||
* The user listening. | ||
* | ||
* @var User | ||
*/ | ||
public $user; | ||
|
||
/** | ||
* Create a new event instance. | ||
*/ | ||
public function __construct(Song $song, User $user) | ||
{ | ||
$this->song = $song; | ||
$this->user = $user; | ||
} | ||
|
||
/** | ||
* Get the channels the event should be broadcast on. | ||
* | ||
* @return array | ||
*/ | ||
public function broadcastOn() | ||
{ | ||
return []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace App\Listeners; | ||
|
||
use App\Events\SongStartedPlaying; | ||
use App\Models\Album; | ||
use App\Services\Lastfm; | ||
|
||
class UpdateLastfmNowPlaying | ||
{ | ||
/** | ||
* The Last.fm service instance. | ||
* | ||
* @var Lastfm | ||
*/ | ||
protected $lastfm; | ||
|
||
/** | ||
* Create the event listener. | ||
*/ | ||
public function __construct(Lastfm $lastfm) | ||
{ | ||
$this->lastfm = $lastfm; | ||
} | ||
|
||
/** | ||
* Handle the event. | ||
* | ||
* @param SongStartedPlaying $event | ||
*/ | ||
public function handle(SongStartedPlaying $event) | ||
{ | ||
if (!$this->lastfm->enabled() || | ||
!($sessionKey = $event->user->getLastfmSessionKey()) || | ||
$event->song->album->artist->isUnknown() | ||
) { | ||
return; | ||
} | ||
|
||
$this->lastfm->updateNowPlaying( | ||
$event->song->album->artist->name, | ||
$event->song->title, | ||
$event->song->album->name === Album::UNKNOWN_NAME ? null : $event->song->album->name, | ||
$event->song->length, | ||
$sessionKey | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters