diff --git a/src/main/frontend/components/block.cljs b/src/main/frontend/components/block.cljs index 172a5e282..82376bc78 100644 --- a/src/main/frontend/components/block.cljs +++ b/src/main/frontend/components/block.cljs @@ -1153,10 +1153,7 @@ (defn- macro-video-cp [_config arguments] (when-let [url (first arguments)] - (let [width (min (- (util/get-width) 96) - 560) - height (int (* width (/ 315 560))) - results (text-util/get-matched-video url) + (let [results (text-util/get-matched-video url) src (match results [_ _ _ (:or "youtube.com" "youtu.be" "y2u.be") _ id _] (if (= (count id) 11) ["youtube-player" id] url) @@ -1170,8 +1167,10 @@ [_ _ _ (_ :guard #(string/ends-with? % "vimeo.com")) _ id _] (str "https://player.vimeo.com/video/" id) - [_ _ _ "bilibili.com" _ id _] - (str "https://player.bilibili.com/player.html?bvid=" id "&high_quality=1") + [_ _ _ "bilibili.com" _ id & query] + (str "https://player.bilibili.com/player.html?bvid=" id "&high_quality=1" + (when-let [page (second query)] + (str "&page=" page))) :else url)] @@ -1179,16 +1178,20 @@ (= (first src) "youtube-player")) (youtube/youtube-video (last src)) (when src - [:iframe - {:allowfullscreen true - :allow "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope" - :framespacing "0" - :frameborder "no" - :border "0" - :scrolling "no" - :src src - :width width - :height height}]))))) + (let [width (min (- (util/get-width) 96) 560) + height (int (* width (/ (if (string/includes? src "player.bilibili.com") + 360 315) + 560)))] + [:iframe + {:allow-full-screen true + :allow "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope" + :framespacing "0" + :frame-border "no" + :border "0" + :scrolling "no" + :src src + :width width + :height height}])))))) (defn- macro-else-cp [name config arguments] diff --git a/src/main/frontend/util/text.cljs b/src/main/frontend/util/text.cljs index 7abe25945..e27bfb705 100644 --- a/src/main/frontend/util/text.cljs +++ b/src/main/frontend/util/text.cljs @@ -5,7 +5,7 @@ (defonce between-re #"\(between ([^\)]+)\)") -(def bilibili-regex #"^((?:https?:)?//)?((?:www).)?((?:bilibili.com))(/(?:video/)?)([\w-]+)(\S+)?$") +(def bilibili-regex #"^((?:https?:)?//)?((?:www).)?((?:bilibili.com))(/(?:video/)?)([\w-]+)(\?p=(\d+))?(\S+)?$") (def loom-regex #"^((?:https?:)?//)?((?:www).)?((?:loom.com))(/(?:share/|embed/))([\w-]+)(\S+)?$") (def vimeo-regex #"^((?:https?:)?//)?((?:www).)?((?:player.vimeo.com|vimeo.com))(/(?:video/)?)([\w-]+)(\S+)?$") (def youtube-regex #"^((?:https?:)?//)?((?:www|m).)?((?:youtube.com|youtu.be|y2u.be|youtube-nocookie.com))(/(?:[\w-]+\?v=|embed/|v/)?)([\w-]+)([\S^\?]+)?$")