-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
68 lines (59 loc) · 2.87 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Facebook Video Downloader</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container mt-5">
<div class="row justify-content-center">
<div class="col-md-6">
<h2 class="text-center">Facebook Video Downloader</h2>
<form method="POST" action="">
<div class="mb-3">
<label for="videoUrl" class="form-label">Enter Facebook Video URL:</label>
<input type="url" class="form-control" id="videoUrl" name="videoUrl" placeholder="https://www.facebook.com/video-url" required>
</div>
<button type="submit" class="btn btn-primary w-100">Download Video</button>
</form>
</div>
</div>
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$videoUrl = $_POST['videoUrl'];
function fetchFacebookVideo($url) {
$mobileUserAgent = "Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $mobileUserAgent);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
function extractVideoUrl($html) {
$pattern = '/https:\/\/video\.xx\.fbcdn\.net\/[^"]+\.mp4[^"]*/';
if (preg_match($pattern, $html, $matches)) {
return $matches[0];
}
return false;
}
$htmlContent = fetchFacebookVideo($videoUrl);
$videoDownloadUrl = extractVideoUrl($htmlContent);
if ($videoDownloadUrl) {
echo "<div class='alert alert-success mt-4'>Video is ready for download!</div>";
echo "<a href='$videoDownloadUrl' class='btn btn-success w-100' download>Download Now</a>";
} else {
echo "<div class='alert alert-danger mt-4'>Failed to retrieve the video. Ensure the URL is correct or the video is public.</div>";
}
}
?>
</div>
<!-- Bootstrap JS -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>