parse($input->filename); if ($input->mediaType === "tvshows" && !property_exists($ptn, 'episode') && !property_exists($ptn, 'season') ) { $input->filename = $input->episodeId . '_' . $input->filename; } $download = $this->downloadRepository->insert( $this->getUser(), $input->url, $input->title, $input->filename, $input->imdbId, $input->mediaType, "", ); $this->downloadRepository->getEntityManager()->persist($download); $this->downloadRepository->getEntityManager()->flush(); $input->downloadId = $download->getId(); $input->userId = $this->getUser()->getId(); try { $this->bus->dispatch($input->toCommand()); } catch (\Throwable $exception) { return $this->json(['error' => $exception->getMessage()], Response::HTTP_INTERNAL_SERVER_ERROR); } $this->broadcaster->alert( title: 'Success', message: "$input->title added to Queue." ); return $this->json(['status' => 200, 'message' => 'Added to Queue']); } #[Route('/api/download/{downloadId}', name: 'api_download_delete', methods: ['DELETE'])] public function deleteDownload( DeleteDownloadInput $input, DeleteDownloadHandler $handler, ): Response { $result = $handler->handle($input->toCommand()); $this->broadcaster->alert( title: 'Success', message: "{$result->download->getTitle()} has been deleted.", ); return $this->json(['status' => 200, 'message' => 'Download Deleted']); } #[Route('/api/download/{downloadId}/pause', name: 'api_download_pause', methods: ['PATCH'])] public function pauseDownload( PauseDownloadInput $input, PauseDownloadHandler $handler, ): Response { $result = $handler->handle($input->toCommand()); $this->broadcaster->alert( title: 'Success', message: "{$result->download->getTitle()} has been Paused.", ); return $this->json(['status' => 200, 'message' => 'Download Paused']); } #[Route('/api/download/{downloadId}/resume', name: 'api_download_resume', methods: ['PATCH'])] public function resumeDownload( ResumeDownloadInput $input, ResumeDownloadHandler $handler, ): Response { $result = $handler->handle($input->toCommand()); $this->broadcaster->alert( title: 'Success', message: "{$result->download->getTitle()} has been Resumed.", ); return $this->json(['status' => 200, 'message' => 'Download Resumed']); } }