MG 1.1 Scan For Broken Youtube Videos

Jafo

Active member
I have a client who has a sizeable gallery that contains many youtube videos. Some of these videos are no longer available on youtube. Is there any way to scan/rebuild these and remove the broken ones?
 
Thanks.. There were hundreds here that were invalid as many of the videos had simply been deleted over the years. I wrote up a quick script that moderated any videos that could not be found on youtube. You may have to run it several times (or just make it a rebuild component) in case your server times out or run on the command line. I didn't have the time to make this any more rich. Make a backup of your xengallery_media table to be safe. In case anyone needs it in the future:


PHP:
<?php

$startTime = microtime(true);
$fileDir = dirname(__FILE__);

require($fileDir . '/library/XenForo/Autoloader.php');
XenForo_Autoloader::getInstance()->setupAutoloader($fileDir . '/library');

XenForo_Application::initialize($fileDir . '/library', $fileDir);
XenForo_Application::set('page_start_time', $startTime);

$dependencies = new XenForo_Dependencies_Public();
$dependencies->preLoadData();


$q = XenForo_Application::get('db')->fetchAll("
                SELECT * from xengallery_media where media_type = 'video_embed' and media_state = 'visible' and media_embed_url like '%youtube.com%'");

$x = 0;

foreach ($q as $v)
{
    $raw = parse_url($v['media_embed_url']);

    parse_str($raw['query'], $query);

    if (array_key_exists('v', $query))
    {
        $video_url = @file_get_contents('https://www.youtube.com/oembed?format=json&url=' . $v['media_embed_url']);

        if(!$video_url) {
                echo('video DOES NOT exist' . "<br />\n");

                $w = XenForo_Application::get('db')->query("UPDATE xengallery_media set media_state = 'moderated' where media_id = " . $v['media_id']);

                $x++;
        }
        else
        {
            echo "Does exist!<br />\n";
        }
    }
}

echo "<br /><br />Done and moderated $x videos";
 
Last edited:
That does make them moderated in the sense that they would be no longer visible to most users, but it won't actually add them to the moderation queue.

If the aim is to just hide them from view, you'd be better off just setting them to "deleted". If your aim is to have a queue you can refer back to in order to review each one to perhaps try and fix it manually or ultimately delete it, then you will need to add an entry into the xf_moderation_queue table as well.
 
Top Bottom