Add php-proxy-plugin-bundle to project

master 1.0
Michael Reber 5 years ago
parent aee2d99391
commit 4ea82b5224

@ -1 +0,0 @@
Subproject commit 172202c9b7913dc397b0a2eeacb68984a73f5c6e

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2016
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

@ -0,0 +1,4 @@
# php-proxy-plugin-bundle
A collection of useful plugins to be used with php-proxy or php-proxy-app. A lot of those are used on unblockvideos.com

@ -0,0 +1,17 @@
{
"name": "athlon1600/php-proxy-plugin-bundle",
"description": "A collection of useful plugins to be used with php-proxy",
"type": "library",
"license": "MIT",
"autoload": {
"psr-4": {
"Proxy\\Plugin\\": "src/"
},
"files": [
"src/utils.php"
]
},
"require": {
"athlon1600/youtube-downloader": "^1.0"
}
}

@ -0,0 +1,39 @@
<?php
namespace Proxy\Plugin;
use Proxy\Plugin\AbstractPlugin;
use Proxy\Event\ProxyEvent;
use Proxy\Html;
class DailyMotionPlugin extends AbstractPlugin {
protected $url_pattern = 'dailymotion.com';
public function onCompleted(ProxyEvent $event){
$response = $event['response'];
$content = $response->getContent();
// http://www.dailymotion.com/json/video/{$id}?fields=stream_h264_sd_url,stream_h264_hq_url,stream_h264_url,stream_h264_hd_url
if(preg_match('/"url":"([^"]+mp4[^"]*)"/m', $content, $matches)){
$video = stripslashes($matches[1]);
// generate our own player
$player = vid_player($video, 1240, 478);
$content = Html::replace_inner("#player", $player, $content);
}
// too many useless scripts on this site
$content = Html::remove_scripts($content);
$response->setContent($content);
}
}
?>

@ -0,0 +1,38 @@
<?php
use Proxy\Plugin\AbstractPlugin;
use Proxy\Event\ProxyEvent;
class LogPlugin extends AbstractPlugin {
public function onHeadersReceived(ProxyEvent $event){
// because this will be included in index.php - php-proxy-app/storage
$storage_dir = realpath('./storage');
if(!is_writable($storage_dir)){
return;
}
$log_file = $storage_dir.'/'.date("Y-m-d").'.log';
$request = $event['request'];
$response = $event['response'];
$data = array(
'ip' => $_SERVER['REMOTE_ADDR'],
'time' => time(),
'url' => $request->getUri(),
'status' => $response->getStatusCode(),
'type' => $response->headers->get('content-type', 'unknown'),
'size' => $response->headers->get('content-length', 'unknown')
);
$message = implode("\t", $data)."\r\n";
@file_put_contents($log_file, $message, FILE_APPEND);
}
}
?>

@ -0,0 +1,27 @@
<?php
namespace Proxy\Plugin;
use Proxy\Plugin\AbstractPlugin;
use Proxy\Event\ProxyEvent;
use Proxy\Html;
class TwitterPlugin extends AbstractPlugin {
protected $url_pattern = 'twitter.com';
public function onCompleted(ProxyEvent $event){
// there is some problem with content-length when submitting form...
$response = $event['response'];
$content = $response->getContent();
// remove all javascript
$content = Html::remove_scripts($content);
$response->setContent($content);
}
}
?>

@ -0,0 +1,59 @@
<?php
namespace Proxy\Plugin;
use Proxy\Plugin\AbstractPlugin;
use Proxy\Event\ProxyEvent;
use Proxy\Html;
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', 'Opera/7.50 (Windows XP; U)');
}
public function onCompleted(ProxyEvent $event){
$response = $event['response'];
$url = $event['request']->getUrl();
$output = $response->getContent();
// 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);
// replace future thumbnails with src=
$output = preg_replace('#<img[^>]*data-thumb=#s','<img alt="Thumbnail" src=', $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);
}
}
?>

@ -0,0 +1,45 @@
<?php
function vid_player($url, $width, $height, $extension = false){
$path = parse_url($url, PHP_URL_PATH);
$html5 = false;
if($path){
$extension = $extension ? $extension : pathinfo($path, PATHINFO_EXTENSION);
if($extension == 'mp4' || $extension == 'webm' || $extension == 'ogg'){
$html5 = true;
}
}
// this better be an absolute url and proxify_url function better already be included from somewhere
$video_url = proxify_url($url);
if($html5){
$html = '<video width="100%" height="100%" controls autoplay>
<source src="'.$video_url.'" type="video/'.$extension.'">
Your browser does not support the video tag.
</video>';
} else {
// encode before embedding it into player's parameters
$video_url = rawurlencode($video_url);
$html = '<object id="flowplayer" width="'.$width.'" height="'.$height.'" data="//releases.flowplayer.org/swf/flowplayer-3.2.18.swf" type="application/x-shockwave-flash">
<param name="allowfullscreen" value="true" />
<param name="wmode" value="transparent" />
<param name="flashvars" value=\'config={"clip":"'.$video_url.'", "plugins": {"controls": {"autoHide" : false} }}\' />
</object>';
}
return $html;
}
?>
Loading…
Cancel
Save