|
@@ -4,9 +4,12 @@ namespace App\Http\Controllers\Orion;
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
use App\Http\Requests\Orion\GetLinkRequest;
|
|
|
+use App\Http\Requests\Orion\GetShowsLinks;
|
|
|
use App\Http\Requests\Orion\GetStreamUrl;
|
|
|
+use App\Http\Requests\Orion\RequestLink;
|
|
|
use App\Http\Services\OrionService;
|
|
|
use Illuminate\Http\Request;
|
|
|
+use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
class LinksController extends Controller
|
|
|
{
|
|
@@ -24,16 +27,40 @@ class LinksController extends Controller
|
|
|
'data' => $response->data
|
|
|
])->render();
|
|
|
|
|
|
- ray($html);
|
|
|
+ return response()->json([
|
|
|
+ 'status' => $response->status,
|
|
|
+ 'result' => $response->result,
|
|
|
+ 'html' => $html
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getShowsLinks(GetShowsLinks $request) {
|
|
|
+ ray()->clearAll();
|
|
|
+ ray($request->all());
|
|
|
+
|
|
|
+ $orion = new OrionService();
|
|
|
+ $orion->tvdbid = (string) $request->tmbd_id;
|
|
|
+ $orion->tmdbid = (string) $request->tmdb_id;
|
|
|
+ $orion->imdbid = (string) $request->imdb_id;
|
|
|
+ $orion->type = (string) $request->searchType;
|
|
|
+ $orion->queryString = (string) $request->queryString;
|
|
|
+ $orion->seasonNumber = (string) $request->season_number;
|
|
|
+ $orion->episodeNumber = (string) $request->episode_number;
|
|
|
+
|
|
|
+ $response = $orion->getLinks();
|
|
|
+
|
|
|
+ $html = view('components.orion-link-data', [
|
|
|
+ 'data' => $response->data
|
|
|
+ ])->render();
|
|
|
|
|
|
return response()->json([
|
|
|
'status' => $response->status,
|
|
|
+ 'result' => $response->result,
|
|
|
'html' => $html
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
public function getStreamLink(GetStreamUrl $request) {
|
|
|
- ray()->clearAll();
|
|
|
$orion = new OrionService();
|
|
|
$orion->orionId = $request->orionId;
|
|
|
$orion->streamId = $request->streamId;
|
|
@@ -42,7 +69,130 @@ class LinksController extends Controller
|
|
|
|
|
|
return response()->json([
|
|
|
'status' => "success",
|
|
|
+ 'result' => $response->result,
|
|
|
'data' => $response
|
|
|
]);
|
|
|
}
|
|
|
+
|
|
|
+ public function requestLink(RequestLink $request) {
|
|
|
+ $exists = $this->checkExists($request);
|
|
|
+
|
|
|
+ if ($exists === true) {
|
|
|
+ return response()->json([
|
|
|
+ 'status' => 'failed',
|
|
|
+ 'message' => 'A request for this link already exists.'
|
|
|
+ ], 200);
|
|
|
+ }
|
|
|
+
|
|
|
+ ray($request->type);
|
|
|
+
|
|
|
+ if ($request->type === "movie") {
|
|
|
+ $response = $this->addMovieToDb( $request);
|
|
|
+ return response()->json($response, 200);
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($request->type === "show") {
|
|
|
+ $response = $this->addShowToDb( $request);
|
|
|
+ return response()->json($response, 200);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private function checkMovieExists(RequestLink $request) {
|
|
|
+ $exists = false;
|
|
|
+
|
|
|
+ $importExists = DB::table('vod_import')->where('imdb_id', '=', $request->imdbid)->first();
|
|
|
+ $masterExists = DB::table('vod_master')->where('imdb_id', '=', $request->imdbid)->first();
|
|
|
+
|
|
|
+ // Check if exists in vod_import first
|
|
|
+ if (!is_null($importExists) || !is_null($masterExists)) {
|
|
|
+ $exists = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ return $exists;
|
|
|
+ }
|
|
|
+
|
|
|
+ private function checkShowExists(RequestLink $request)
|
|
|
+ {
|
|
|
+ $exists = false;
|
|
|
+
|
|
|
+ $importExists = DB::table('episodes_import')->where('imdb', '=', $request->imdbid)->first();
|
|
|
+ $masterExists = DB::table('episodes_master')->where('imdb', '=', $request->imdbid)->first();
|
|
|
+
|
|
|
+ // Check if exists in vod_import first
|
|
|
+ if (!is_null($importExists) || !is_null($masterExists)) {
|
|
|
+ $exists = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ return $exists;
|
|
|
+ }
|
|
|
+
|
|
|
+ private function checkExists(RequestLink $request)
|
|
|
+ {
|
|
|
+ $exists = false;
|
|
|
+
|
|
|
+ if ($request->type === "movie") {
|
|
|
+ $exists = $this->checkMovieExists($request);
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($request->type === "show") {
|
|
|
+ $exists = $this->checkShowExists($request);
|
|
|
+ }
|
|
|
+
|
|
|
+ return $exists;
|
|
|
+ }
|
|
|
+
|
|
|
+ private function addMovieToDb(RequestLink $request) {
|
|
|
+ try {
|
|
|
+ DB::beginTransaction();
|
|
|
+ DB::table('vod_import')->insert([
|
|
|
+ 'imdb_id' => $request->imdbid,
|
|
|
+ 'tmdb_id' => $request->tmdbid,
|
|
|
+ 'media_url' => $request->magnet
|
|
|
+ ]);
|
|
|
+ DB::commit();
|
|
|
+
|
|
|
+ return [
|
|
|
+ 'status' => "success",
|
|
|
+ 'message' => 'Request for this title has been accepted.'
|
|
|
+ ];
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ DB::rollBack();
|
|
|
+ return [
|
|
|
+ 'status' => 'failed',
|
|
|
+ 'reason' => $e->getMessage(),
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private function addShowToDb(RequestLink $request) {
|
|
|
+ try {
|
|
|
+ ray($request->all());
|
|
|
+ DB::beginTransaction();
|
|
|
+ $x = DB::table('episodes_import')->insert([
|
|
|
+ 'imdb' => $request->imdbid,
|
|
|
+ 'tmdb' => $request->tmdbid,
|
|
|
+ 'tvdb' => $request->tvbdid,
|
|
|
+ 'episode' => $request->episode_number,
|
|
|
+ 'season' => $request->season_number,
|
|
|
+ 'media_url' => $request->magnet
|
|
|
+ ]);
|
|
|
+
|
|
|
+ ray($x);
|
|
|
+
|
|
|
+ DB::commit();
|
|
|
+ ray('commited');
|
|
|
+ return [
|
|
|
+ 'status' => "success",
|
|
|
+ 'message' => 'Request for this title has been accepted.'
|
|
|
+ ];
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ ray($e);
|
|
|
+ DB::rollBack();
|
|
|
+ return [
|
|
|
+ 'status' => 'failed',
|
|
|
+ 'reason' => $e->getMessage(),
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|