如何通过PHP程序化获取JWPlayer在线流媒体视频的源URL?
How to Fetch JWPlayer Video Source from Vidnode Using PHP
Absolutely, you can programmatically grab that JWPlayer video source URL with PHP. Let’s break down the process step by step, considering how these streaming sites typically work:
Step 1: Fetch the Target Page HTML
First, you need to get the full HTML content of the Vidnode streaming page. Sites like this often block non-browser requests, so make sure to mimic a real user agent and handle any redirects:
$targetUrl = "https://vidnode.net/streaming.php?id=MTU3MjM2&title=Hostiles&typesub=SUB&sub_es=true&sub=L2hvc3RpbGVzL2hvc3RpbGVzLnZ0dA=="; // Initialize cURL session $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $targetUrl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Mimic a Chrome browser user agent curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36"); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // Follow redirects if any curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies.txt'); // Store cookies to maintain session curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies.txt'); $pageHtml = curl_exec($ch); curl_close($ch); if (!$pageHtml) { die("Failed to fetch the page content"); }
Step 2: Extract JWPlayer Configuration
Vidnode embeds JWPlayer with a JavaScript setup call that includes the video source details. We’ll use a regex to pull out this configuration JSON:
// Match the JWPlayer setup block preg_match('/jwplayer\([^)]+\)\.setup\((.*?)\);/s', $pageHtml, $matches); if (!isset($matches[1])) { die("Could not find JWPlayer configuration"); } // Parse the JSON configuration $playerConfig = json_decode($matches[1], true); if (json_last_error() !== JSON_ERROR_NONE) { die("Failed to parse JWPlayer configuration JSON"); }
Step 3: Extract the Video Source URL
Once you have the player config, you can dig into the playlist to get the video file URLs:
if (isset($playerConfig['playlist'][0]['sources'])) { $videoSources = $playerConfig['playlist'][0]['sources']; echo "Available video sources:\n"; foreach ($videoSources as $source) { // The 'file' field contains the direct video URL echo "- " . $source['file'] . "\n"; } } else { die("No video sources found in the player configuration"); }
Important Notes & Caveats
- Anti-scraping Measures: Vidnode might implement anti-bot checks like IP blocking, cookie validation, or dynamic content rendering. If the above method fails (because the config is loaded dynamically via JS), you’ll need a headless browser tool like Puppeteer (you can use PHP libraries like
spatie/browsershotto integrate it) to render the page fully. - URL Expiry: The video source URL (like the FB CDN link you shared) is often time-limited (check the
oeparameter, which is a Unix timestamp). It’ll stop working after the expiry time, so you’ll need to fetch it fresh each time. - Legal & Terms Compliance: Always review the website’s Terms of Service before scraping. Unauthorized scraping might violate copyright laws or site policies.
内容的提问来源于stack exchange,提问作者Adarsh Chouhan
相关产品推荐
相关产品推荐

