Related Topics


[Video CMS v4]Automatically unpublish videos when removed from YouTube  (Read 680 times) Print

1 B


Hersh  July 30, 2015, 04:38:57 AM

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:
Code
    foreach ($videos as $video) {

AFTER, add this:
Code
        $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:
Code
if ($result) {
    foreach ($result as $related) {

AFTER, add:
Code
        $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:
Code
unpublish_video(****);
to
Code
delete_video(****);

Logged


theprocss  August 06, 2015, 05:24:39 AM

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.

Logged


lucaphuoc  August 06, 2015, 09:50:18 AM

Yes, i'm too. I hope you fix soon.

Logged


Hersh  August 08, 2015, 02:33:14 AM

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.

Logged


theprocss  August 08, 2015, 05:50:43 AM

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?

Logged


leen12  September 02, 2015, 07:08:53 PM

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

Logged
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  September 04, 2015, 12:27:24 AM

How can I enable caching for Logged in users?

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.

Logged