json([ 'status' => 'error', 'data' => [ 'error_code' => 402, 'message' => 'Invalid parameters' ]]); } /* the address may carry the safe spelling: a raw slash in it would break the route */ $portDecr = EncryptBras(str_replace('|brasbar', '/', $port),'d'); $expData = explode('|',$portDecr); /* the owner comes from the guard: a token without the "id|" prefix is valid too */ $tokenOwner = (int) (request()->user()->id ?? 0); $siteServer = DB::table('site_server')->where('domain','=',$expData[0])->get(); if(!$siteServer->count()){ return response()->json([ 'status' => 'error', 'data' => [ 'error_code' => 403, 'message' => 'Access denieds' ]]); } $answer = $this->api->get('lookup', ['action' => 'port', 'port' => (int) $expData[1]], (int) $siteServer->first()->server_id); $siteData = ($answer['site'] ?? null) ? (object) $answer['site'] : null; if(!$siteData || $siteData->user_id != $tokenOwner){ return response()->json([ 'status' => 'error', 'data' => [ 'error_code' => 403, 'message' => 'Access denied' ]]); } $getStreamDetails = DB::table('streamings')->where('port','=',$expData[1])->get()->first(); /* CHECK LIMITS */ $userData = DB::table('users')->where('id','=',$tokenOwner)->get()->first(); if($userData->limit_used >= $userData->limit_total){ return response()->json([ 'status' => 'error', 'data' => [ 'error_code' => 403, 'message' => 'Access deniedy' ]]); } User::where('id','=',$tokenOwner)->increment('limit_used', 1); /* END CHECK LIMITS */ $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_URL, 'https://' . $siteData->stream_server . '.' . env('BASE_SERVER_URL', 'brascast.com') . '/bras_api/data/current.php?p=' . $getStreamDetails->port); $result = curl_exec($ch); $dataAutoDJInfo = json_decode($result, true); curl_close($ch); $chs = curl_init(); curl_setopt($chs, CURLOPT_URL, "https://".$siteData->stream_server.".brascast.com:".$getStreamDetails->port."/status-json.xsl"); curl_setopt($chs, CURLOPT_RETURNTRANSFER, 1); curl_setopt($chs, CURLOPT_CONNECTTIMEOUT, 2); curl_setopt($chs, CURLOPT_TIMEOUT, 2); curl_setopt($chs, CURLOPT_USERAGENT, 'BRASCASTX'); $resultado = json_decode(curl_exec($chs)); curl_close($chs); return response()->json([ 'status' => 'success', 'plan' => [ 'radio_name' => $siteData->name, 'listeners' => $getStreamDetails->plan_listeners, 'bitrate' => $getStreamDetails->plan_bitrate ], 'listeners' => [ 'current' => $resultado->icestats->source[0]->listeners, 'peak' => $resultado->icestats->source[0]->listener_peak ], 'onair_data' => [ 'current_music' => $dataAutoDJInfo['now'], 'next_music' => $dataAutoDJInfo['next'], 'stream_data' => [ 'codec' => $resultado->icestats->source[0]->server_type, 'bitrate' => $resultado->icestats->source[0]->bitrate ] ] ],200, ['Content-Type' => 'application/json;charset=UTF-8', 'Charset' => 'utf-8'], JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES); } public function checkDJ($port = null,$pass = null,$ip = null) { $getPortDJ = DB::table('streamings')->where('autodj_port','=',$port)->get(); $portVerify = ($getPortDJ->count() ? $getPortDJ[0]->port : $port); /*Verify Any active*/ $active = DB::table('djs')->where('port','=',$portVerify)->where('active','=','1')->get()->count(); if($active){ return response()->json(['status' => false, 'reason' => 'Unauthenticated']); } $verify = DB::table('djs')->where('password','=',$pass)->where('port','=',$portVerify)->where('prohibed','=','0')->get()->first(); if(!$verify){ return response()->json(['status' => false, 'reason' => 'Prohibed']); } /* Restrict */ if($verify->time_start){ $weekday = substr(strtolower(date('l')),0,3); $restrictVerify = DB::select(" SELECT COUNT(id) AS total FROM djs WHERE id = '".$verify->id."' AND time_end >= '".date('H:i').":00' OR '".date('H:i').":00' <= time_start "); if(!$restrictVerify[0]->total){ return response()->json(['status' => false, 'reason' => 'Restricted']); } return response()->json(['status' => true,'loc' => $verify->name]); } return response()->json(['status' => true,'loc' => $verify->name]); } public function cover($sid,$port) { if(!$port || !$sid){ return response()->json([ 'status' => 'error', 'data' => [ 'error_code' => 402, 'message' => 'Invalid parameters' ]]); } $siteServer = DB::table('site_server')->where('site_id','=',$sid)->get(); if(!$siteServer->count()){ return response()->json([ 'status' => 'error', 'data' => [ 'error_code' => 403, 'message' => 'Access denied' ]]); } $getStreamDetails = DB::table('streamings')->where('port','=',$port)->get()->first(); $getServerDetails = DB::table('servers')->where('id','=',$getStreamDetails->server_id)->get()->first(); $finalCover = null; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://".$getServerDetails->ip.":".$getStreamDetails->port."/status-json.xsl"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); curl_setopt($ch, CURLOPT_TIMEOUT, 5); curl_setopt($ch, CURLOPT_USERAGENT, 'BRASCASTX'); $resultado = json_decode(curl_exec($ch)); curl_close($ch); $cur = (isset($resultado->icestats->source[0]->title) ? $resultado->icestats->source[0]->title : null); $exp = explode('-',$cur); $defaultCont = array('Hora Certa'); if(strpos($cur, ' - Completo') || strpos($cur, ' - Parte ')) { $expCur = explode('-',$cur); $finalCover = config('radio.cover_url').'covers/default/'.md5($expCur[0]).'.jpg'; }else{ $defaultLive = array('PROGRAMAÇÃO AO VIVO','PROGRAMACAO AO VIVO','PROGRAMAÇÃO AOVIVO','PROGRAMACAO AOVIVO'); if(in_array($cur,$defaultLive)){ $finalCover = config('radio.cover_url').'covers/default/5b36dd0016ac6a4f4df796162752812a.jpg'; }else if(in_array($cur,$defaultCont)){ $finalCover = config('radio.cover_url').'covers/default/'.md5($cur).'.jpg'; }else{ $url = config('radio.cover_url').'covers/'.md5($getStreamDetails->port).'/'.md5($cur).'.jpg'; $headers = @get_headers($url); if(isset($headers[0]) && strpos($headers[0],'200')){ $finalCover = $url; }else{ $cur = str_replace('Ao Vivo','',$cur); /*$finalCover = getDeezerCover($cur); if (!$finalCover && isset($exp[1])) { $finalCover = getDeezerCover($exp[1]); } if (!$finalCover) { $finalCover = getItunesCoverWithFallback($cur, $exp); }*/ if (!$finalCover) { $finalCover = null; } } } } return response()->json([ 'status' => 'success', 'data' => [ 'cover' => $finalCover, 'song' => $cur ]]); } }