Skip to content

Commit a89e1b2

Browse files
committed
fixed thumb proxification for youtube.com
1 parent feb4467 commit a89e1b2

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

src/YoutubePlugin.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,23 @@ public function onCompleted(ProxyEvent $event){
2929
// do this on all youtube pages
3030
$output = preg_replace('@masthead-positioner">@', 'masthead-positioner" style="position:static;">', $output, 1);
3131

32-
// replace future thumbnails with src=
33-
$output = preg_replace('#<img[^>]*data-thumb=#s','<img alt="Thumbnail" src=', $output);
32+
// data-thumb holds real image when it is available!
33+
$output = preg_replace_callback('/<img[^>]+data-thumb="(.*?)"[^>]*/is', function($matches){
34+
35+
// may or may not have src= attribute
36+
$has_src = strpos($matches[0], 'src="') !== false;
37+
38+
// proxified thumb url
39+
$thumb_url = $matches[1]; //proxify_url($matches[1], false);
40+
41+
if($has_src){
42+
// TODO: maybe remove data-thumb too?
43+
$matches[0] = str_replace('data-thumb', 'remove-this', $matches[0]);
44+
return preg_replace('/src="(.*?)"/i', 'src_replaced="1" src="'.$thumb_url.'"', $matches[0]);
45+
}
46+
47+
return preg_replace('/data-thumb="(.*?)"/i', 'src_added="1" src="'.$thumb_url.'"', $matches[0]);
48+
}, $output);
3449

3550
$youtube = new \YouTubeDownloader();
3651
// cannot pass HTML directly because all the links in it are already "proxified"...

0 commit comments

Comments
 (0)