https://codeburst.io/how-to-embed-multiple-youtube-videos-on-your-website-a78a6ddfad95
Photo by Rachit Tank on Unsplash
While working on my Django-made website, I realized that it would make a lot of sense to pair it with my YouTube channel so as to grow the two platforms simultaneously. This process was quite a learning experience for me so I thought I’d write an article to help share what I’ve learnt along the way.
One of the main reasons for joining both my website and YouTube account was that this offered the potential for me to increase the size of my audience (when you add YouTube videos to a website there is a high chance that you will be able to reach a wider audience using your website). Another upshot of doing this is that having a personal website increases your credibility so it is one of the best ways to grow on the YouTube platform. It seemed like a perfect marriage to me: YouTube could bring new visitors to my website, and my website would direct some visitors to my YouTube channel.
This article will also guide you through arranging YouTube videos into a Grid view (thanks to materializecss). An added bonus here is that this program will update and organize the videos automatically on your website whenever you post a new one, meaning that you won’t have to look back at the code again.
First, let’s have a look at how to add a specific video.
Screenshot from my upcoming website
For specific videos, you just need the YouTube video ID, which you can get from the URL and paste it in the code below. For example- https://youtu.be/xQsTLQevgdI for this URL video ID is xQsTLQevgdI.
For specific videos
The above code will display your YouTube video wherever you want it to appear on the site. You can experiment with CSS to display it according to your website design. I recommend using materializecss because it makes the job much easier.
Screenshot of grid view from my upcoming website
If you want all of your videos, or a certain number of videos, to be displayed on your website then you can use a grid view. I have implemented this on my Django website, but the same code can be modified to work with any other framework. To implement this correctly, you need to retrieve the JSON data for your YouTube videos, to do this you can use an API called rss2json. Just open the website, paste your YouTube channel URL in the field, press ‘convert to JSON’ button, and you will find an API call like this one:
This will allow us to get all of the data that we need to upload the video and get info about the video such as title, release date, URL, etc.
Please note: You only need to carry out the following step if you’re using Django, otherwise you can skip this step.
put this code in views.py file if you are using Django