Tutorials / The automatic import explained

Importing YouTube videos automatically from a given source (YouTube channel, playlist or user uploads) is an easy task with WordPress YouTube Hub. For more details on how to create automatically importing playlists please see Automatic video import.

Setting up the import options

The first step that you should take before starting your automatic importing is to set the import options. These options can be found in plugin Settings page, tab Import options.

The import frequency

The import frequency (named Automatic import in options) determines how many videos will be imported at once and how often. You can select to import from 1 up to 50 videos every 1 minute up to 24 hours.

The selection made here will dictate how much stress you will put on your system. Basically, when a new video is imported as a WordPress post, the plugin will ask WordPress to do the following, in this particular order:

  1. Insert the post details into the database;
  2. Import the featured image from YouTube (which is quite resource consuming) into your website Media Gallery and assign the featured image to this new post. This means that WordPress will actually create the image and then insert the details into the database;
  3. create a new WordPress category and assign the newly created post to it;
  4. create the YouTube tags that should be imported and assign them to the new post.
    1. The process is pretty intensive so you should test different settings for frequency and number of videos until you find the optimal combination.

      Enabling conditional imports

      Before explaining this feature you must understand how the automatic import process works. Basically, this process is triggered by your website visitors. This means that when the timer expires, the plugin will wait for the first visitor that visits your website and it will trigger the import.

      For example, if you set automatic imports to happen every 5 minutes, after 5 minutes have passed, the first visitor that sees your website will trigger the import. Once this happens, the plugin will import the videos it has in queue and will wait for another 5 minutes. After the next 5 minutes have passed, it will repeat the process.

      As you have probably noticed, this is somehow unreliable because there’s no guarantee that your website will receive a visitor every 5 minutes so you won’t reach the optimal import frequency unless you own a high traffic website.
      Even on a high traffic website there can be problems, like duplicated videos caused by concurrent imports that can happen when two or more visitors visit your website at the same time and trigger the automatic import process.

      To solve both issues mentioned above you can use conditional importing. When this feature is enabled, automatic imports will be made only if, at the given time interval, a hit is received on a certain link on your website (you will see the link after you enable this option). This link can be used to set a cron job on your server that will open your website every X minutes and will ensure that automatic import will run consistently. Besides this, it also eliminates concurrent imports because the hit will be received only once.

      Legacy automatic import

      When doing automatic imports that are triggered by your website visitors, once the timer is expired and an import can be made, the plugin will use WordPress’s shutdown action to import the videos in queue. Until all importing is done, the page will show as loading in your visitor’s browser, which can be a bit frustrating for them, especially if you’re importing large quantities of videos.

      To eliminate this, we implemented a different functionality. When videos must be imported, the plugin will make a remote call to your website, having some variables set on the link that will trigger the import. The maximum execution time of this remote call is 1 second, which means that your page won’t be displayed as loading for long and the plugin will do all its work in background. This is the default functionality of the plugin but if you experience problems, you can go back to the old way of functioning by enabling this option.

      Conclusion

      To conclude all this, always set the number of videos imported at once at a realistic number, tuned with your server performance. Don’t go straight for 50 videos every minute; try to find the numbers that work for you. If you don’t know how to do this, go for maximum 10-15 videos every 5 minutes, it should work on most websites.

      For better performance, choose conditional importing and use server cron job to trigger the imports. While this is an advanced feature since not everyone knows how to set a cron job, you can always ask your hosting provider for help or search for information on the internet.