<!doctype html>
<html lang="pt-BR">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Star+</title>
    <meta name="apple-mobile-web-app-title" content="Star+"/>
        <meta name="theme-color" content="#ffffff"/>
        <meta name="msapplication-TileColor" content="#ffffff"/>
        <meta name="msapplication-config" content="https://static-assets.bamgrid.com/product/starplus/favicons/browserconfig.37a0f5e68223ed98fd4110fd5e727ea7.xml"/>
        <link rel="manifest" href="https://static-assets.bamgrid.com/product/starplus/favicons/manifest.0ed6a576afcdb93cb0caf06713bf3046.json"/>
        <link rel="shortcut icon" href="https://static-assets.bamgrid.com/product/starplus/favicons/favicon.e1b583d6771b7121f3b57326dfe078b6.ico"/>
        <link rel="mask-icon" href="https://static-assets.bamgrid.com/product/starplus/favicons/safari-pinned-tab.aa33e9e7084f7a736c034f1e634bf392.svg" color="#1d1fff"/>
        <link rel="apple-touch-icon" sizes="180x180" href="https://static-assets.bamgrid.com/product/starplus/favicons/apple-touch-icon.6e5c8469505b0ee8c211f11d62c063ba.png"/>
        <link rel="icon" type="image/png" sizes="32x32" href="https://static-assets.bamgrid.com/product/starplus/favicons/favicon-32x32.da4ae1a0645d9c381645155d7dc1b4d3.png"/>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-9ndCyUaIbzAi2FUVXJi0CjmCapSmO7SnpJef0486qhLnuZ2cdeRhO02iuK6FUUVM" crossorigin="anonymous">
  </head>
  <body style="background-color: black; color: white;">
    <h1 class="text-center"><img src="https://static-assets.bamgrid.com/product/starplus/images/logo.770970996243b55d166fbeb8b1a52b36.svg" width="300" height="100"></h1>
    <div class="container text-center">
    <div class="row row-cols-1 row-cols-sm-2 row-cols-md-3 g-3">
<?php
error_reporting(0);
date_default_timezone_set('America/Sao_Paulo');
$server = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
$path = str_replace ("lista.php" , 'master_co.php' , $server);
$categories_array = array
(
//eventos de hoje
//'https://star.content.edge.bamgrid.com/svc/content/CuratedSet/version/5.1/region/BR/audience/k-false,l-true/maturity/1850/language/pt-BR/setId/d074a95d-96d9-486b-9903-127608f92c85/pageSize/50/page/1',
//Chile
//'https://star.content.edge.bamgrid.com/svc/content/CuratedSet/version/5.1/region/CL/audience/k-false,l-true/maturity/1850/language/pt-BR/setId/415311fd-599b-460e-8006-80a3e626c119/pageSize/50/page/1',

//Mexico
//'https://star.content.edge.bamgrid.com/svc/content/CuratedSet/version/5.1/region/MX/audience/k-false,l-true/maturity/1850/language/pt-BR/setId/415311fd-599b-460e-8006-80a3e626c119/pageSize/50/page/1',

//Colombia
//'https://star.content.edge.bamgrid.com/svc/content/CuratedSet/version/5.1/region/CO/audience/k-false,l-true/maturity/1850/language/pt-BR/setId/415311fd-599b-460e-8006-80a3e626c119/pageSize/50/page/1',

//Argentina
//'https://star.content.edge.bamgrid.com/svc/content/CuratedSet/version/5.1/region/AR/audience/k-false,l-true/maturity/1850/language/es-AR/setId/415311fd-599b-460e-8006-80a3e626c119/pageSize/50/page/1',

//Peru
//'https://star.content.edge.bamgrid.com/svc/content/CuratedSet/version/5.1/region/PE/audience/k-false,l-true/maturity/1850/language/pt-BR/setId/415311fd-599b-460e-8006-80a3e626c119/pageSize/50/page/1',

//Uruguay
//'https://star.content.edge.bamgrid.com/svc/content/CuratedSet/version/5.1/region/UY/audience/k-false,l-true/maturity/1850/language/pt-BR/setId/415311fd-599b-460e-8006-80a3e626c119/pageSize/50/page/1',

//Ecuador
//'https://star.content.edge.bamgrid.com/svc/content/CuratedSet/version/5.1/region/EC/audience/k-false,l-true/maturity/1850/language/pt-BR/setId/415311fd-599b-460e-8006-80a3e626c119/pageSize/50/page/1',

//Venezuela
//'https://star.content.edge.bamgrid.com/svc/content/CuratedSet/version/5.1/region/VE/audience/k-false,l-true/maturity/1850/language/pt-BR/setId/415311fd-599b-460e-8006-80a3e626c119/pageSize/50/page/1',

//Honduras
//'https://star.content.edge.bamgrid.com/svc/content/CuratedSet/version/5.1/region/HN/audience/k-false,l-true/maturity/1850/language/pt-BR/setId/415311fd-599b-460e-8006-80a3e626c119/pageSize/50/page/1',

//Panama
//'https://star.content.edge.bamgrid.com/svc/content/CuratedSet/version/5.1/region/PA/audience/k-false,l-true/maturity/1850/language/pt-BR/setId/415311fd-599b-460e-8006-80a3e626c119/pageSize/50/page/1',

//Costa Rica
//'https://star.content.edge.bamgrid.com/svc/content/CuratedSet/version/5.1/region/CR/audience/k-false,l-true/maturity/1850/language/pt-BR/setId/415311fd-599b-460e-8006-80a3e626c119/pageSize/50/page/1',

//Paraguay
//'https://star.content.edge.bamgrid.com/svc/content/CuratedSet/version/5.1/region/PY/audience/k-false,l-true/maturity/1850/language/pt-BR/setId/415311fd-599b-460e-8006-80a3e626c119/pageSize/50/page/1',

//El Salvador
//'https://star.content.edge.bamgrid.com/svc/content/CuratedSet/version/5.1/region/SV/audience/k-false,l-true/maturity/1850/language/pt-BR/setId/415311fd-599b-460e-8006-80a3e626c119/pageSize/50/page/1',

//Dominican Republic
//'https://star.content.edge.bamgrid.com/svc/content/CuratedSet/version/5.1/region/DO/audience/k-false,l-true/maturity/1850/language/pt-BR/setId/415311fd-599b-460e-8006-80a3e626c119/pageSize/50/page/1',

//Bolivia
//'https://star.content.edge.bamgrid.com/svc/content/CuratedSet/version/5.1/region/BO/audience/k-false,l-true/maturity/1850/language/pt-BR/setId/415311fd-599b-460e-8006-80a3e626c119/pageSize/50/page/1',

//Guatemala
//'https://star.content.edge.bamgrid.com/svc/content/CuratedSet/version/5.1/region/GT/audience/k-false,l-true/maturity/1850/language/pt-BR/setId/415311fd-599b-460e-8006-80a3e626c119/pageSize/50/page/1',

//Nicaragua
//'https://star.content.edge.bamgrid.com/svc/content/CuratedSet/version/5.1/region/NI/audience/k-false,l-true/maturity/1850/language/pt-BR/setId/415311fd-599b-460e-8006-80a3e626c119/pageSize/50/page/1',
//eventos de amanhã
//'https://star.content.edge.bamgrid.com/svc/content/CuratedSet/version/5.1/region/BR/audience/k-false,l-true/maturity/1850/language/pt-BR/setId/204c3df2-6ba4-447d-b328-365a9d915144/pageSize/50/page/1',

//eventos geral
'https://star.content.edge.bamgrid.com/svc/content/CuratedSet/version/5.1/region/BR/audience/k-false,l-true/maturity/1850/language/pt-BR/setId/415311fd-599b-460e-8006-80a3e626c119/pageSize/50/page/1',
'https://star.content.edge.bamgrid.com/svc/content/CuratedSet/version/5.1/region/BR/audience/k-false,l-true/maturity/1850/language/pt-BR/setId/415311fd-599b-460e-8006-80a3e626c119/pageSize/50/page/2',

//eventos de amanhã
//'https://star.content.edge.bamgrid.com/svc/content/CuratedSet/version/5.1/region/BR/audience/k-false,l-true/maturity/1850/language/pt-BR/setId/204c3df2-6ba4-447d-b328-365a9d915144/pageSize/50/page/1',
//'https://star.content.edge.bamgrid.com/svc/content/CuratedSet/version/5.1/region/BR/audience/k-false,l-true/maturity/1850/language/pt-BR/setId/204c3df2-6ba4-447d-b328-365a9d915144/pageSize/50/page/2'
);
for ($cat = 0; $cat < count($categories_array); $cat++) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $categories_array[$cat]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$headers = [
'Host: star.content.edge.bamgrid.com',
'accept: application/json',
'user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36',
'referer: https://www.starplus.com/'];
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
    }
curl_close($ch);

$json = json_decode($result , true);
$events = $json['data']['CuratedSet']['items'];


for ($i = 0; $i < count($json['data']['CuratedSet']['items']); $i++) {
    $id = $events[$i]['family']['encodedFamilyId'];
    $eventId = $events[$i]["eventId"];
    $mediaId = $events[$i]["mediaMetadata"]["mediaId"];
    
    $state = $events[$i]["mediaMetadata"]["state"];
    $esporte = $events[$i]['sport']['text']['name']['full']['sport']['default']['content'];

    $games = $events[$i]['text']['title']['full']['program']['default']['content'];
    $league = strtoupper($json["data"]["CuratedSet"]["items"][$i]["event"]["league"]["text"]["name"]["full"]["league"]["default"]["content"]);
    $fecha = $events[$i]['startDate'];
    $grupo = $events[$i]['league']['texts'][1]['content'];
    $playbackUrls = str_replace('{scenario}', 'restricted-drm-ctr-sw', $events[$i]['mediaMetadata']['playbackUrls'][0]['href']);
    $liveBroadcast = $events[$i]['liveBroadcast'];
    
    if (!$liveBroadcast == 1) {
        $liveBroadcast = ' | Replay';
    } else { $liveBroadcast = ' | Live';}
    $networkName = ' | ' . $events[$i]['channel']['networkName'];
	
	$start = strtotime ($json["data"]["CuratedSet"]["items"][$i]["startDate"]);
	$start_12h = date ( "j M h:i a" , $start);
    $date = strtoupper(date("h:i A", strtotime($fecha)));
    $datetime = new DateTime($date);
    $datetime->setTimezone(new DateTimeZone('America/Sao_Paulo'));      
    $horaLocal = ($datetime->format('h:i A'));
	$horaJuego = new DateTime($fecha);
	$timestampJuego = $horaJuego->getTimestamp();
	$link=$path."?id={$id}&eventId={$eventId}&mediaId={$mediaId}" .'&time='.urlencode($timestampJuego). chr(10);
   

$league = $json["data"]["CuratedSet"]["items"][$i]["event"]["league"]["text"]["name"]["full"]["league"]["default"]["content"];
$logo = $json["data"]["CuratedSet"]["items"][$i]["image"]["tile"]["1.78"]["program"]["default"]["url"]."/badging?width=400&aspectRatio=1.78&format=jpeg&label=originals&.jpeg";

//formato data
if (substr($date, 6, 8) == "AM"){
	$dataevento = str_replace('AM','',$date);
}
if(substr($date, 6, 8) == "PM"){
	$pm = substr($date, 0, 2);
	$pmsoma = $pm+12;
	$dataevento = $pmsoma.substr($date, 2, 3);
}
if($date == "12:00 AM"){
    $dataevento = "00:00";
}
if($date == "12:00 PM"){
    $dataevento = "12:00";
}
//formato data
?>

<div class="col">
            <div class="card shadow-sm" style="background-color: grey">
                <img src="<?php echo $logo; ?>" width="100%" height="225" alt="<?php echo $games;?>">
                <p><b><?php echo $games;?></b></p><?php echo $league;?>
                <div class="card-body">
                    <p class="card-text">
                        
                    </p>
                    <div class="d-flex justify-content-between align-items-center">
                        <div class="btn-group">
                            <div class="url"><a href="<?php echo $link;?>"><button type="button" class="btn btn-light">ASSISTIR</button></a></div>
                        </div>
                        <div class="btn-group">
                            <div class="url"><button type="button" class="btn btn-dark">
                                <?php if($esporte != ""){ echo $esporte;}else{echo '<img src="https://prod-ripcut-delivery.disney-plus.net/v1/variant/star/076E549AB89F389B20D1568147F72A8ACA0C70A0F13462365E493466934A993A/scale?" width="80px" height="23px">';}?>
                            </button></div>
                        </div>
                        <small class="text-muted">
                            <?php if($state == "ON"){?>
                                <button type="button" class="btn btn-danger">
                                    <?php echo "AO VIVO"; ?>
                                </button>
                            <?php }elseif($state == "OFF"){ ?>
                                
                                    <?php echo $dataevento;?>
                                </button>
                            <?php }else{ ?>
                                <button type="button" class="btn btn-dark">
                                    <?php echo $dataevento; ?>
                                </button>
                            <?php } ?>
                        </small>
                    </div>
                </div>
            </div>
</div>

<?php
}
}
?>
  </div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-geWF76RCwLtnZ8qwWowPQNguL3RmwHVBC9FhGdlKrxdiJJigb/j/68SIy3Te4Bkz" crossorigin="anonymous"></script>
</body>
</html>
