[nodebb-plugin-youtube] Youtube Embed Plugin

NodeBB Plugins
  • Ok, I'm officially at a loss with this... Not only is it mangling the iFrame, it's changing the video ID into all lower case, so the videos don't actually work.

    I don't understand how it goes from

    $el.on('click', function (e) {
            if (!$el.hasClass('lazyYT-video-loaded') && $el.hasClass('lazyYT-image-loaded')) {
                $el.html('<iframe width="' + width + '" height="' + height + '" src="//www.youtube.com/embed/"' + id + '?autoplay=1&' + youtubeParameters + '"></iframe>')

    To being output as

    <iframe width="640" height="360" yuobzwf0aws?autoplay="1&amp;&quot;" src="//www.youtube.com/embed/"></iframe>

    Sense, it doesn't make it.

  • Got it working. Seems to be something to do with the height and width of the iFrame. πŸ˜• Will do some more testing, then probably release on npm. πŸ˜‰

  • How reduce size of video?

  • @Master-Antonio, try @a_5mith's Youtube-Lite plugin. It may be more suited to your needs if the video is appearing to large.

  • I have the RSS Feed poster plugin and the feeds posts YouTube videos in iFrames instead of just a standard URL.

    Example: <iframe width="560" height="315" src="https://www.youtube.com/embed/vzNErWJWxTo" frameborder="0" allowFullScreen=""></iframe>

    How would I modify this YouTube plugin work with posts that contain YouTube videos in an iFrame tag?

  • @Hero Ah seems like the REGEX is detecting the link in the rss feed. I will look into this now, and maybe also @psychobunny

    Also @Hero could you test with this plugin also https://github.com/a5mith/nodebb-plugin-youtube-lite

  • @xCausxn

    I actually was trying it with the Youtube-Lite plugin but was unable to find the thread on here. I've tried modified the REGEX expressions in library.js to detect the iFrame tags but no luck.

  • @Hero the iframes are added by the plugin, to make the youtube embed, and as the youtube plugin checks the postcontent for youtube links this is why it is added.

    @psychobunny @a_5mith would be able to help more, as ive only just started making nodebb plugins πŸ˜›

  • @xCausxn said:

    @Hero the iframes are added by the plugin, to make the youtube embed, and as the youtube plugin checks the postcontent for youtube links this is why it is added.

    Thanks for the reply. The RSS feed already includes the iframe/embed code so for some reason the YouTube plugin doesn't parse it. The result of the RSS post including a YouTube video is the actual embed code itself. The only way I've been able to get around it is by allowing HTML on all posts which isn't the safest thing πŸ˜‰

  • So the youtube links are iframe from the rss, hmm ok. If i may ask could you PM me the rss feed url if its not private πŸ˜› ?

  • Will take a look when I get home. Entirely possible to just strip the iframe tags then put them back in. Or whatever the desired output is. You could have a play with regexr to fast check your regex.

  • @a_5mith That's what I thought too but I guess my RegEx was off. I created..

    var iframeUrl and enter the regex expression

    I also copied the post code from embedUrl and replaced all occurnces of embedUrl with iframeUrl.

    The standard youtube links still embedded fine with the plugin but the ones from RSS feeds that already contain the iframe source didn't work. I'm thinking my regex was wrong.

  • @Hero Not seeing any iFrames in that rss feed, or youtube URLs, not just me being blind is it?

    If I can get the actual code for it, I can create a regex to strip it out, but I don't know if they use youtu.be or youtube.com/watch? for their iFrames, so it'd be a bit of a guess. Do you have a page I can look at with the code already on?

  • @a_5mith

    Here is the iFrame that is embedded in the RSS feed.

    <iframe width="560" height="315" src="https://www.youtube.com/embed/vzNErWJWxTo" frameborder="0" allowFullScreen=""></iframe>

  • Ok, give me 20 minutes or so and I'll send you an adjusted library.js you can use.

  • Thanks @a_5mith πŸ˜„

  • I'm missing the full screen button...... what's the hack?

  • You would add allowfullscreen to your iFrame code, alternatively, use the youtube-lite plugin for lazy loading and other niceties. It's the plugin that's used here. πŸ‘

  • @Hero sorry for the delay.

    Here is the updated library.js file you'll need. It will extract the youtube ID from the iFrame, and place it into the lazy load iFrame code instead so will work the same way.

    (function(module) {
    	"use strict";
    	var YoutubeLite = {},
    		embed = '<div class="js-lazyYT" data-youtube-id="$1" data-width="640" data-height="360"><iframe class="lazytube" src="//www.youtube.com/embed/$1"></iframe></div>';
    	var	regularUrl = /<a href="(?:https?:\/\/)?(?:www\.)?(?:youtube\.com)\/(?:watch\?v=)(.+)">.+<\/a>/g;
            var	shortUrl = /<a href="(?:https?:\/\/)?(?:www\.)?(?:youtu\.be)\/(.+)">.+<\/a>/g;
            var	embedUrl = /<a href="(?:https?:\/\/)?(?:www\.)youtube.com\/embed\/([\w\-_]+)">.+<\/a>/;
    		var iFrameUrl = /<iframe width="560" height=""315" src\=\"(?:https?:\/\/)?(?:www\.)youtube.com\/embed\/([\w\-_]+)" frameborder="0" allowFullScreen=""><\/iframe>/g;
        YoutubeLite.parse = function(data, callback) {
            if (!data || !data.postData || !data.postData.content) {
                return callback(null, data);
            if (data.postData.content.match(embedUrl)) {
                data.postData.content = data.postData.content.replace(embedUrl, embed);
            if (data.postData.content.match(regularUrl)) {
                data.postData.content = data.postData.content.replace(regularUrl, embed);
            if (data.postData.content.match(shortUrl)) {
                data.postData.content = data.postData.content.replace(shortUrl, embed);
    		if (data.PostData.content.match(iFrameUrl)) {
    			data.postData.content = data.PostData.content.replace(iFrameUrl, embed);
            callback(null, data);
    	module.exports = YoutubeLite;

Suggested Topics

  • 0 Votes
    1 Posts
  • Patreon plugin

    NodeBB Plugins
    0 Votes
    1 Posts
  • 1 Votes
    4 Posts
  • 6 Votes
    13 Posts
  • 4 Votes
    1 Posts