[nodebb-plugin-youtube] Youtube Embed Plugin
-
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) { e.preventDefault(); 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>') .removeClass('lazyYT-image-loaded') .addClass('lazyYT-video-loaded'); } });
To being output as
<iframe width="640" height="360" yuobzwf0aws?autoplay="1&"" src="//www.youtube.com/embed/"></iframe>
Sense, it doesn't make it.
-
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
-
@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
-
-
@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?
-
@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; }(module));