[YorushikaBridge] Replace YouTube embeds with YouTube link (#3321)

This commit is contained in:
Miika Launiainen 2023-03-19 13:50:04 +02:00 committed by GitHub
parent fbe7cc11ec
commit 4e616c7092
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 2 deletions

View File

@ -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('<a href="https://youtube.com/watch?v=%1$s">https://youtube.com/watch?v=%1$s</a>', $matches[1]);
$art_html = str_replace($yt_embed, $yt_link, $art_html);
}
$item['uri'] = $url;
$item['title'] = $title . ' (' . $art_category . ')';