From 4e616c7092b0fa2ad181117817ab80ad6cf4dfef Mon Sep 17 00:00:00 2001 From: Miika Launiainen Date: Sun, 19 Mar 2023 13:50:04 +0200 Subject: [PATCH] [YorushikaBridge] Replace YouTube embeds with YouTube link (#3321) --- bridges/YorushikaBridge.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/bridges/YorushikaBridge.php b/bridges/YorushikaBridge.php index ce649a97..12d02f1f 100644 --- a/bridges/YorushikaBridge.php +++ b/bridges/YorushikaBridge.php @@ -62,9 +62,9 @@ class YorushikaBridge extends BridgeAbstract $url = $art->find('a.clearfix', 0)->href; // Get article date - $exp = '/\d+\.\d+\.\d+/'; + $exp_date = '/\d+\.\d+\.\d+/'; $date = $art->find('.date', 0)->plaintext; - preg_match($exp, $date, $matches); + preg_match($exp_date, $date, $matches); $date = date_create_from_format('Y.m.d', $matches[0]); $date = date_format($date, 'd.m.Y'); @@ -72,6 +72,15 @@ class YorushikaBridge extends BridgeAbstract $art_html = getSimpleHTMLDOMCached($url)->find('.text.inview', 0); $art_html = defaultLinkTo($art_html, $this->getURI()); + // Check if article contains a embed YouTube video + $exp_youtube = '/https:\/\/[w\.]+youtube\.com\/embed\/([\w]+)/m'; + if (preg_match($exp_youtube, $art_html, $matches)) { + // Replace the YouTube embed with a YouTube link + $yt_embed = $art_html->find('iframe[src*="youtube.com"]', 0); + $yt_link = sprintf('https://youtube.com/watch?v=%1$s', $matches[1]); + $art_html = str_replace($yt_embed, $yt_link, $art_html); + } + $item['uri'] = $url; $item['title'] = $title . ' (' . $art_category . ')';