File size: 3.67Kb
<?php
$response = array(
'data' => null,
'error' => null,
);
$isResponse = false;
$isError = false;
$isSuccessResponse = false;
$providerName = null;
$url = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$isResponse = true;
require_once __DIR__ . '/YoutubeDownloader.php';
try {
if (!isset($_POST['url']) || !trim($_POST['url'])) {
header("Location: /ytdown/?");exit;
}
$url = trim($_POST['url']);
$yd = new YoutubeDownloader($url);
$fullInfo = $yd->getFullInfo();
$videoId = $fullInfo['video_id'];
$response['data'] = array(
'baseInfo' => $yd->getBaseInfo(),
'downloadInfo' => $yd->getDownloadsInfo(),
);
$isSuccessResponse = true;
} catch (Exception $e) {
$isError = true;
header('Bad request', true, 400);
$response['error'] = $e->getMessage();
}
}
include_once '../sys/inc/start.php';
include_once '../sys/inc/compress.php';
include_once '../sys/inc/sess.php';
include_once '../sys/inc/home.php';
include_once '../sys/inc/settings.php';
include_once '../sys/inc/db_connect.php';
include_once '../sys/inc/ipua.php';
include_once '../sys/inc/fnc.php';
// заголовок страницы
$set['title'] = 'Скачать видео Youtube';
include_once '../sys/inc/thead.php';
title();
aut();
err();
?>
<div class="main">Введите URL</div>
<div class="main">
<form action="" method="post" id="download-form">
<div class="form-group <?= $isError ? 'has-error' : '' ?>">
<input id="video-url" title="Video url" type="text" name="url" placeholder="ссылка" class="form-control" value="<?= htmlspecialchars($url) ?>"/>
<button class="btn btn-success">Искать</button>
</form></div></div>
<div class="alert alert-danger" role="alert" id="error-block" style="display: <?= $isError ? 'block' : 'none' ?>">
<?= $isError ? $response['error'] : '' ?>
</div>
<?php if ($isSuccessResponse): ?>
<?php
$baseInfo = $response['data']['baseInfo'];
$downloadInfo = $response['data']['downloadInfo'];
?>
<?php endif; ?>
<div class="col-md-6" id="video-name">
<?php if ($isSuccessResponse): ?><div class="nav2"><h4>
<?= text($baseInfo['name']) ?></h4></div>
<?php endif; ?>
</div>
<div class="col-md-6" style="display: <?= $isSuccessResponse ? 'block' : 'none' ?>">
<div id="video-preview">
<?php if ($isSuccessResponse): ?>
<div class="nav2"><div style="text-align: center;"><img src="<?= $baseInfo['previewUrl'] ?>" alt="Video preview" class="img-responsive img-thumbnail img-rounded"></div></div>
<?php endif; ?>
</div></div>
<?php if ($isSuccessResponse): ?>
<?php if (!$baseInfo['description']){
$_SESSION['message'] = 'Не верна ссылка !';
header("Location: /ytdown/?");exit;} ?>
<div class="nav2">
<?= output_text($baseInfo['description']) ?></div>
<?php endif; ?>
<?php if ($isSuccessResponse): ?><div class="nav2"><table id="download-list" class="table">
<?php foreach ($downloadInfo AS $downloadInfoItem): ?>
<tr>
<?php $downloadInfoItem['fileType'] = str_replace('video/', 'видео: ', $downloadInfoItem['fileType']); ?>
<?php $downloadInfoItem['fileType'] = str_replace('audio/', 'аудио: ', $downloadInfoItem['fileType']); ?>
<?php if ($downloadInfoItem['fileSizeHuman']==0){
$_SESSION['message'] = 'Не доступно для скачки !';
header("Location: /ytdown/?");exit;} ?>
<td class="nav2">Формат <?= $downloadInfoItem['fileType'] ?></td>
<td class="nav2">Размер: <?= $downloadInfoItem['fileSizeHuman'] ?></td>
<td class="nav2">
<?php $downloadUrl = 'download.php?id=' . $videoId . '&itag=' . $downloadInfoItem['youtubeItag'];?>
<a href="<?= $downloadUrl ?>" target="_blank">
<span class="glyphicon glyphicon-circle-arrow-down"></span>Скачать</a>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</table></div>
<?
include_once '../sys/inc/tfoot.php';
?>