Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #7 #10 and #14 #22

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 23 additions & 8 deletions youtube-dl.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,8 @@ private function get_videodata($str)
$pb_info = self::get_public_info();

if($pb_info !== FALSE) {
$htmlTitle = htmlentities(utf8_decode($pb_info["title"]));
//https://github.com/eyecatchup/php-yt_downloader/issues/10#issuecomment-117083347
$htmlTitle = htmlentities(utf8_decode($pb_info["title"]), ENT_QUOTES | ENT_IGNORE, "UTF-8");
$videoTitle = self::canonicalize($htmlTitle);
}
else {
Expand All @@ -492,6 +493,9 @@ private function get_videodata($str)
*/
private function get_url_map($data)
{
//https://github.com/eyecatchup/php-yt_downloader/issues/7
$videos = false;

preg_match('/stream_map=(.[^&]*?)&/i',$data,$match);
if(!isset($match[1])) {
return FALSE;
Expand All @@ -505,11 +509,18 @@ private function get_url_map($data)
$urls = explode(',',$fmt_url);
$tmp = array();

//https://github.com/eyecatchup/php-yt_downloader/issues/10#issuecomment-147021789
foreach($urls as $url) {
if(preg_match('/itag=([0-9]+)&url=(.*?)&.*?/si',$url,$um))
{
$u = urldecode($um[2]);
$tmp[$um[1]] = $u;
$lines = explode('&',$url);
$num = '';
$url = '';
foreach($lines as $u){
$num = ((empty($num)) && (preg_match("/itag=/i",$u))) ? str_replace("itag=","",$u):$num;
$url = ((empty($url)) && (preg_match("/url=/i",$u))) ? str_replace("url=","",$u):$url;
if((!empty($url)) && ((!empty($num)))){
$tmp[$num] = urldecode($url);
break;
}
}
}

Expand Down Expand Up @@ -573,7 +584,8 @@ private function formattedVideoTitle($str)

$title = explode("&", $matches[1][0]);
$title = $title[0];
$title = htmlentities(utf8_decode($title));
//https://github.com/eyecatchup/php-yt_downloader/issues/10#issuecomment-117083347
$title = htmlentities(utf8_decode($title), ENT_QUOTES | ENT_IGNORE, "UTF-8");

return self::canonicalize($title);
}
Expand Down Expand Up @@ -647,8 +659,11 @@ private function valid_dir($dir)
*/
private function has_ffmpeg()
{
$sh = `which ffmpeg`;
return (bool) (strlen(trim($sh)) > 0);
// check if ffmpeg is installed using returnVariable on help command
$returnVar = false;
$out = array();
exec('ffmpeg -h', $out, $returnVar);
return $returnVar === 0;
}

/**
Expand Down