因此,第一步是获取我们要提取视频URL的页面源代码,这是代码如何完成的代码,
$uri = 'https://www.reddit.com/r/interestingasfuck/comments/130fgu1/interviewing_with_the_kkk_footage_might_disturbing/';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $uri);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3');
$html = curl_exec($ch); // here in html page's source stored
curl_close($ch);
在接下来的时候,我们将通过Regex方程找到视频URL,
$video_regex = '/(https:\/\/v\.redd\.it\/[a-z0-9]+\/HLSPlaylist\.m3u8).*?/';
preg_match($video_regex, $html, $videoUrl);
,然后从这个方程式获得视频ID并打印输出
$url = $videoUrl[0];
$regex1 = '/https:\/\/v\.redd\.it\/(\w+)\/HLSPlaylist\.m3u8/';
preg_match($regex1, $url, $video);
$video_id = $video[1];
echo '<video controls src="https://v.redd.it/' . $video_id . '/DASH_720.mp4" type="video/mp4" width="320"></video>';