<?php
namespace App\Controller;
use App\Entity\AceTv\AceTvBagsMinutes;
use App\Entity\AceTv\AceTvCategory;
use App\Entity\AceTv\AceTvCourtsCameras;
use App\Entity\AceTv\AceTvCredit;
use App\Entity\AceTv\AceTvEnclosures;
use App\Entity\AceTv\AceTvRecordings;
use App\Entity\App\AppUser;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
/**
* @Route("/")
*/
class IndexController extends AbstractController
{
private $url = "https://fast-acetv.cloudbase.cl:5443/LiveApp/";
public function __construct()
{
}
/**
* @Route("/", name="index")
*/
public function index(): Response
{
/*
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "{$this->url}rest/v2/broadcasts/list/0/10",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
));
$response = curl_exec($curl);
curl_close($curl);
$response = json_decode($response,true);
$listStreaming = [];
foreach ($response AS $i) {
if($i['status'] == 'broadcasting'){
$listStreaming[] = [
'idStreaming' => $i['streamId'],
'name' => $i['name']
];
}
}*/
/*
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "{$this->url}rest/v2/vods/list/0/10",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
));
$response2 = curl_exec($curl);
curl_close($curl);
$response2 = json_decode($response2,true);
$listVods = [];
foreach ($response2 AS $i) {
dump($i);
$listVods[] = [
'idVod' => $i['vodId'],
'name' => $i['streamName'],
'vodName' => $i['vodName'],
'duration' => $i['duration'],
];
}
*/
$em = $this->getDoctrine()->getManager();
$aceTvCategory = $em->getRepository(AceTvCategory::class)->findAll();
$aceTvCourtsCameras = $em->getRepository(AceTvCourtsCameras::class)->findBy(['flagStatus' => true]);
$cameras = [];
foreach ($aceTvCourtsCameras as $i) {
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://fast-acetv.cloudbase.cl:5443/LiveApp/rest/v2/broadcasts/{$i->getStreamId()}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
));
$response = curl_exec($curl);
curl_close($curl);
$resp = json_decode($response, true);
dump($resp);
if(isset($resp['status'])){
if($resp['status'] == 'broadcasting') {
if(@getimagesize("https://fast-acetv.cloudbase.cl:5443/LiveApp/previews/{$i->getStreamId()}.png")){
$image = true;
} else {
$image = false;
}
$cameras[] = [
'id' => $i->getId(),
'idStreaming' => $i->getStreamId(),
'name' => $i->getName(),
'image' => $image
];
}
}
}
$aceTvRecordings = $em->getRepository(AceTvRecordings::class)->findBy(['flagPublic' => true, 'flagFinish' => true],['id'=>'DESC']);
$recordings = [];
foreach ($aceTvRecordings as $i) {
$diff = $i->getDateStart()->diff($i->getDateEnd());
$duration = '';
if ($diff->h > 0) {
$duration .= "{$diff->h} hr: ";
}
if ($diff->i > 0) {
$duration .= "{$diff->i} mins";
}
$recordings[] = [
'id' => $i->getId(),
'idVod' => $i->getRecordingsId(),
'name' => $i->getName(),
'image' => $i->getImage(),
'realName' => str_replace('.mp4','',$i->getRealName()),
'duration' => $duration
];
}
return $this->render('BaseFrontEnd/index.html.twig', [
'listStreaming' => $cameras,
'listVods' => $recordings,
###################################
'aceTvCategory' => $aceTvCategory,
'menu' => 'index',
]);
}
/**
* @Route("/clubs/{id}", name="index_clubs")
*/
public function clubs(AceTvEnclosures $aceTvEnclosures): Response
{
$em = $this->getDoctrine()->getManager();
$aceTvCategory = $em->getRepository(AceTvCategory::class)->findByAceTvEnclosures($aceTvEnclosures->getId());
$aceTvCourtsCameras = $em->getRepository(AceTvCourtsCameras::class)->findBy(['flagStatus' => true, 'aceTvEnclosures' => $aceTvEnclosures]);
$cameras = [];
foreach ($aceTvCourtsCameras as $i) {
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://fast-acetv.cloudbase.cl:5443/LiveApp/rest/v2/broadcasts/{$i->getStreamId()}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
));
$response = curl_exec($curl);
curl_close($curl);
$resp = json_decode($response, true);
if(isset($resp['status'])) {
if ($resp['status'] == 'broadcasting') {
if (@getimagesize("https://fast-acetv.cloudbase.cl:5443/LiveApp/previews/{$i->getStreamId()}.png")) {
$image = true;
} else {
$image = false;
}
$cameras[] = [
'id' => $i->getId(),
'idStreaming' => $i->getStreamId(),
'name' => $i->getName(),
'image' => $image
];
}
}
}
$aceTvRecordings = $em->getRepository(AceTvRecordings::class)->findByAceTvEnclosures($aceTvEnclosures->getId());
$recordings = [];
foreach ($aceTvRecordings as $i) {
$diff = $i->getDateStart()->diff($i->getDateEnd());
$duration = '';
if ($diff->h > 0) {
$duration .= "{$diff->h} hr: ";
}
if ($diff->i > 0) {
$duration .= "{$diff->i} mins";
}
$recordings[] = [
'id' => $i->getId(),
'idVod' => $i->getRecordingsId(),
'name' => $i->getName(),
'image' => $i->getImage(),
'realName' => str_replace('.mp4','',$i->getRealName()),
'duration' => $duration
];
}
return $this->render('BaseFrontEnd/clubs.html.twig', [
'listStreaming' => $cameras,
'listVods' => $recordings,
'aceTvEnclosures' => $aceTvEnclosures,
###################################
'aceTvCategory' => $aceTvCategory,
'menu' => 'clubs',
]);
}
/**
* @Route("/category/{id}/{idClubs}", defaults={"idClubs": null}, name="index_category")
*/
public function category(AceTvCategory $aceTvCategory, $idClubs): Response
{
$em = $this->getDoctrine()->getManager();
$aceTvCourtsCameras = $em->getRepository(AceTvCourtsCameras::class)->findByAceTvCategory($aceTvCategory->getId(),$idClubs);
$cameras = [];
foreach ($aceTvCourtsCameras as $i) {
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://fast-acetv.cloudbase.cl:5443/LiveApp/rest/v2/broadcasts/{$i->getStreamId()}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
));
$response = curl_exec($curl);
curl_close($curl);
$resp = json_decode($response, true);
if(isset($resp['status'])) {
if ($resp['status'] == 'broadcasting') {
if (@getimagesize("https://fast-acetv.cloudbase.cl:5443/LiveApp/previews/{$i->getStreamId()}.png")) {
$image = true;
} else {
$image = false;
}
$cameras[] = [
'id' => $i->getId(),
'idStreaming' => $i->getStreamId(),
'name' => $i->getName(),
'image' => $image
];
}
}
}
$aceTvRecordings = $em->getRepository(AceTvRecordings::class)->findByAceTvCategory($aceTvCategory->getId(),$idClubs);
$recordings = [];
foreach ($aceTvRecordings as $i) {
$diff = $i->getDateStart()->diff($i->getDateEnd());
$duration = '';
if ($diff->h > 0) {
$duration .= "{$diff->h} hr: ";
}
if ($diff->i > 0) {
$duration .= "{$diff->i} mins";
}
$recordings[] = [
'id' => $i->getId(),
'idVod' => $i->getRecordingsId(),
'name' => $i->getName(),
'image' => $i->getImage(),
'realName' => str_replace('.mp4','',$i->getRealName()),
'duration' => $duration
];
}
return $this->render('BaseFrontEnd/category.html.twig', [
'listStreaming' => $cameras,
'listVods' => $recordings,
###################################
'aceTvCategory' => $aceTvCategory,
'menu' => 'clubs',
]);
}
/**
* @Route("/myVideo", name="index_myVideo")
*/
public function myVideo(): Response
{
$em = $this->getDoctrine()->getManager();
$aceTvRecordings = $em->getRepository(AceTvRecordings::class)->findBy(['appUser' => $this->getUser(), 'flagFinish' => true],['id'=>'DESC']);
$recordings = [];
foreach ($aceTvRecordings as $i) {
if($i->getDateEnd()) {
$diff = $i->getDateStart()->diff($i->getDateEnd());
$duration = '';
if ($diff->h > 0) {
$duration .= "{$diff->h} hr: ";
}
if ($diff->i > 0) {
$duration .= "{$diff->i} mins";
}
$recordings[] = [
'id' => $i->getId(),
'idVod' => $i->getRecordingsId(),
'name' => $i->getName(),
'url' => $i->getUrl(),
'image' => $i->getImage(),
'realName' => str_replace('.mp4', '', $i->getRealName()),
'duration' => $duration
];
}
}
return $this->render('BaseFrontEnd/myVideo.html.twig', [
###################################
'listVods' => $recordings,
'menu' => 'myVideo',
]);
}
/**
* @Route("/prices", name="index_bagsMinutes")
*/
public function bagsMinutes(): Response
{
$em = $this->getDoctrine()->getManager();
$aceTvBagsMinutes = $em->getRepository(AceTvBagsMinutes::class)->findBy(['flagStatus' => true],['priceMinute'=>'ASC']);
return $this->render('BaseFrontEnd/bagsminutes.html.twig', [
###################################
'aceTvBagsMinutes' => $aceTvBagsMinutes
]);
}
/**
* @Route("/balance", name="index_balance")
*/
public function balance(): Response
{
$em = $this->getDoctrine()->getManager();
$aceTvCredits = $em->getRepository(AceTvCredit::class)->findBy(['appUser' => $this->getUser()],['id'=>'DESC']);
$balance = 0;
foreach ($aceTvCredits AS $i) {
if($i->getCreditAdd() > 0){
$balance += $i->getCreditAdd();
}
if($i->getCreditSubstract() > 0){
$balance -= $i->getCreditSubstract();
}
}
#exit();
return $this->render('BaseFrontEnd/balance.html.twig', [
###################################
'balance' => $balance,
'aceTvCredits' => $aceTvCredits,
]);
}
/**
* @Route("/live/{idStreaming}", name="index_live")
* @Security("is_granted('ROLE_LOGIN_TRUE')")
*/
public function video($idStreaming): Response
{
return $this->redirectToRoute('index_online',['idStreaming'=>$idStreaming]);
}
/**
* @Route("/online/{idStreaming}", name="index_online")
*/
public function videoOnline($idStreaming): Response
{
$em = $this->getDoctrine()->getManager();
$aceTvCourtsCameras = $em->getRepository(AceTvCourtsCameras::class)->findOneBy(['streamId' => $idStreaming, 'flagStatus' => true]);
$aceTvRecordings = $em->getRepository(AceTvRecordings::class)->findOneBy([
'appUser' => $this->getUser(),
'flagFinish' => false,
'aceTvCourtsCameras' => $aceTvCourtsCameras
]);
$isMyVideo = false;
if($aceTvRecordings){
$isMyVideo = true;
}
$date = null;
$date2 = null;
$minute = null;
$flagFirstRecording = false;
if($this->getUser()){
if($this->getUser()->getInitRecording()){
$date = $this->getUser()->getInitRecording()->format('Y-m-d H:i');
$date2 = new \DateTime();
$date2 = $date2->format('Y-m-d H:i');
$minute = $this->getUser()->getMinute();
}
$aceTvRecordings2 = $em->getRepository(AceTvRecordings::class)->findBy(['appUser' => $this->getUser()]);
$flagFirstRecording = count($aceTvRecordings2) == 0;
}
return $this->render('BaseFrontEnd/live.html.twig', [
'idStreaming' => $idStreaming,
'aceTvCourtsCameras' => $aceTvCourtsCameras,
'isMyVideo' => $isMyVideo,
'date' => $date,
'date2' => $date2,
'minute' => $minute,
'flagFirstRecording' => $flagFirstRecording,
]);
}
/**
* @Route("/vod/{vodId}", name="index_vod")
*/
public function vod($vodId): Response
{
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "{$this->url}rest/v2/vods/{$vodId}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
));
$response2 = curl_exec($curl);
curl_close($curl);
$response2 = json_decode($response2, true);
return $this->render('BaseFrontEnd/vod.html.twig', [
'vod' => $response2,
'url' => $this->url,
]);
}
/**
* @Route("/termsAndConditions", name="index_termsAndConditions")
*/
public function termsAndConditions(): Response
{
return $this->render('BaseFrontEnd/termsAndConditions.html.twig', [
]);
}
/**
* @Route("/privacyPolicy", name="index_privacyPolicy")
*/
public function privacyPolicy(): Response
{
return $this->render('BaseFrontEnd/privacyPolicy.html.twig', [
]);
}
/**
* @Route("/startEndVideo/{idStreaming}", name="index_startEndVideo")
*/
public function startVideo(Request $request, $idStreaming): Response
{
$em = $this->getDoctrine()->getManager();
$aceTvCourtsCameras = $em->getRepository(AceTvCourtsCameras::class)->findOneBy(['streamId' => $idStreaming, 'flagStatus' => true]);
$curl = curl_init();
if (!$aceTvCourtsCameras->isFlagRecording()) {
curl_setopt_array($curl, array(
CURLOPT_URL => "https://fast-acetv.cloudbase.cl:5443/LiveApp/rest/v2/broadcasts/{$idStreaming}/recording/true?recordType=mp4",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'PUT',
));
$aceTvCourtsCameras->setFlagRecording(true);
} else {
curl_setopt_array($curl, array(
CURLOPT_URL => "https://fast-acetv.cloudbase.cl:5443/LiveApp/rest/v2/broadcasts/{$idStreaming}/recording/false?recordType=mp4",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'PUT',
));
$aceTvCourtsCameras->setFlagRecording(false);
}
$response = curl_exec($curl);
curl_close($curl);
$response = json_decode($response, true);
if ($response['success']) {
$em->persist($aceTvCourtsCameras);
$em->flush();
$aceTvRecordings = $em->getRepository(AceTvRecordings::class)->findOneBy(['recordingsId' => $response['dataId']]);
if (!$aceTvRecordings) {
$totalTimeMinute = $request->get('totalTime');
$appUser = $em->getRepository(AppUser::class)->find($this->getUser()->getId());
$appUser
->setInitRecording(new \DateTime())
->setMinute($totalTimeMinute)
->setIdStreaming($idStreaming)
;
$em->persist($appUser);
$em->flush();
$flagPublic = (bool)$request->get('flagPublic');
$aceTvRecordings = new AceTvRecordings();
$aceTvRecordings
->setAppUser($this->getUser())
->setDateStart(new \DateTime())
->setMinute($totalTimeMinute)
->setRecordingsId($response['dataId'])
->setFlagFinish(false)
->setAceTvCourtsCameras($aceTvCourtsCameras)
->setName($aceTvCourtsCameras->getAceTvEnclosures()->getName() . ' ' . $aceTvCourtsCameras->getName(). ' '.date('d/m/Y H:i'))
->setFlagPublic($flagPublic)
->setUrl('?')
->setAceTvCategory($aceTvCourtsCameras->getAceTvCategory())
;
} else {
$appUser = $em->getRepository(AppUser::class)->find($this->getUser()->getId());
$appUser
->setInitRecording(null)
->setMinute(null)
->setIdStreaming(null)
;
$em->persist($appUser);
$em->flush();
$nameImage = uniqid().'.png';
$url = "https://fast-acetv.cloudbase.cl:5443/LiveApp/previews/{$aceTvRecordings->getAceTvCourtsCameras()->getStreamId()}.png";
file_put_contents($this->getParameter('user_directory').'/'.$nameImage, file_get_contents($url));
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://fast-acetv.cloudbase.cl:5443/LiveApp/rest/v2/vods/{$aceTvRecordings->getRecordingsId()}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
));
$response = curl_exec($curl);
curl_close($curl);
$response = json_decode($response, true);
$fecha = new \DateTime();
$agregarDias = 7;
$fecha->add(new \DateInterval("P{$agregarDias}D"));
$aceTvRecordings
->setDateEnd(new \DateTime())
->setDateDelete($fecha)
->setFlagFinish(true)
->setRealName($response['vodName'])
->setUrl($this->url.$response['filePath'])
->setImage($nameImage)
;
}
$em->persist($aceTvRecordings);
$em->flush();
if ($aceTvRecordings->getDateEnd()) {
$diff = $aceTvRecordings->getDateStart()->diff($aceTvRecordings->getDateEnd());
$duration = 0;
if ($diff->h > 0) {
$duration += $diff->h * 60;
}
if ($diff->i > 0) {
$duration += $diff->i;
}
$aceTvCredit = new AceTvCredit();
$aceTvCredit
->setDateCreation(new \DateTime())
->setCreditAdd(0)
->setAppUser($this->getUser())
->setCreditSubstract($duration);
$em->persist($aceTvCredit);
$em->flush();
}
return new JsonResponse(['status' => 'ok']);
}
return new JsonResponse(['status' => 'error']);
}
}