Anyone can help me with this. <?php function xVideos($url) { $url = str_replace(' ', '', $url); if(!empty($url)): curl_setopt($curl = curl_init($url), CURLOPT_RETURNTRANSFER, 1); preg_match("/flv_url=(.+)url_bigthumb=([^&]+)/i", curl_exec($curl), $infos); curl_close($curl); return "<a href='".urldecode($infos[1])."'><img src='".urldecode($infos[2])."' width='150' height='150' border=0 alt='Download'></a>"; endif; } echo (!empty($_GET['url'])) ? xVideos($_GET['url']) : 'E o link ?'; ?> PHP: The code above supposed to get links from xvideos.com by enter localhost/index.php?url=xvideos-dot-com/videos0099/example-link. However, isn't working. Couldn't figure out why
You didn't check what you got back - xvideos.com redirects to www.xvideos.com, and you didn't allow for cURL to follow redirects. The following code works: <?php function xVideos($url) { $url = str_replace(' ', '', $url); if(!empty($url)): curl_setopt($curl = curl_init($url), CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); preg_match("/flv_url=(.+)url_bigthumb=([^&]+)/i", curl_exec($curl), $infos); curl_close($curl); return "<a href='".urldecode($infos[1])."'><img src='".urldecode($infos[2])."' width='150' height='150' border=0 alt='Download'></a>"; endif; } echo (!empty($_GET['url'])) ? xVideos($_GET['url']) : 'E o link ?'; ?> PHP:
Try "youtubedl" to download from more than 160 video sharing websites (including the one you mentioned). You can download in variety of formats including MP4. Calling this tool from PHP is simple: <?php $output = `youtubedl "<VIDEO_PAGE_URL> "`; print $output; Code (markup):