join('streamings', 'djs.port', '=', 'streamings.port')
->where('streamings.server_id', 3)
->where(function ($query) {
$query->whereNull('djs.sha')
->orWhere('djs.sha', '');
})
->select(
'djs.*',
'streamings.autodj_port',
'streamings.timezone'
)
->get();
$i=0;
foreach($djs as $dj){
if($i == 50){exit();}
$days = [];
if ($dj->mon) $days[] = 1;
if ($dj->tue) $days[] = 2;
if ($dj->wed) $days[] = 3;
if ($dj->thu) $days[] = 4;
if ($dj->fri) $days[] = 5;
if ($dj->sat) $days[] = 6;
if ($dj->sun) $days[] = 7;
$ranges = [];
if ($dj->prohibed) {
$ranges[] = [
'start' => $dj->time_start,
'end' => $dj->time_end,
];
}
$response = Http::timeout(10)->asJson()->post('https://hts07.brascast.com/bras_api/data/sync_auth.php', [
'action' => 'upsert',
'dj_id' => $dj->id,
'port' => (string) $dj->port,
'autodj_port' => (string) ($dj->autodj_port ?? ''),
'timezone' => $dj->timezone ?? 'America/Sao_Paulo',
'name' => filter_var($dj->name, FILTER_SANITIZE_STRING),
'password' => strip_tags($dj->password),
'enabled' => true,
'restricted' => (bool) $dj->prohibed,
'days' => $days,
'ranges' => $ranges,
]);
$secret = '679af55cd1b1d9137822a2354ae4a6de15505c4da54cda80124b7a6f0b61930a';
$hash = hash_hmac('sha256', $dj->password, $secret);
DB::table('djs')->where('id','=',$dj->id)->update(['sha' => $hash]);
echo $dj->port.' - '.$hash;
$i++;
}
exit();
*/
$streamings = DB::table('streamings')
->where('server_id', 3)
->select('port', 'autodj_port')
->get();
foreach($streamings as $stream){
$response = Http::timeout(10)->asForm()->post('https://hts07.brascast.com/bras_api/data/sync_aliase.php', [
'port' => $stream->port,
'port_dj' => $stream->autodj_port,
]);
echo $stream->port.' - '.$response.'
';
}
exit();
$inicio = microtime(true);
list($start,$end) = explode("-",$arg);
$ports = collect(
DB::connection('mysql_site_1')->table('sites')->pluck('stream_port')
)->merge(
DB::connection('mysql_site_2')->table('sites')->pluck('stream_port')
)->merge(
DB::connection('mysql_site_3')->table('sites')->pluck('stream_port')
)->unique();
DB::table('streamings')
->select('port', 'timezone', 'server_id')
->where('status', 1)
->orderBy('id') // importante usar uma coluna Ășnica
->chunk(100, function ($streams) use ($ports) {
foreach ($streams as $stream) {
if (!$ports->contains($stream->port)) {
$ch = curl_init();
/* sem limite, servidor mudo segura o processo ate o teto do PHP */
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt_array($ch, [
CURLOPT_URL => 'https://app.brascast.com/brasapi/stream/delete/' . $stream->port .'/YnJhc2Nhc3RzdHJlYW1pbmc=',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 30,
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if (curl_errno($ch)) {
echo "Erro {$stream->port}: " . curl_error($ch) . "
";
} else {
echo "{$stream->port} - HTTP {$httpCode} - {$response}
";
}
curl_close($ch);
echo $stream->port . '
';
}
}
});
}
}