generated from discourse/discourse-plugin-skeleton
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.rb
106 lines (86 loc) · 2.11 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# frozen_string_literal: true
# name: discourse-chinese-onebox
# about: Add support for Chinese video sites embeds in Discourse
# version: 1.0.2
# authors: TreeNewBee
# url: https://github.com/TheTNB/discourse-chinese-onebox
# required_version: 2.7.0
require "onebox"
class Onebox::Engine::BilibiliOnebox
include Onebox::Engine
matches_regexp(/^https?:\/\/(?:www\.)?bilibili\.com\/video\/([A-Za-z0-9]+)\/?$/)
always_https
def video_id
return unless uri&.path
if (match = uri.path.match(/\/video\/av(\d+)(\.html)?.*/))
"aid=#{match[1]}"
elsif (match = uri.path.match(/\/video\/BV([A-Za-z0-9]+)(\.html)?.*/))
"bvid=#{match[1]}"
end
end
def to_html
<<-HTML
<iframe
src='https://player.bilibili.com/player.html?#{video_id}&p=1'
frameborder="0"
framespacing="0"
width='100%'
height='420'
allowfullscreen>
</iframe>
HTML
end
def placeholder_html
to_html
end
end
class Onebox::Engine::YoukuOnebox
include Onebox::Engine
matches_regexp(/^https?:\/\/v\.youku\.com\/v_show\/id_([A-Za-z0-9=]+)\.html/)
always_https
def video_id
return unless uri&.path
match = uri.path.match(/\/v_show\/id_([A-Za-z0-9=]+)\.html/)
match[1] if match
end
def to_html
<<-HTML
<iframe
src='https://player.youku.com/embed/#{video_id}'
frameborder="0"
framespacing="0"
width='100%'
height='420'
allowfullscreen>
</iframe>
HTML
end
def placeholder_html
to_html
end
end
class Onebox::Engine::TencentVideoOnebox
include Onebox::Engine
matches_regexp(/^https?:\/\/v\.qq\.com\/x\/page\/([A-Za-z0-9]+)\.html/)
always_https
def video_id
return unless uri&.path
match = uri.path.match(/\/x\/page\/([A-Za-z0-9]+)\.html/)
match[1] if match
end
def to_html
<<-HTML
<iframe
src='https://v.qq.com/txp/iframe/player.html?vid=#{video_id}'
frameborder="0"
framespacing="0"
width='100%'
height='420'
allowfullscreen>
</iframe>
HTML
end
def placeholder_html
to_html
end
end