-
Notifications
You must be signed in to change notification settings - Fork 4
/
plugin.rb
45 lines (37 loc) · 1.03 KB
/
plugin.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# name: discourse-onebox-bilibili
# about: 为 Discourse Onebox 增加了 bilibili 视频支持
# version: 0.0.2
# authors: MuZhou233
# url: https://github.com/MuZhou233/discourse-onebox-bilibili
require_relative "../../lib/onebox"
Onebox = Onebox
class Onebox::Engine::BilibiliOnebox
include Onebox::Engine
matches_regexp(/^https?:\/\/(?:www\.)?bilibili\.com\/video\/([a-zA-Z0-9]+)\/?$/)
always_https
def video_id
match = uri.path.match(/\/video\/av(\d+)(\.html)?.*/)
return "aid=#{match[1]}" if match && match[1]
match = uri.path.match(/\/video\/BV([a-zA-Z0-9]+)(\.html)?.*/)
return "bvid=#{match[1]}" if match && match[1]
nil
rescue
return nil
end
def to_html
<<-HTML
<iframe
src='https://player.bilibili.com/player.html?#{video_id}&page=1'
scrolling="no"
border="0"
frameborder="no"
framespacing="0"
width='640'
height='430'
allowfullscreen='true'></iframe>
HTML
end
def placeholder_html
to_html
end
end