Skip to content

Commit eb7773f

Browse files
committed
Use handleYoutube on all bridges
1 parent e235847 commit eb7773f

15 files changed

+37
-80
lines changed

bridges/AssociatedPressNewsBridge.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,7 @@ private function processMediaPlaceholders($html, $id)
214214
}
215215

216216
if ($media['type'] === 'YouTube') {
217-
$div->outertext = <<<EOD
218-
<iframe src="https://www.youtube.com/embed/{$media['externalId']}" width="560" height="315">
219-
</iframe>
220-
EOD;
217+
$div->outertext = handleYoutube($media['externalId']);
221218
}
222219
}
223220
}
@@ -249,10 +246,7 @@ private function processVideo($storyContent)
249246
$video = $storyContent['media'][0];
250247

251248
if ($video['type'] === 'YouTube') {
252-
$url = 'https://www.youtube.com/embed/' . $video['externalId'];
253-
$html = <<<EOD
254-
<iframe width="560" height="315" src="{$url}" frameborder="0" allowfullscreen></iframe>
255-
EOD;
249+
$html = handleYoutube($video['externalId']);
256250
} else {
257251
$html = <<<EOD
258252
<video controls poster="https://storage.googleapis.com/afs-prod/media/{$video['id']}/800.jpeg" preload="none">

bridges/Drive2ruBridge.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,7 @@ private function adjustContent($content)
173173
$node->outertext = '';
174174
}
175175
foreach ($content->find('iframe') as $node) {
176-
preg_match('/embed\/(.*?)\?/', $node->src, $match);
177-
$node->outertext = '<a href="https://www.youtube.com/watch?v=' . $match[1] .
178-
'">https://www.youtube.com/watch?v=' . $match[1] . '</a>';
176+
$node->outertext = handleYoutube($node->src);
179177
}
180178
return $content;
181179
}

bridges/EuronewsBridge.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,7 @@ private function getItemContent($url)
207207
$player_div = $html->find('.js-player-pfp', 0);
208208
if ($player_div) {
209209
$video_id = $player_div->getAttribute('data-video-id');
210-
$video_url = 'https://www.youtube.com/watch?v=' . $video_id;
211-
$content .= '<a href="' . $video_url . '">' . $video_url . '</a>';
210+
$content .= handleYoutube($video_id);
212211
}
213212
}
214213

bridges/FallGuysBridge.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,23 +94,18 @@ public function collectData()
9494
if (count($mediaOptions) == count($mainContentOptions)) {
9595
for ($i = 0; $i < count($mediaOptions); $i++) {
9696
if (property_exists($mediaOptions[$i], 'youtubeVideo')) {
97-
$videoUrl = 'https://youtu.be/' . $mediaOptions[$i]->youtubeVideo->contentId;
98-
$image = $mainContentOptions[$i]->image->src ?? '';
97+
$videoID = $mediaOptions[$i]->youtubeVideo->contentId;
98+
$videoHtml = handleYoutube($videoID);
9999

100-
$content .= '<p>';
100+
$content .= '<p>' . $videoHtml;
101101

102+
$image = $mainContentOptions[$i]->image->src ?? '';
102103
if ($image != $headerImage) {
103104
$contentImages[] = $image;
104105

105-
$content .= <<<HTML
106-
<a href="{$videoUrl}"><img src="{$image}"></a><br>
107-
HTML;
106+
$content .= '<img src="{$image}"><br>';
108107
}
109108

110-
$content .= <<<HTML
111-
<i>(Video: <a href="{$videoUrl}">{$videoUrl}</a>)</i>
112-
HTML;
113-
114109
$content .= '</p>';
115110
}
116111
}

bridges/GenshinImpactBridge.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ public function collectData()
3737
if (preg_match($exp_youtube, $article_html, $matches)) {
3838
// Replace the YouTube embed with a YouTube link
3939
$yt_embed = $article_html->find('div[class="ttr-video-frame"]', 0);
40-
$yt_link = sprintf('<a href="https://www.youtube.com/watch?v=%1$s">https://www.youtube.com/watch?v=%1$s</a>', $matches[1]);
41-
$article_html = str_replace($yt_embed, $yt_link, $article_html);
40+
$yt_embed->outertext = handleYoutube($yt_embed);
4241
}
4342
$item = [];
4443
$item['title'] = $json_item['sTitle'];

bridges/GolemBridge.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,7 @@ private function extractContent($page, $prevcontent)
133133
if (array_key_exists($i, $embedSrcs)) {
134134
$src = $embedSrcs[$i];
135135
if (preg_match('/youtube(-nocookie)?\.com/', $src, $match)) {
136-
$placeholders[$i]->innertext = <<<EOT
137-
<iframe width="560" height="315" src="$src" title="YouTube video player" frameborder="0"
138-
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
139-
referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>';
140-
EOT;
136+
$placeholders[$i]->innertext = handleYoutube($src);
141137
}
142138
}
143139
}

bridges/HeiseBridge.php

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ public function collectData()
127127

128128
protected function parseItem(array $item)
129129
{
130+
$item['uri'] = 'https://www.heise.de/news/ChatGPT-Atlas-ist-ein-Quatsch-Browser-10964861.html';
130131
$sessioncookie = $this->getInput('sessioncookie');
131132

132133
// strip rss parameter
@@ -207,19 +208,13 @@ private function addArticleToItem($item, $article)
207208
//fix for embbedded youtube-videos
208209
$oldlink = '';
209210
foreach ($article->find('div.video__yt-container') as &$ytvideo) {
210-
if (preg_match('/www.youtube.*?\"/', $ytvideo->innertext, $link) && $link[0] != $oldlink) {
211-
//save link to prevent duplicates
212-
$oldlink = $link[0];
213-
$ytiframe = <<<EOT
214-
<iframe width="560" height="315" src="https://$link[0] title="YouTube video player" frameborder="0"
215-
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
216-
referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
217-
EOT;
218-
//check if video is in header or article for correct possitioning
219-
if (strpos($header->innertext, $link[0])) {
220-
$item['content'] .= $ytiframe;
211+
$ytResult = handleYoutube($ytvideo->innertext);
212+
if ($ytResult) {
213+
//check if video is in header or article for correct positioning
214+
if (strpos($header->innertext, $ytvideo)) {
215+
$item['content'] .= $ytResult;
221216
} else {
222-
$ytvideo->innertext .= $ytiframe;
217+
$ytvideo->innertext .= $ytResult;
223218
$reloadneeded = 1;
224219
}
225220
}

bridges/RedditBridge.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,7 @@ private function collectDataInternal(): void
280280
}
281281
} elseif (isset($data->media) && $data->media->type == 'youtube.com') {
282282
// Youtube link
283-
$item['content'] = $this->createFigureLink($data->url, $data->media->oembed->thumbnail_url, 'YouTube');
284-
//$item['content'] = htmlspecialchars_decode($data->media->oembed->html);
283+
$item['content'] = handleYoutube($data->url);
285284
} elseif (explode('.', $data->domain)[0] == 'self') {
286285
// Crossposted text post
287286
// TODO (optionally?) Fetch content of the original post.

bridges/ReutersBridge.php

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -535,17 +535,7 @@ private function handleArticleContent($contents)
535535
EOD;
536536
break;
537537
case 'youtube':
538-
$url = "https://www.youtube.com/embed/$cid";
539-
$embed .= <<<EOD
540-
<‌iframe
541-
width="560"
542-
height="315"
543-
src="{$url}"
544-
frameborder="0"
545-
allowfullscreen
546-
>
547-
</iframe>
548-
EOD;
538+
$embed .= handleYoutube($cid);
549539
break;
550540
}
551541
$description .= $embed;

bridges/SteamCommunityBridge.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,10 @@ private function collectMedia()
109109
$mediaURI = $media->getAttribute('src');
110110
$downloadURI = $mediaURI;
111111

112+
$content = '';
113+
112114
if ($category == 'videos') {
113-
preg_match('/.*\/embed\/(.*)\?/', $mediaURI, $result);
114-
$youtubeID = $result[1];
115-
$mediaURI = 'https://img.youtube.com/vi/' . $youtubeID . '/hqdefault.jpg';
116-
$downloadURI = 'https://www.youtube.com/watch?v=' . $youtubeID;
115+
$content = handleYoutube($mediaURI);
117116
}
118117

119118
$desc = '';
@@ -133,8 +132,12 @@ private function collectMedia()
133132
$downloadURI = $htmlCard->find('a.downloadImage', 0)->href;
134133
}
135134

136-
$item['content'] = '<p><a href="' . $downloadURI . '"><img src="' . $mediaURI . '"/></a></p>';
137-
$item['content'] .= '<p>' . $desc . '</p>';
135+
if (empty($content)) {
136+
$content = '<p><a href="' . $downloadURI . '"><img src="' . $mediaURI . '"/></a></p>';
137+
$content .= '<p>' . $desc . '</p>';
138+
}
139+
140+
$item['content'] = $content;
138141

139142
$this->items[] = $item;
140143

0 commit comments

Comments
 (0)