From 4f6277b6b508c9389c8bb6730f503ae27f7f2134 Mon Sep 17 00:00:00 2001 From: logmanoriginal Date: Fri, 16 Feb 2018 22:12:24 +0100 Subject: [PATCH] [YoutubeBridge] Fix parsing author name breaks the bridge The author name is parsed by searching a string within the entire HTML document: $author = $html->innertext; $author = substr($author, strpos($author, '"author=') + 8); $author = substr($author, 0, strpos($author, '\u0026')); This solution will return big portions of the HTML document if the strpos function returns zero (not found). This commit replaces the previous implementation by searching for a specific script tag and making use of the JSON data inside it. References #580 --- bridges/YoutubeBridge.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/bridges/YoutubeBridge.php b/bridges/YoutubeBridge.php index b10db9e..b4c3f6c 100644 --- a/bridges/YoutubeBridge.php +++ b/bridges/YoutubeBridge.php @@ -56,9 +56,19 @@ class YoutubeBridge extends BridgeAbstract { return; } - $author = $html->innertext; - $author = substr($author, strpos($author, '"author=') + 8); - $author = substr($author, 0, strpos($author, '\u0026')); + foreach($html->find('script') as $script){ + $data = trim($script->innertext); + + if(strpos($data, '{') !== 0) + continue; // Wrong script + + $json = json_decode($data); + + if(!isset($json->itemListElement)) + continue; // Wrong script + + $author = $json->itemListElement[0]->item->name; + } if(!is_null($html->find('div#watch-description-text', 0))) $desc = $html->find('div#watch-description-text', 0)->innertext;