Reputation: 49
Hello here is my code and i can't get data, don't know where m doing mistake. i trying to get download link in output. please corrent this code.
<?php
$id = 'yeyBEpsZfrs';
$url = "http://youpak.com/watch?v=".$id;
$html = file_get_contents($url);
$dom = new DOMDocument('1.0', 'utf-8');
$dom->loadHTML($html);
$classname = 'btn-group btn-group-justified';
$xpath = new DOMXPath($dom);
$results = $xpath->query("//*[@class='" . $classname . "']");
if ($results->length > 0)
{
$children = $results->item(0)->childNodes;
foreach ($children as $child) {
$ar['download'] .= $child->ownerDocument->saveXML( $child );
}
}
$belement = $dom->getElementById("videoholder");
$dom->saveHTML($belement);
$ar['play'] = $belement->C14N();
return($ar);
?>
Upvotes: 0
Views: 100
Reputation: 240
You can Get this data in JSON With This Code
$id = 'yeyBEpsZfrs';
$url = "https://youpak.com/watch?v=".$id;
$html = file_get_contents($url);
$dom = new DOMDocument();
@$dom->loadHTML($html);
$classname = 'btn-group btn-group-justified';
$xpath = new DOMXPath($dom);
$results = $xpath->query("//*[@class='" . $classname . "']");
if ($results->length > 0)
{
$children = $results->item(0)->childNodes;
foreach ($children as $child) {
@$ar['download'] .= $child->ownerDocument->saveXML( $child );
}
}
$links = array();
$expression = "//a[contains(@class, '')]";
foreach($xpath->evaluate($expression) as $link) {
$content = $link->textContent;
$link = $link->getAttribute('href');
preg_match("/&mime=([^&]*)&/", $link, $mime);
preg_match("/&itag=([^&]*)&/", $link, $itag);
preg_match("/\((.*)\)/", $content, $extension);
@$links[$itag[1]] = array(
"quality" => $itag[1],
"type" => $mime[1],
"url" => $link
);
}
header('Content-Type: application/json');
echo json_encode($links);
Upvotes: 1