Getting a script to fetch Facebook video links on android browsers


Getting a script to fetch Facebook video links on android browsers



These coding for Facebook links are fetching errors on android browsers only. What might be missing in coding?



Below is a text form of PHP and json file for the script







/*
* {lib_name; facebook}
*/



/**
* Description of Facebook
*
* @hadit
/
/

{source_info}{"name":"Facebook.com","website":"https://www.facebook.com/"}{end_source_info}
*/



class Facebook
{


function getMediaInfo($url)
{
$data = array();
$data['found'] = 0;
$urlParts = parse_url($url);

$pathArr = explode("/", rtrim($urlParts['path'], "/"));

$context = [
'http' => [
'method' => 'GET',
'header' => "User-Agent: " . $_SERVER['HTTP_USER_AGENT'],
],
];

$context = stream_context_create($context);

if($urlParts['host'] == 'mobile.facebook.com'){
$url = str_replace('mobile.facebook', 'web.facebook', $url);

}
if($urlParts['host'] == 'm.facebook.com'){
$url = str_replace('m.facebook', 'web.facebook', $url);

}
if($urlParts['host'] == 'www.facebook.com'){
$url = str_replace('www.facebook', 'web.facebook', $url);


}

$result = file_get_contents($url, false, $context);

if ($result)
{
$videoSDlink = getStringBetween($result, 'sd_src_no_ratelimit:"', '"');
$videoHDlink = getStringBetween($result, 'hd_src_no_ratelimit:"', '"');
if(empty($videoHDlink)){
$videoHDlink = getStringBetween($result, 'hd_src:"', '"');

}


if ($videoSDlink)
{

$data['found'] = 1;
$data['id'] = $id;
$links = array();

$links['SD'] = $videoSDlink;
if (!empty($videoHDlink))
{
$links['HD'] = $videoHDlink;
}
$ti = getStringBetween($result, 'h2 class="uiHeaderTitle"', '</h2>');
if ($ti)
{
$title = $ti;
} else
{

$title = getStringBetween($result, 'title id="pageTitle">', '</title>');
}

$description = getStringBetween($result, '<meta property="og:description" content="', '"/>');
$image = html_entity_decode(getStringBetween($result, '<meta property="og:image" content="', '" /><meta property="og:url" content="'));
$data['title'] = $title;
$data['image'] = $image;

if (!empty($description))
{
$data['description'] = htmlentities(truncate(trim(preg_replace('/[s]+/', ' ', preg_replace("/r|n/", " ", $description))), 250), ENT_QUOTES);
} else
{
$data['description'] = "Download " . $title . " From Facebook";
}

$formatCodes = array(
"SD" => array("order" => "1", "height" => "{{height}}", "ext" => "mp4", "resolution" => "SD", "video" => "true", "video_only" => "false"),
"HD" => array("order" => "2", "height" => "{{height}}", "ext" => "mp4", "resolution" => "HD", "video" => "true", "video_only" => "false")
);
$videos = array();
foreach ($formatCodes as $formatId => $formatData)
{
if (isset($links[$formatId]))
{
$link = array();
$link['data'] = $formatData;
$link['formatId'] = $formatId;
$link['order'] = $formatData['order'];
$link['url'] = $links[$formatId];
$link['title'] = $title . "." . $formatData['ext'];
$link['size'] = "unknown";
array_push($videos, $link);
}
}
$data['videos'] = $videos;
}
}


return $data;
}



}



json FILE:



{"order": "1", "icon": "facebook.png", "status": "1", "linkCacheTime": "3600"}









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

PySpark - SparkContext: Error initializing SparkContext File does not exist

django NoReverseMatch Exception

List of Kim Possible characters