2015-12-13 04:42:28 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Providers;
|
|
|
|
|
2018-08-19 09:05:33 +00:00
|
|
|
use App\Events\AlbumInformationFetched;
|
|
|
|
use App\Events\ArtistInformationFetched;
|
|
|
|
use App\Events\LibraryChanged;
|
|
|
|
use App\Events\SongLikeToggled;
|
|
|
|
use App\Events\SongStartedPlaying;
|
|
|
|
use App\Listeners\ClearMediaCache;
|
|
|
|
use App\Listeners\DownloadAlbumCover;
|
|
|
|
use App\Listeners\DownloadArtistImage;
|
|
|
|
use App\Listeners\LoveTrackOnLastfm;
|
|
|
|
use App\Listeners\TidyLibrary;
|
|
|
|
use App\Listeners\UpdateLastfmNowPlaying;
|
2015-12-13 04:42:28 +00:00
|
|
|
use App\Models\Album;
|
2016-03-22 08:22:39 +00:00
|
|
|
use App\Models\File;
|
2016-03-23 13:23:13 +00:00
|
|
|
use App\Models\Song;
|
2017-06-03 16:35:08 +00:00
|
|
|
use Exception;
|
2015-12-13 04:42:28 +00:00
|
|
|
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
|
|
|
|
|
|
|
class EventServiceProvider extends ServiceProvider
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The event listener mappings for the application.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $listen = [
|
2018-08-19 09:05:33 +00:00
|
|
|
SongLikeToggled::class => [
|
|
|
|
LoveTrackOnLastfm::class,
|
2015-12-13 04:42:28 +00:00
|
|
|
],
|
2016-02-02 07:47:00 +00:00
|
|
|
|
2018-08-19 09:05:33 +00:00
|
|
|
SongStartedPlaying::class => [
|
|
|
|
UpdateLastfmNowPlaying::class,
|
2015-12-23 06:26:16 +00:00
|
|
|
],
|
2016-02-02 07:47:00 +00:00
|
|
|
|
2018-08-19 09:05:33 +00:00
|
|
|
LibraryChanged::class => [
|
|
|
|
TidyLibrary::class,
|
|
|
|
ClearMediaCache::class,
|
|
|
|
],
|
|
|
|
|
|
|
|
AlbumInformationFetched::class => [
|
|
|
|
DownloadAlbumCover::class,
|
|
|
|
],
|
|
|
|
|
|
|
|
ArtistInformationFetched::class => [
|
|
|
|
DownloadArtistImage::class,
|
2016-02-02 07:47:00 +00:00
|
|
|
],
|
2015-12-13 04:42:28 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register any other events for your application.
|
|
|
|
*/
|
2016-09-26 06:30:00 +00:00
|
|
|
public function boot()
|
2015-12-13 04:42:28 +00:00
|
|
|
{
|
2016-09-26 06:30:00 +00:00
|
|
|
parent::boot();
|
2015-12-13 04:42:28 +00:00
|
|
|
|
|
|
|
// Generate a unique hash for a song from its path to be the ID
|
|
|
|
Song::creating(function ($song) {
|
2016-03-22 08:22:39 +00:00
|
|
|
$song->id = File::getHash($song->path);
|
2015-12-13 04:42:28 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// Remove the cover file if the album is deleted
|
|
|
|
Album::deleted(function ($album) {
|
|
|
|
if ($album->hasCover) {
|
2017-06-03 16:35:08 +00:00
|
|
|
try {
|
|
|
|
unlink(app()->publicPath()."/public/img/covers/{$album->cover}");
|
2017-06-03 16:48:13 +00:00
|
|
|
} catch (Exception $e) {
|
|
|
|
}
|
2015-12-13 04:42:28 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|