public function getInfo($name, &$err) { if (0 === strpos($name, 'http://') || 0 === strpos($name, 'https://')) { if (false !== ($youTubeId = YouTubeTool::getId($name))) { if (null !== $this->apiKey) { $v = YouTubeVideo::create()->setVideoId($youTubeId)->setApiKey($this->apiKey); $iframe = '<iframe src="https://www.youtube.com/embed/' . $youTubeId . '" frameborder="0" allowfullscreen></iframe>'; return ['type' => 'youtube', 'title' => $v->getTitle(), 'description' => nl2br($v->getDescription()), 'duration' => $v->getDuration(), 'thumbnail' => $v->getThumbnail(), 'iframe' => $iframe]; } else { $err = "YouTubeInfoHandler: YouTube api key not set"; } } } return false; }
function colis_get_info_by_name($name) { $type = 'none'; $ext = strtolower(FileSystemTool::getFileExtension($name)); $ext2Type = ['jpg' => 'image', 'jpeg' => 'image', 'gif' => 'image', 'png' => 'image', 'mp4' => 'video']; if (array_key_exists($ext, $ext2Type)) { $type = $ext2Type[$ext]; } $finalName = null; if (0 === strpos($name, 'http://') || 0 === strpos($name, 'https://')) { $finalName = $name; // handling youtube urls if ('video' === $type) { $type = 'externalVideo'; } elseif (false !== ($youTubeId = YouTubeTool::getId($finalName))) { $type = 'youtube'; } } else { // look for a file named name in a specific dir... $finalName = ITEMS_DIR_URL . '/' . $name; } switch ($type) { case 'image': return ['type' => $type, 'src' => $finalName]; break; case 'youtube': $v = YouTubeVideo::create()->setVideoId($youTubeId)->setApiKey(YOUTUBE_API_KEY); $iframe = '<iframe src="https://www.youtube.com/embed/' . $youTubeId . '" frameborder="0" allowfullscreen></iframe>'; return ['type' => $type, 'title' => $v->getTitle(), 'description' => nl2br($v->getDescription()), 'duration' => $v->getDuration(), 'thumbnail' => $v->getThumbnail(), 'iframe' => $iframe]; break; case 'externalVideo': $realPath = WEB_ROOT_DIR . $finalName; return ['type' => $type, 'src' => $finalName]; break; case 'video': $realPath = WEB_ROOT_DIR . $finalName; $duration = getVideoDuration($realPath); return ['type' => 'localVideo', 'src' => $finalName, 'duration' => $duration]; break; default: return ["type" => $type]; break; } }
<?php use PhpBeast\AuthorTestAggregator; use PhpBeast\PrettyTestInterpreter; use PhpBeast\Tool\ComparisonErrorTableTool; use YouTubeUtils\YouTubeTool; require_once "bigbang.php"; $agg = AuthorTestAggregator::create(); $a = ["https://www.youtube.com/watch?v=nCwRJUg3tcQ&list=PLv5BUbwWA5RYaM6E-QiE8WxoKwyBnozV2&index=4", "http://www.youtube.com/watch?v=nCwRJUg3tcQ&feature=relate", 'http://youtube.com/v/nCwRJUg3tcQ?feature=youtube_gdata_player', 'http://youtube.com/vi/nCwRJUg3tcQ?feature=youtube_gdata_player', 'http://youtube.com/?v=nCwRJUg3tcQ&feature=youtube_gdata_player', 'http://www.youtube.com/watch?v=nCwRJUg3tcQ&feature=youtube_gdata_player', 'http://youtube.com/?vi=nCwRJUg3tcQ&feature=youtube_gdata_player', 'http://youtube.com/watch?v=nCwRJUg3tcQ&feature=youtube_gdata_player', 'http://youtube.com/watch?vi=nCwRJUg3tcQ&feature=youtube_gdata_player', 'http://youtu.be/nCwRJUg3tcQ?feature=youtube_gdata_player', "https://youtube.com/v/nCwRJUg3tcQ", "https://youtube.com/vi/nCwRJUg3tcQ", "https://youtube.com/?v=nCwRJUg3tcQ", "https://youtube.com/?vi=nCwRJUg3tcQ", "https://youtube.com/watch?v=nCwRJUg3tcQ", "https://youtube.com/watch?vi=nCwRJUg3tcQ", "https://youtu.be/nCwRJUg3tcQ", "http://youtu.be/nCwRJUg3tcQ?t=30m26s", "https://youtube.com/v/nCwRJUg3tcQ", "https://youtube.com/vi/nCwRJUg3tcQ", "https://youtube.com/?v=nCwRJUg3tcQ", "https://youtube.com/?vi=nCwRJUg3tcQ", "https://youtube.com/watch?v=nCwRJUg3tcQ", "https://youtube.com/watch?vi=nCwRJUg3tcQ", "https://youtu.be/nCwRJUg3tcQ", "https://youtube.com/embed/nCwRJUg3tcQ", "http://youtube.com/v/nCwRJUg3tcQ", "http://www.youtube.com/v/nCwRJUg3tcQ", "https://www.youtube.com/v/nCwRJUg3tcQ", "https://youtube.com/watch?v=nCwRJUg3tcQ&wtv=wtv", "http://www.youtube.com/watch?dev=inprogress&v=nCwRJUg3tcQ&feature=related", "http://www.zoutube.com/watch?dev=inprogress&v=nCwRJUg3tcQ&feature=related", "http://www.you.tube.com/watch?dev=inprogress&v=nCwRJUg3tcQ&feature=related"]; $b = ['nCwRJUg3tcQ', 'nCwRJUg3tcQ', 'nCwRJUg3tcQ', 'nCwRJUg3tcQ', 'nCwRJUg3tcQ', 'nCwRJUg3tcQ', 'nCwRJUg3tcQ', 'nCwRJUg3tcQ', 'nCwRJUg3tcQ', 'nCwRJUg3tcQ', 'nCwRJUg3tcQ', 'nCwRJUg3tcQ', 'nCwRJUg3tcQ', 'nCwRJUg3tcQ', 'nCwRJUg3tcQ', 'nCwRJUg3tcQ', 'nCwRJUg3tcQ', 'nCwRJUg3tcQ', 'nCwRJUg3tcQ', 'nCwRJUg3tcQ', 'nCwRJUg3tcQ', 'nCwRJUg3tcQ', 'nCwRJUg3tcQ', 'nCwRJUg3tcQ', 'nCwRJUg3tcQ', 'nCwRJUg3tcQ', 'nCwRJUg3tcQ', 'nCwRJUg3tcQ', 'nCwRJUg3tcQ', 'nCwRJUg3tcQ', 'nCwRJUg3tcQ', false, false]; $agg->addTestsByColumn($a, $b, function ($value, $expected, &$msg, $testNumber) { $res = YouTubeTool::getId($value); if ($expected !== $res) { ComparisonErrorTableTool::collect($testNumber, $expected, $res); } return $expected === $res; }); PrettyTestInterpreter::create()->execute($agg); ComparisonErrorTableTool::display();