Embedding a list of your YouTube videos into your website

Posted February 16th, 2009 by Maarten

I recently found out it's quite easy to create a page on your website showing your own YouTube videos, which automatically displays new videos as you add them (provided you have basic knowledge of PHP). My YouTube page is right here on my website. You could create the same page as follows:

  • Download an RSS parser for PHP. I used Magpie RSS: http://magpierss.sourceforge.net/. Read their documentation to set up the parser. Amongst other things, a writable cache folder is needed.
  • Create a PHP file which will generate the list.
  • Optionally, create a PHP file which will display a YouTube video player.

Files with the PHP code can be found at the bottom of this page. To view them on screen right away, click the images below. I am sure this code can be greatly improved, but at the moment this is working just fine for me.

Code for the list page:
PHP code for YouTube video list

Code for the player page:
PHP code for YouTube video player

Note I added the fmt%3D22 suffix to the parameters for the embedded player, this will show videos in HD if possible. Warning: the videos will not load if this suffix is added while the quality is actually lower. Use fmt%3D18 for high quality and stereo sound, or no suffix if the quality is even lower than that. Be sure to take a look at the div tags and replace their style (including size) attributes to create a look which suits your website, or add the CSS style to your CSS file.

Be aware that the RSS file doesn't get updated every few minutes, but within an interval of a couple of hours. This means newly uploaded videos on YouTube will not be visible immediately.

AttachmentSize
video_list.php.txt1.14 KB
video_player.php.txt655 bytes