bucket}/{$request->key}"; $tags = $request->tags; $artist = Artist::get(array_get($tags, 'artist')); $compilation = (bool) trim(array_get($tags, 'albumartist')); $album = Album::get($artist, array_get($tags, 'album'), $compilation); if ($cover = array_get($tags, 'cover')) { $album->writeCoverFile(base64_decode($cover['data']), $cover['extension']); } $song = Song::updateOrCreate(['id' => Media::getHash($path)], [ 'path' => $path, 'album_id' => $album->id, 'contributing_artist_id' => $compilation ? $artist->id : null, 'title' => trim(array_get($tags, 'title', '')), 'length' => array_get($tags, 'duration', 0), 'track' => (int) array_get($tags, 'track'), 'lyrics' => array_get($tags, 'lyrics', ''), 'mtime' => time(), ]); return response()->json($song); } /** * Remove a song whose info matches with data sent from AWS. * * @param RemoveSongRequest $request * * @throws \Exception * * @return \Illuminate\Http\JsonResponse */ public function remove(RemoveSongRequest $request) { abort_unless($song = Song::byPath("s3://{$request->bucket}/{$request->key}"), 404); $song->delete(); event(new LibraryChanged()); return response()->json(); } }