1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-05 19:42:38 +02:00

Improve download layout

This commit is contained in:
Daniel 2022-01-19 16:18:18 -03:00
parent 56cdf7cd8f
commit 149ec78c8a
3 changed files with 59 additions and 15 deletions

View file

@ -59,12 +59,14 @@ if (count($downloadOptions) == 1) {
<?php
$count = 0;
$lastURL = '';
$lastFormat = '';
foreach ($downloadOptions as $theLink) {
if (!empty($theLink)) {
$count++;
$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">
<i class="fas fa-download"></i> Download <?php echo $theLink['name']; ?>
</button>
@ -75,9 +77,9 @@ if (count($downloadOptions) == 1) {
</div>
</div>
<script>
function _goToURLOrAlertError(url){
avideoToastSuccess(<?php echo json_encode(__('Downloading').'... '.$video['title']); ?>);
goToURLOrAlertError(url, {});
function _goToURLOrAlertError(url, format) {
avideoToastSuccess(<?php echo json_encode(__('Downloading') . '... ' . $video['title']); ?>);
downloadURLOrAlertError(url, {}, '<?php echo $video['clean_title']; ?>.' + format);
}
</script>
<?php
@ -87,7 +89,7 @@ if (count($downloadOptions) == 1) {
?>
<script>
$(function () {
_goToURLOrAlertError('<?php echo $lastURL; ?>');
_goToURLOrAlertError('<?php echo $lastURL; ?>', '<?php echo $lastFormat; ?>');
});
</script>
<?php

View file

@ -2091,23 +2091,65 @@ function animateChilds(selector, type, delay) {
});
}
function goToURLOrAlertError(jsonURL, data){
function goToURLOrAlertError(jsonURL, data) {
modal.showPleaseWait();
$.ajax({
url: jsonURL,
method: 'POST',
data: data,
success: function (response) {
if(response.error){
if (response.error) {
avideoAlertError(response.msg);
modal.hidePleaseWait();
}else if(response.url){
if(response.msg){
} else if (response.url) {
if (response.msg) {
avideoAlertInfo(response.msg);
}
document.location = response.url;
setTimeout(function(){ modal.hidePleaseWait();},3000)
}else{
setTimeout(function () {
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);
modal.hidePleaseWait();
}

View file

@ -260,7 +260,7 @@ if (User::hasBlockedUser($video['users_id'])) {
foreach ($filesToDownload as $theLink) {
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">
<i class="fas fa-download"></i> <?php echo $theLink['name']; ?>
</button>