forked from vikas5914/Facebook-Video-Downloader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.php
69 lines (56 loc) · 1.61 KB
/
main.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
$url = $_POST['url'];
$context = [
'http' => [
'method' => 'GET',
'header' => "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.47 Safari/537.36",
],
];
$context = stream_context_create($context);
$data = file_get_contents($url, false, $context);
function cleanStr($str)
{
return html_entity_decode(strip_tags($str), ENT_QUOTES, 'UTF-8');
}
function hd_finallink($curl_content)
{
$regex = '/hd_src_no_ratelimit:"([^"]+)"/';
if (preg_match($regex, $curl_content, $match)) {
return $match[1];
} else {return;}
}
function sd_finallink($curl_content)
{
$regex = '/sd_src_no_ratelimit:"([^"]+)"/';
if (preg_match($regex, $curl_content, $match1)) {
return $match1[1];
} else {return;}
}
function getTitle($curl_content)
{
$title = null;
if (preg_match('/h2 class="uiHeaderTitle"?[^>]+>(.+?)<\/h2>/', $curl_content, $matches)) {
$title = $matches[1];
} elseif (preg_match('/title id="pageTitle">(.+?)<\/title>/', $curl_content, $matches)) {
$title = $matches[1];
}
return cleanStr($title);
}
$hdlink = hd_finallink($data);
$sdlink = sd_finallink($data);
$title = gettitle($data);
$message = array();
if ($sdlink != "") {
$message = array(
'type' => 'success',
'title' => $title,
'hd_download_url' => $hdlink,
'sd_download_url' => $sdlink,
);
} else {
$message = array(
'type' => 'failure',
'message' => 'Error retrieving the download link for the url. Please try again later',
);
}
echo json_encode($message);