@@ -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 );
0 commit comments