[ Video Sharing CMS v4 ] Automatically unpublish videos when removed from YouTube

Started by Hersh,

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

HershTopic starter

This can probably done by sending an API query to YouTube to check if a video has been removed or not but that would probably use up your API call quota. Here is my solution for this problem. I recently discovered that thousands of videos on my site had suddenly been removed by YouTube. So rather than going around and unpublishing videos manually, I added a simple conditional to video-carousel.php, video-loop.php and related.php to check these videos during load.

In video-carousel.php and video-loop.php, find:
    foreach ($videos as $video) {


AFTER, add this:
        $md5image1 = md5_file(thumb_fix($video->thumb, true, get_option('thumb-width'), get_option('thumb-height')));
        $md5image2 = md5_file('http://i4.ytimg.com/vi/0/0.jpg');
        if ($md5image1 == $md5image2) {
            unpublish_video($video->id);
        }


In related.php, find:
if ($result) {
    foreach ($result as $related) {


AFTER, add:
        $md5image1 = md5_file(thumb_fix($related->thumb, true, 120, 90));
        $md5image2 = md5_file('http://i4.ytimg.com/vi/0/0.jpg');
        if ($md5image1 == $md5image2) {
            unpublish_video($related->vid);
        }


Once you do this, videos will automatically be pushed to "unpublished" status. If you want to permanently delete the videos rather than unpublishing them, you can change the function:
unpublish_video(****);

to
delete_video(****);
  •  

theprocss

I did it but I had 3 problems

the site takes 10x longer to open.
More CPU consumption.
And Only work in some videos.

I must have about 300 videos not working.
and that unpublished only 20 or 30 videos.
  •  

lucaphuoc

  •  

HershTopic starter

Quote from: theprocss on
I did it but I had 3 problems

the site takes 10x longer to open.
More CPU consumption.
And Only work in some videos.

I must have about 300 videos not working.
and that unpublished only 20 or 30 videos.

As I described in a previous post, this is memory and cpu intensive. The reason why it takes a while to load a page is because you are logged in and caching is disabled for logged in users. When caching is enabled, there is almost no impact on performance.

That said, a better alternative is probably to run a cron job rather than checking on page load. But this will mean that the cron will have to go through all of the videos you have in order to determine which of them need to be unpublished,

Another alternative would require adding a database entry with a time stamp and checking for the last time it was checked before performing the comparison. This should significantly reduce the load time issue.
  •  

theprocss

This will be great

"That said, a better alternative is probably to run a cron job rather than checking on page load. But this will mean that the cron will have to go through all of the videos you have in order to determine which of them need to be unpublished"

you know how I do it?
  •  

leen12

nice thanks for the tutorial. would be better if we didnt have to load every video basically though. i have 143k videos removed 10k so far and still loads to go
http://hip-hop99.com best hip hop music website
http://social-nuke.com free facebook likes and shares
https://wppluginscheap.com Wordpress plugins and themes cheap
  •  

Martin

How can I enable caching for Logged in users?

Quote from: Hersh on
As I described in a previous post, this is memory and cpu intensive. The reason why it takes a while to load a page is because you are logged in and caching is disabled for logged in users. When caching is enabled, there is almost no impact on performance.

That said, a better alternative is probably to run a cron job rather than checking on page load. But this will mean that the cron will have to go through all of the videos you have in order to determine which of them need to be unpublished,

Another alternative would require adding a database entry with a time stamp and checking for the last time it was checked before performing the comparison. This should significantly reduce the load time issue.

Similar topics (7)