transcription/website/download.php

135 lines
3.2 KiB
PHP
Raw Normal View History

2021-03-18 23:04:04 +01:00
<?php
2021-03-23 12:13:23 +01:00
include( '_head.php' );
2021-03-23 12:54:17 +01:00
?>
<div class="container">
2021-03-23 12:13:23 +01:00
2021-03-23 12:54:17 +01:00
<?php
/**
* récupération d'une vidéo par youtube dl et conversion
*/
2021-03-23 12:13:23 +01:00
2021-03-23 12:54:17 +01:00
/**
* @param $cmd
*
* @return bool
*/
function command_exist( $cmd ) {
$return = shell_exec( sprintf( "which %s", escapeshellarg( $cmd ) ) );
2021-03-23 12:13:23 +01:00
2021-03-23 12:54:17 +01:00
return ! empty( $return );
}
2021-03-23 12:13:23 +01:00
2021-03-23 12:54:17 +01:00
if ( isset( $_POST[ 'url' ] ) ) {
// sanitize input
2021-03-23 12:13:23 +01:00
2021-03-23 12:54:17 +01:00
$url = $_POST[ 'url' ];
2021-08-18 16:26:49 +02:00
$lang = isset($_POST[ 'lang' ]) ? $_POST['lang'] : 'fr';
2021-03-23 12:54:17 +01:00
echo "<br/>récupération de la vidéo à l'url " . $url . " ... <br>";
2021-03-23 12:13:23 +01:00
// if (!command_exist('youtube-dl')) {
// print '[Erreur] pas de commande youtube-dl installée sur ce serveur';
// } else {
2021-08-18 16:26:49 +02:00
// $uniqid = date( 'Y-M-d_' ) . time();
$uniqid = 'demo_video_tk';
2021-03-23 12:54:17 +01:00
2021-03-27 09:13:03 +01:00
// # exemple url https://peertube.cipherbliss.com/videos/watch/e6a37508-042e-4d83-8598-5d36b764bb3d
2021-03-23 12:13:23 +01:00
2021-08-18 16:26:49 +02:00
if (file_exists('../input/ydl/'.$uniqid)) {
echo "The file $filename exists";
}else{
2021-03-27 10:08:19 +01:00
// exec( './youtube-dl.sh uniqueid_facho https://peertube.cipherbliss.com/videos/watch/b88a9568-517c-4a49-ab07-75c79323a825', $output, $result );
2021-03-27 10:30:38 +01:00
exec( './youtube-dl.sh ' . $uniqid . ' ' . $url . ' ' . $lang, $output, $result );
$phrases_only = file_get_contents( '../input/ydl/' . $uniqid . '/3_without_nulls.txt' );
2021-03-23 12:13:23 +01:00
2021-08-18 16:26:49 +02:00
echo "<br/> résultat du script. <br><pre>";
2021-03-23 12:54:17 +01:00
var_dump( $result );
2021-08-18 16:26:49 +02:00
echo "</pre><br/> output du script. <br><pre>";
var_dump( $output );
echo "</pre>";
2021-03-27 10:30:38 +01:00
2021-03-27 10:08:19 +01:00
2021-03-23 12:54:17 +01:00
if ( $result ) {
2021-03-27 10:30:38 +01:00
echo '<div class="alert is-danger"> </div>
<article class="message is-danger">
<div class="message-header">
<p>Problème de script</p>
<button class="delete" aria-label="delete"></button>
</div>
<div class="message-body">
<h2 class="title is2">
Sortie du script:
</h2><br> <br>
';
var_dump( $output );
echo '
</div>
</article>
';
2021-03-23 12:54:17 +01:00
include( '_foot.php' );
}
// récup du nom de fichier
2021-03-27 10:30:38 +01:00
echo '<article class="message is-info">
<div class="message-body">
récupération de la piste audio OK.
</div>
</article>';
2021-03-18 23:04:04 +01:00
2021-03-23 12:54:17 +01:00
echo "<br/>Conversion de la vidéo " . $uniqid . "... <br>";
2021-03-18 23:04:04 +01:00
2021-08-18 16:26:49 +02:00
}
2021-03-27 10:30:38 +01:00
echo '<article class="message is-success">
<div class="message-header">
<p>Succès</p>
<button class="delete" aria-label="delete"></button>
</div>
<div class="message-body">
Vous pouvez télécharger vos fichiers.
2021-08-18 16:26:49 +02:00
<ul>
<li>
<a href='../input/ydl/'.$uniqid.'/4_phrases_.txt'>phrases txt</a>
</li>
</ul>
2021-03-27 10:30:38 +01:00
</div>
</article><br>
<article class="message is-info">
<div class="message-header">
<p>Texte avec uniquement les phrases</p>
<button class="delete" aria-label="delete"></button>
</div>
<div class="message-body">
' . $phrases_only . '
</div>
</article>
<hr>
<br>
TODO: <br>
texte avec horodatage minute et secondes avant les phrases. <br>
fichier de sous titres au standard srt <br>
';
2021-03-18 23:04:04 +01:00
2021-03-23 12:54:17 +01:00
$dir = scandir( '../input/ydl/' . $uniqid );
var_dump( $dir );
2021-03-23 12:13:23 +01:00
// }
2021-03-18 23:04:04 +01:00
2021-03-23 12:54:17 +01:00
} else {
echo " <br> pas d'url envoyée. Vérifiez le formulaire. <a href='index.php'>Retour</a>";
}
2021-03-18 23:04:04 +01:00
2021-03-27 10:30:38 +01:00
// exec( './youtube-dl.sh canadien https://www.youtube.com/watch?v=w97pAEr3svc', $output, $result );
2021-03-23 12:54:17 +01:00
?>
2021-03-18 23:04:04 +01:00
2021-03-23 12:54:17 +01:00
</div>
<?php
2021-03-23 12:13:23 +01:00
include( '_foot.php' );