koel/app/Jobs/ScrobbleJob.php

44 lines
1.1 KiB
PHP
Raw Normal View History

<?php
namespace App\Jobs;
use App\Models\Album;
use App\Models\Song;
use App\Models\User;
use App\Services\LastfmService;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
2020-09-06 21:20:42 +00:00
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class ScrobbleJob implements ShouldQueue
{
2020-09-06 21:20:42 +00:00
use Dispatchable;
use InteractsWithQueue;
use Queueable;
use SerializesModels;
2021-06-05 10:47:56 +00:00
private User $user;
private Song $song;
private int $timestamp;
public function __construct(User $user, Song $song, int $timestamp)
{
$this->user = $user;
$this->song = $song;
$this->timestamp = $timestamp;
}
public function handle(LastfmService $lastfmService): void
{
$lastfmService->scrobble(
$this->song->artist->name,
$this->song->title,
$this->timestamp,
$this->song->album->name === Album::UNKNOWN_NAME ? '' : $this->song->album->name,
$this->user->lastfm_session_key
);
}
}