YouTube видео в HTML5 Player с YouTube-DL и PHP - PullRequest
0 голосов
/ 09 февраля 2019

Я нашел код PHP для YouTube-DL следующим образом

<?php
 
 define('YOUTUBE_DL', '/usr/local/bin/youtube-dl'); // find your youtube-dl path and replace with it
 $youtube_video = 'https://www.youtube.com/watch?v=e4Uq8O5ZhUA'; // replace with any youtube video
/**
 * Fetches direct URL of given youtube video
 */
function getDirectUrl($youtube_video) {
  // lets build command to get direct url via youtube-dl
  $video_json_command = YOUTUBE_DL.' -g '.$youtube_video;
  // get url
  $direct_url = shell_exec($video_json_command);
// remove any possible white spaces
  $direct_url = str_replace(array(' ',"\n"), '', $direct_url);
return $direct_url;
 }
function buildPlayer($direct_url) {
  echo '<video width="400" controls>
    <source src="'.$direct_url.'" type="video/mp4">
    Your browser does not support HTML5 video.
  </video>';
 }
function playVideo($youtube_video) {
  $url = getDirectUrl($youtube_video);
  buildPlayer($url);
 }
// call below function and play any video
 playVideo($youtube_video);
?>

Я хочу изменить URL https://www.youtube.com/watch?v=e4Uq8O5ZhUA вне php-кода

пример: site.com/youtube-dl.php? link = https://www.youtube.com/watch?v=e4Uq8O5ZhUA

, существующий в $ youtube_video = 'https://www.youtube.com/watch?v=e4Uq8O5ZhUA'

заменить на $ youtube_video =' $ _GET ['link'] ' но ошибка

как это может работать?

1 Ответ

0 голосов
/ 09 февраля 2019

Безопасное это

if (ereg("^[0-9A-z_-]+$",$_GET['link'])) $youtube_video = "https://www.youtube.com/watch?v=".$_GET['link'];

http://example.com/youtube-dl.php?link=e4Uq8O5ZhUA

...