fix bilibili embed issues

1. fix #5820
2. fix #5811
pull/5849/head
llcc 2022-06-25 11:31:04 +08:00 committed by Tienson Qin
parent ca52df97bc
commit 292bda9f8b
2 changed files with 20 additions and 17 deletions

View File

@ -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]

View File

@ -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^\?]+)?$")