Skip to content

Instantly share code, notes, and snippets.

@httzipdev
Last active Jan 1, 2021
Embed
What would you like to do?
<?php
/* Share on httzip.com
*/
ini_set('display_errors', 'Off');
function get_web_page($url) {
$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => false,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_MAXREDIRS => 10,
CURLOPT_USERAGENT => "facebookexternalhit/1.1 (+https://www.facebook.com/externalhit_uatext.php)", // Do not Remove this line
CURLOPT_AUTOREFERER => true,
CURLOPT_CONNECTTIMEOUT => 120,
CURLOPT_TIMEOUT => 120,
);
$ch = curl_init($url);
curl_setopt_array($ch, $options);
$content = curl_exec($ch);
curl_close($ch);
$findHD = preg_match_all('/hd_src:"([^"]*)"/', $content, $hd);
$findSD = preg_match_all('/sd_src:"([^"]*)"/', $content, $sd);
$findAudio = preg_match_all('/,audio:\[(.*?)\]/sm', $content, $audio,PREG_SET_ORDER, 0);
/*Extract Audio*/
$audioString = str_replace(",audio:","",$audio[0][0]);
$audioFirstUrl = preg_match('/{url:"(.*?)\",/',$audioString,$audio,PREG_OFFSET_CAPTURE, 0);
/*End Extract Audio*/
$findThumbnail = preg_match_all('/"thumbnailUrl":"([^"]*)"/', $content, $thumbnail);
$findTitle = preg_match_all('/<meta property="og:title" content="([^"]*)"/', $content, $title);
$findPageName = preg_match_all('/<title id="pageTitle">([^"]*)<\/title>/', $content, $pageName);
$findVideoDescription = preg_match_all('/<div data-testid="post_message" class="_5pbx userContent _3576" data-ft="&#123;&quot;tn&quot;:&quot;K&quot;&#125;"><p>(.*)<\/p><\/div>/s', $content, $videoDescription);
$hd = !empty($hd[1][0]) ? $hd[1][0] : null;
$sd = !empty($sd[1][0]) ? $sd[1][0] : null;
$audio = !empty($audio[1][0]) ? $audio[1][0] : null;
$thumbnail = !empty($thumbnail[1][0]) ? str_replace("\\","",$thumbnail[1][0]) : null;
$description = !empty($videoDescription[1][0]) ? strip_tags($videoDescription[1][0]) : null;
$title = !empty($title[1][0]) ? $title[1][0] : null;
$pageName = !empty($pageName[1][0]) ? explode("-", $pageName[1][0]) : null;
// Output
$oData = [
"hd_src" => $hd,
"sd_src" => $sd,
"audio_src" => $audio,
"thumbnail" => $thumbnail,
"desc" => $description,
"title" => $title,
"page_name" => !empty($pageName[0]) ? $pageName[0] : ""
];
return json_encode($oData);
}
echo ( get_web_page("https://www.facebook.com/vtvchatluongcuocsong/videos/1771875049651792")); // Change your facebook video url
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment