2016-05-30 05:50:59 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\API;
|
|
|
|
|
2020-04-27 18:55:12 +00:00
|
|
|
use App\Jobs\ScrobbleJob;
|
2016-05-30 05:50:59 +00:00
|
|
|
use App\Models\Song;
|
2018-08-19 21:17:05 +00:00
|
|
|
use App\Services\LastfmService;
|
2017-06-04 01:30:45 +00:00
|
|
|
use Illuminate\Http\JsonResponse;
|
2017-05-01 17:49:44 +00:00
|
|
|
use Illuminate\Http\Request;
|
2016-05-30 05:50:59 +00:00
|
|
|
|
2018-12-09 21:24:43 +00:00
|
|
|
/**
|
|
|
|
* @group Last.fm integration
|
|
|
|
*/
|
2016-05-30 05:50:59 +00:00
|
|
|
class ScrobbleController extends Controller
|
|
|
|
{
|
2018-08-19 21:17:05 +00:00
|
|
|
private $lastfmService;
|
|
|
|
|
|
|
|
public function __construct(LastfmService $lastfmService)
|
|
|
|
{
|
|
|
|
$this->lastfmService = $lastfmService;
|
|
|
|
}
|
|
|
|
|
2016-05-30 05:50:59 +00:00
|
|
|
/**
|
2020-04-12 08:18:17 +00:00
|
|
|
* Scrobble a song
|
2018-12-09 21:24:43 +00:00
|
|
|
*
|
|
|
|
* Create a [Last.fm scrobble entry](https://www.last.fm/api/scrobbling) for a song.
|
2016-05-30 05:50:59 +00:00
|
|
|
*
|
2018-08-29 07:07:44 +00:00
|
|
|
* @param string $timestamp The UNIX timestamp when the song started playing.
|
2016-05-30 05:50:59 +00:00
|
|
|
*
|
2017-06-04 01:30:45 +00:00
|
|
|
* @return JsonResponse
|
2016-05-30 05:50:59 +00:00
|
|
|
*/
|
2018-08-24 15:27:19 +00:00
|
|
|
public function store(Request $request, Song $song, string $timestamp)
|
2016-05-30 05:50:59 +00:00
|
|
|
{
|
2018-09-04 06:25:24 +00:00
|
|
|
if (!$song->artist->is_unknown && $request->user()->connectedToLastfm()) {
|
2020-04-27 18:55:12 +00:00
|
|
|
ScrobbleJob::dispatch($request->user(), $song, (int) $timestamp);
|
2018-08-19 21:17:05 +00:00
|
|
|
}
|
|
|
|
|
2018-08-24 15:27:19 +00:00
|
|
|
return response()->json();
|
2016-05-30 05:50:59 +00:00
|
|
|
}
|
|
|
|
}
|