MyBB Community Forums

Full Version: Bilibili Videos Embed
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I would like MyBB community to add this feature because YouTube and Facebook are blocked in China. I already did all the work so I'll post the steps here:

MyBB >= 1.8.21:

In 'jscripts/bbcodes_sceditor.js', add in 'mybbCmd' after 'Twitch' code section:

'Bilibili': {
'match': /https:\/\/www\.bilibili\.com\/video\/([^/]+)\/?/,
'url': '//player.bilibili.com/player.html?bvid=',
'html': '<iframe src="{url}" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true" ' +
' style="width: 640px; height: 430px; max-width: 100%" height="378" width="620" data-mybb-vt="{type}" data-mybb-vsrc="{src}"></iframe>'
}


In Admin CP add custom MyCode:

Title: Bilibili
Short Description: Bilibili videos
Regular Expression: \[video=bilibili\]https:\/\/www\.bilibili\.com\/video\/([^/]+)\/?\[\/video\]
Replacement: <iframe src="//player.bilibili.com/player.html?aid=$1&bvid=$1" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true" style="width: 640px; height: 430px; max-width: 100%"></iframe>

MyBB < 1.8.21:

1. Create template "video_bilibili_embed" with content:

<iframe src="//player.bilibili.com/player.html?aid={$id}" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true"  style="width: 640px; height: 430px; max-width: 100%"></iframe>

2. Edit "inc/class_parser.php", find the switch case for videos (search "twitch" for example) and add before the default:

case "bilibili":
	// https://www.bilibili.com/video/av34623787/
	$id = substr($path[2], 2);
	break;

3. Edit "inc/functions.php" and on the function "build_mycode_inserter", on the array "$editor_lang_strings", add the following:

"editor_insertbilibilivideo" => "Insert a Bilibili video",
"editor_enterbilibiliurl" => "Enter the Bilibli video URL:",
"editor_invalidbilibili" => "Invalid Bilibili video"

Note: I don't know where this is used and if there are more things necessary to edit.

4. Edit "jscripts/bbcodes_sceditor.js", find:

twitch: '<iframe src="{url}" frameborder="0" scrolling="no" height="378" width="620" data-mybb-vt="{type}" data-mybb-vsrc="{src}"></iframe>'

add below:

bilibili: '<iframe src="{url}" frameborder="0" scrolling="no" height="378" width="620" data-mybb-vt="{type}" data-mybb-vsrc="{src}"></iframe>'

find:

case 'twitch':
	matches = content.match(/twitch\.tv\/(?:[\w+_-]+)\/v\/(\d+)/);
	url     = matches ? '//player.twitch.tv/?video=v' + matches[1] : false;
	break;

add below:

case 'bilibili':
	matches = content.match(/bilibili\.com\/video\/av(\d+)($|\/)/);
	url     = matches ? '//player.bilibili.com/player.html?aid=' + matches[1] : false;
	break;

find:

'<option value="twitch">' + editor._('Twitch') + '</option>' +

add below:

'<option value="bilibili">' + editor._('Bilibili') + '</option>' +
Feel free to open a PR to discuss
(2018-11-27, 11:51 AM)MangaD Wrote: [ -> ]I would like MyBB community to add this feature because YouTube and Facebook are blocked in China. I already did all the work so I'll post the steps here:

1. Create template "video_bilibili_embed" with content:

<iframe src="//player.bilibili.com/player.html?aid={$id}" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true"  style="width: 640px; height: 430px; max-width: 100%"></iframe>

2. Edit "inc/class_parser.php", find the switch case for videos (search "twitch" for example) and add before the default:

case "bilibili":
	// https://www.bilibili.com/video/av34623787/
	$id = substr($path[2], 2);
	break;

3. Edit "inc/functions.php" and on the function "build_mycode_inserter", on the array "$editor_lang_strings", add the following:

"editor_insertbilibilivideo" => "Insert a Bilibili video",
"editor_enterbilibiliurl" => "Enter the Bilibli video URL:",
"editor_invalidbilibili" => "Invalid Bilibili video"

Note: I don't know where this is used and if there are more things necessary to edit.

4. Edit "jscripts/bbcodes_sceditor.js", find:

twitch: '<iframe src="{url}" frameborder="0" scrolling="no" height="378" width="620" data-mybb-vt="{type}" data-mybb-vsrc="{src}"></iframe>'

add below:

bilibili: '<iframe src="{url}" frameborder="0" scrolling="no" height="378" width="620" data-mybb-vt="{type}" data-mybb-vsrc="{src}"></iframe>'

find:

case 'twitch':
	matches = content.match(/twitch\.tv\/(?:[\w+_-]+)\/v\/(\d+)/);
	url     = matches ? '//player.twitch.tv/?video=v' + matches[1] : false;
	break;

add below:

case 'bilibili':
	matches = content.match(/bilibili\.com\/video\/av(\d+)($|\/)/);
	url     = matches ? '//player.bilibili.com/player.html?aid=' + matches[1] : false;
	break;

find:

'<option value="twitch">' + editor._('Twitch') + '</option>' +

add below:

'<option value="bilibili">' + editor._('Bilibili') + '</option>' +

You can create a plugin for this. 

If you are not that comfortable doing this, then maybe someone else can make a plugin.
(2019-06-13, 07:29 AM)Serpius Wrote: [ -> ]You can create a plugin for this. 

If you are not that comfortable doing this, then maybe someone else can make a plugin.
A plugin which will modify bbcodes_sceditor.js ? Really bad idea imho
(2019-06-13, 07:53 AM)Crazycat Wrote: [ -> ]
(2019-06-13, 07:29 AM)Serpius Wrote: [ -> ]You can create a plugin for this. 

If you are not that comfortable doing this, then maybe someone else can make a plugin.
A plugin which will modify bbcodes_sceditor.js ? Really bad idea imho

I don't know if that is a good idea or not. I am making suggestions. That's all. 

F.Y.I., I am not a coder or programmer, so I don't know if something is good or not. 

Making suggestions is not a bad idea.
I agree, suggestions are always welcome Smile

btw, making a plugin or a dedicated MyCode is a good idea, the only trouble is to add it in the video selector. I didn't look at the 1.8.21editor configuration, peharps is it now possible to extend it without changing it core files.
Guys. I also don't know if it is possible for a plugin to modify the editor but....

... why can't this be an official feature?

MyBB already has 6 video sources, some I've never even heard about. What is the harm in one more that is heavily used in China? All the work is done, it is just a matter of adding it to the MyBB official files. Although I don't know about the 1.8.21 upgrade and if it will require different coding. I'll look into it when I upgrade my forum.
(2019-06-13, 11:41 AM)MangaD Wrote: [ -> ]Guys. I also don't know if it is possible for a plugin to modify the editor but....

... why can't this be an official feature?

MyBB already has 6 video sources, some I've never even heard about. What is the harm in one more that is heavily used in China? All the work is done, it is just a matter of adding it to the MyBB official files. Although I don't know about the 1.8.21 upgrade and if it will require different coding. I'll look into it when I upgrade my forum.

I'm not in the developer team, but I can see 2 reasons:
1/ it's not possible to integrate all the video providers, choice have to be made
2/ developers seems to have a lot of work, finding time to add this could be hard.

And to propose this change, do not publish it here but in a github fork and made a pull request

I'll made tries to see if it's possible to extend the editor without modifying its core files.
(2019-06-13, 11:41 AM)MangaD Wrote: [ -> ]Guys. I also don't know if it is possible for a plugin to modify the editor but....

... why can't this be an official feature?

MyBB already has 6 video sources, some I've never even heard about. What is the harm in one more that is heavily used in China? All the work is done, it is just a matter of adding it to the MyBB official files. Although I don't know about the 1.8.21 upgrade and if it will require different coding. I'll look into it when I upgrade my forum.

Well, as I understand it, if it's a new feature, that won't be added in until MyBB 1.9.xx series. 

They are not doing any new major features for the 1.8.xx series.

That's why I was suggesting a plugin for now.

Who knows how long it will be added to the 1.9.xx series.  Huh

So, why not a plugin for the 1.8.xx series now?
Regarding not adding any new features to 1.8: that applies to big features. Adding a video provider is not a big feature at all and in past 1.8 releases we have made changes to video providers.
Pages: 1 2