diff --git a/src/Parsers/BBCode/Tags/VideoTag.php b/src/Parsers/BBCode/Tags/VideoTag.php
index 5f39a584..6e8b538c 100644
--- a/src/Parsers/BBCode/Tags/VideoTag.php
+++ b/src/Parsers/BBCode/Tags/VideoTag.php
@@ -5,9 +5,11 @@ use Misuzu\Parsers\BBCode\BBCodeTag;
final class VideoTag extends BBCodeTag
{
- private const YOUTUBE_URL_REGEX = '#^(?:www\.)?youtube(?:-nocookie)?\.(?:[a-z]{2,63})$#u';
+ private const YOUTUBE_REGEX = '#^(?:www\.)?youtube(?:-nocookie)?\.(?:[a-z]{2,63})$#u';
private const YOUTUBE_EMBED = '';
+ private const NICODOUGA_EMBED = '';
+
public function parseText(string $text): string
{
return preg_replace_callback(
@@ -27,7 +29,7 @@ final class VideoTag extends BBCodeTag
return sprintf(self::YOUTUBE_EMBED, $url['path']);
}
- if (!empty($url['query']) && ($url['path'] ?? '') === '/watch' && preg_match(self::YOUTUBE_URL_REGEX, $url['host'])) {
+ if (!empty($url['query']) && ($url['path'] ?? '') === '/watch' && preg_match(self::YOUTUBE_REGEX, $url['host'])) {
parse_str(html_entity_decode($url['query']), $ytQuery);
if (!empty($ytQuery['v']) && preg_match('#^([a-zA-Z0-9_-]+)$#u', $ytQuery['v'])) {
@@ -35,6 +37,14 @@ final class VideoTag extends BBCodeTag
}
}
+ if ($url['host'] === 'nicovideo.jp' || $url['host'] === 'www.nicovideo.jp') {
+ $splitPath = explode('/', trim($url['path'], '/'));
+
+ if (count($splitPath) > 1 && $splitPath[0] === 'watch') {
+ return sprintf(self::NICODOUGA_EMBED, $splitPath[1]);
+ }
+ }
+
$mediaUrl = url_proxy_media($matches[1]);
return sprintf('', $mediaUrl);
},