Skip to content

Commit 402b9e4

Browse files
committed
updated xhamster plugin
1 parent b09920b commit 402b9e4

2 files changed

Lines changed: 22 additions & 18 deletions

File tree

src/XHamsterPlugin.php

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,38 +10,42 @@ class XHamsterPlugin extends AbstractPlugin {
1010

1111
protected $url_pattern = 'xhamster.com';
1212

13+
public function onBeforeRequest(ProxyEvent $event){
14+
// mobile
15+
$event['request']->headers->set('user-agent', 'Mozilla/5.0 (Linux; U; Android 4.0.3; de-ch; HTC Sensation Build/IML74K) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30');
16+
}
17+
1318
private function find_video($html){
14-
1519
$file = false;
1620

17-
if(preg_match("/file: '([^']+)'/", $html, $matches)){
18-
$file = rawurldecode($matches[1]);
19-
} else if(preg_match("@srv=&file=([^&]+)@s", $html, $matches)){
21+
if(preg_match('/"play":"([^"]+)"/', $html, $matches)){
2022
$file = rawurldecode($matches[1]);
23+
$file = str_replace('\\', '', $file);
2124
}
2225

2326
return $file;
2427
}
2528

26-
private function img_sprite($matches){
27-
return str_replace($matches[1], proxify_url($matches[1], $matches[1]), $matches[0]);
28-
}
29-
3029
public function onCompleted(ProxyEvent $event){
31-
3230
$response = $event['response'];
3331
$content = $response->getContent();
3432

35-
// remove ts_popunder stuff
36-
$content = preg_replace('/<script[^>]*no-popunder[^>]*><\/script>/m', '', $content);
37-
$content = preg_replace_callback('/<img[^>]*sprite=\'(.*?)\'/im', array($this, 'img_sprite'), $content);
33+
// remove ads
34+
$content = HTML::remove('.ts', $content);
3835

39-
// are we on a video page?
36+
// is this video page?
4037
$file = $this->find_video($content);
41-
4238
if($file){
4339
$player = vid_player($file, 638, 504);
44-
$content = Html::replace_inner("#playerSwf", $player, $content);
40+
$player = str_replace('<video', '<video style="display:block;', $player);
41+
42+
$content = HTML::replace_inner('#video_box', $player, $content);
43+
44+
// remove "show comments" button
45+
$content = HTML::remove('#commentToggle', $content);
46+
47+
// display all comments by default
48+
$content = str_replace('<div class="comments_block"', '<div style="display:block;" class="comments_block"', $content);
4549
}
4650

4751
$content = Html::remove_scripts($content);

src/utils.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

3-
function vid_player($url, $width, $height, $extension = false){
4-
3+
function vid_player($url, $width = '100%', $height = '100%', $extension = false){
4+
55
$path = parse_url($url, PHP_URL_PATH);
66

77
$html5 = false;
@@ -20,7 +20,7 @@ function vid_player($url, $width, $height, $extension = false){
2020

2121
if($html5){
2222

23-
$html = '<video width="100%" height="100%" controls autoplay>
23+
$html = '<video width="'.$width.'" height="'.$height.'" controls autoplay>
2424
<source src="'.$video_url.'" type="video/'.$extension.'">
2525
Your browser does not support the video tag.
2626
</video>';

0 commit comments

Comments
 (0)