-
Notifications
You must be signed in to change notification settings - Fork 23
Open
Description
I fixed Youtube and Pornhub
Youtube
Youtube now works in
- Homepage
- Trending
- Video Page
Bug
- Can't do search action
<?php
namespace Proxy\Plugin;
use Proxy\Event\ProxyEvent;
use Proxy\Html;
use YouTube\YouTubeDownloader;
class YoutubePlugin extends AbstractPlugin
{
protected $url_pattern = 'youtube.com';
// force old YouTube layout!
public function onBeforeRequest(ProxyEvent $event)
{
//$event['request']->headers->set('Cookie', 'PREF=f6=8');
$event['request']->headers->set('User-Agent', 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)');
$event['request']->headers->set('X-YouTube-Client-Name','1');
$event['request']->headers->set('X-YouTube-Client-Version','1.20200731.02.01');
}
public function onCompleted(ProxyEvent $event)
{
$response = $event['response'];
$url = $event['request']->getUrl();
$output = $response->getContent();
if(!preg_match('/pbj=1/',$url))
{
$redirect=$url.(!preg_match('/\?/',$url)?("?"):("&"))."pbj=1";
$response->headers->set('location', proxify_url($redirect, $url));
return;
}
// remove top banner that's full of ads
$output = Html::remove("#header", $output);
// do this on all youtube pages
$output = preg_replace('@masthead-positioner">@', 'masthead-positioner" style="position:static;">', $output, 1);
// data-thumb holds real image when it is available!
$output = preg_replace_callback('/<img[^>]+data-thumb="(.*?)"[^>]*/is', function ($matches) {
// may or may not have src= attribute
$has_src = strpos($matches[0], 'src="') !== false;
// proxified thumb url
$thumb_url = proxify_url($matches[1], false);
if ($has_src) {
// TODO: maybe remove data-thumb too?
$matches[0] = str_replace('data-thumb', 'remove-this', $matches[0]);
return preg_replace('/src="(.*?)"/i', 'src_replaced="1" src="' . $thumb_url . '"', $matches[0]);
}
return preg_replace('/data-thumb="(.*?)"/i', 'src_added="1" src="' . $thumb_url . '"', $matches[0]);
}, $output);
$youtube = new YouTubeDownloader();
// cannot pass HTML directly because all the links in it are already "proxified"...
$links = $youtube->getDownloadLinks($url, "mp4 360, mp4");
if ($links) {
$url = current($links)['url'];
$player = vid_player($url, 640, 390, 'mp4');
// this div blocks our player controls
$output = Html::remove("#theater-background", $output);
// replace youtube player div block with our own
$output = Html::replace_inner("#player-api", $player, $output);
}
// causes too many problems...
$output = Html::remove_scripts($output);
$response->setContent($output);
}
}Pornhub
Fied
- Thumb
- Search button on PC
- Video page on PC
<?php
namespace Proxy\Plugin;
use Proxy\Event\ProxyEvent;
use Proxy\Html;
use Proxy\Plugin\AbstractPlugin;
class PornhubPlugin extends AbstractPlugin
{
protected $url_pattern = 'pornhub.com';
private function get_video_url($page_url){
$_ch = curl_init();
curl_setopt($_ch, CURLOPT_URL, $page_url);
curl_setopt($_ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($_ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($_ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($_ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Linux; Android 10; Pixel 4 XL) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.136 Mobile Safari/537.36');
$output = curl_exec($_ch);
curl_close($_ch);
preg_match('/"text":"480p","url":"([^"]+)/', $output, $matches);
$url = $matches[1];
$url = str_replace('\\', '', $url);
return $url;
}
public function onCompleted(ProxyEvent $event)
{
$response = $event['response'];
$content = $response->getContent();
//fix thumb
$content = preg_replace_callback('/<img[^>]+src="([^"]+)"[^>]+data-src = "([^"]+)/', function($matches){
return str_replace($matches[1], $matches[2], $matches[0]);
}, $content);
//fix search button
$content = preg_replace('/<div id="btnSearch" class="orangeButton"><i><\/i><\/div>/','<button id="btnSearch" class="orangeButton"><i></i></button>',$content);
$url = $event['request']->getUrl();
if(preg_match('/view_video/',$url)){
$video_url = $this->get_video_url($url);
$content = Html::remove_scripts($content);
$userAgent = $_SERVER['HTTP_USER_AGENT'];
if(strpos($userAgent, "Windows") || strpos($userAgent, "Mac OS X")){
$player = vid_player($video_url, 989, 557,"mp4");
$content = Html::replace_inner('#player', $player, $content);
}
else{
$player = vid_player($video_url, 400, 216,"mp4");
$content = Html::replace_inner('.playerWrapper', $player, $content);
}
}
else {$content = Html::remove_scripts($content);}
$response->setContent($content);
}
}Metadata
Metadata
Assignees
Labels
No labels