mirror of
https://github.com/DanielnetoDotCom/YouPHPTube
synced 2025-10-06 03:50:04 +02:00
Improve download layout
This commit is contained in:
parent
56cdf7cd8f
commit
149ec78c8a
3 changed files with 59 additions and 15 deletions
|
@ -59,12 +59,14 @@ if (count($downloadOptions) == 1) {
|
||||||
<?php
|
<?php
|
||||||
$count = 0;
|
$count = 0;
|
||||||
$lastURL = '';
|
$lastURL = '';
|
||||||
|
$lastFormat = '';
|
||||||
foreach ($downloadOptions as $theLink) {
|
foreach ($downloadOptions as $theLink) {
|
||||||
if (!empty($theLink)) {
|
if (!empty($theLink)) {
|
||||||
$count++;
|
$count++;
|
||||||
$lastURL = $theLink['url'];
|
$lastURL = $theLink['url'];
|
||||||
|
$lastFormat = strtolower($theLink['name']);
|
||||||
?>
|
?>
|
||||||
<button type="button" onclick="_goToURLOrAlertError('<?php echo $theLink['url']; ?>');"
|
<button type="button" onclick="_goToURLOrAlertError('<?php echo $lastURL; ?>', '<?php echo $lastFormat; ?>');"
|
||||||
class="btn btn-default btn-light btn-lg btn-block" target="_blank">
|
class="btn btn-default btn-light btn-lg btn-block" target="_blank">
|
||||||
<i class="fas fa-download"></i> Download <?php echo $theLink['name']; ?>
|
<i class="fas fa-download"></i> Download <?php echo $theLink['name']; ?>
|
||||||
</button>
|
</button>
|
||||||
|
@ -74,12 +76,12 @@ if (count($downloadOptions) == 1) {
|
||||||
?>
|
?>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<script>
|
<script>
|
||||||
function _goToURLOrAlertError(url){
|
function _goToURLOrAlertError(url, format) {
|
||||||
avideoToastSuccess(<?php echo json_encode(__('Downloading').'... '.$video['title']); ?>);
|
avideoToastSuccess(<?php echo json_encode(__('Downloading') . '... ' . $video['title']); ?>);
|
||||||
goToURLOrAlertError(url, {});
|
downloadURLOrAlertError(url, {}, '<?php echo $video['clean_title']; ?>.' + format);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<?php
|
<?php
|
||||||
include $global['systemRootPath'] . 'view/include/footer.php';
|
include $global['systemRootPath'] . 'view/include/footer.php';
|
||||||
|
|
||||||
|
@ -87,7 +89,7 @@ if (count($downloadOptions) == 1) {
|
||||||
?>
|
?>
|
||||||
<script>
|
<script>
|
||||||
$(function () {
|
$(function () {
|
||||||
_goToURLOrAlertError('<?php echo $lastURL; ?>');
|
_goToURLOrAlertError('<?php echo $lastURL; ?>', '<?php echo $lastFormat; ?>');
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
<?php
|
<?php
|
||||||
|
|
|
@ -2091,23 +2091,65 @@ function animateChilds(selector, type, delay) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function goToURLOrAlertError(jsonURL, data){
|
function goToURLOrAlertError(jsonURL, data) {
|
||||||
modal.showPleaseWait();
|
modal.showPleaseWait();
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: jsonURL,
|
url: jsonURL,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
data: data,
|
data: data,
|
||||||
success: function (response) {
|
success: function (response) {
|
||||||
if(response.error){
|
if (response.error) {
|
||||||
avideoAlertError(response.msg);
|
avideoAlertError(response.msg);
|
||||||
modal.hidePleaseWait();
|
modal.hidePleaseWait();
|
||||||
}else if(response.url){
|
} else if (response.url) {
|
||||||
if(response.msg){
|
if (response.msg) {
|
||||||
avideoAlertInfo(response.msg);
|
avideoAlertInfo(response.msg);
|
||||||
}
|
}
|
||||||
document.location = response.url;
|
document.location = response.url;
|
||||||
setTimeout(function(){ modal.hidePleaseWait();},3000)
|
setTimeout(function () {
|
||||||
}else{
|
modal.hidePleaseWait();
|
||||||
|
}, 3000)
|
||||||
|
} else {
|
||||||
|
avideoResponse(response);
|
||||||
|
modal.hidePleaseWait();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function downloadURLOrAlertError(jsonURL, data, filename) {
|
||||||
|
modal.showPleaseWait();
|
||||||
|
avideoToastInfo('Converting');
|
||||||
|
$.ajax({
|
||||||
|
url: jsonURL,
|
||||||
|
method: 'POST',
|
||||||
|
data: data,
|
||||||
|
success: function (response) {
|
||||||
|
if (response.error) {
|
||||||
|
avideoAlertError(response.msg);
|
||||||
|
modal.hidePleaseWait();
|
||||||
|
} else if (response.url) {
|
||||||
|
if (response.msg) {
|
||||||
|
avideoAlertInfo(response.msg);
|
||||||
|
}
|
||||||
|
avideoToastInfo('Download start');
|
||||||
|
fetch(response.url)
|
||||||
|
.then(resp => resp.blob())
|
||||||
|
.then(blob => {
|
||||||
|
const url = window.URL.createObjectURL(blob);
|
||||||
|
const a = document.createElement('a');
|
||||||
|
a.style.display = 'none';
|
||||||
|
a.href = url;
|
||||||
|
// the filename you want
|
||||||
|
a.download = filename;
|
||||||
|
document.body.appendChild(a);
|
||||||
|
a.click();
|
||||||
|
window.URL.revokeObjectURL(url);
|
||||||
|
modal.hidePleaseWait();
|
||||||
|
avideoToastSuccess('Download complete');
|
||||||
|
})
|
||||||
|
.catch(() => avideoAlertError('An error on download file'));
|
||||||
|
} else {
|
||||||
avideoResponse(response);
|
avideoResponse(response);
|
||||||
modal.hidePleaseWait();
|
modal.hidePleaseWait();
|
||||||
}
|
}
|
||||||
|
|
|
@ -260,7 +260,7 @@ if (User::hasBlockedUser($video['users_id'])) {
|
||||||
foreach ($filesToDownload as $theLink) {
|
foreach ($filesToDownload as $theLink) {
|
||||||
if (preg_match('/\.json/i', $theLink['url'])) {
|
if (preg_match('/\.json/i', $theLink['url'])) {
|
||||||
?>
|
?>
|
||||||
<button type="button" onclick="goToURLOrAlertError('<?php echo $theLink['url']; ?>', {});"
|
<button type="button" onclick="downloadURLOrAlertError('<?php echo $theLink['url']; ?>', {}, '<?php echo $video['clean_title']; ?>.<?php echo strtolower($theLink['name']); ?>');"
|
||||||
class="btn btn-default" target="_blank">
|
class="btn btn-default" target="_blank">
|
||||||
<i class="fas fa-download"></i> <?php echo $theLink['name']; ?>
|
<i class="fas fa-download"></i> <?php echo $theLink['name']; ?>
|
||||||
</button>
|
</button>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue