Re-Download Thumbs and Posters?
#1
I just moved my libarary from one server to another, updated my xbmc_video.path table so I wouldn't lose any of my settings however now I don't have thumbnails for anything. My question is how can I force the redownload of all the thumbnails and show posters?

My setup is:
- MySQL for my lib - 192.168.0.11
- All files are shared by Win 7 - was smb://Master-Chief/ now is smb://Mario/
- I watch on 2 Win 7 x64 computers and 1 Mac running 10.6 - 0.11, 0.12, 0.13

I also have a issue where if a file is discovered on one computers it won't have a poster or thumb on any other. I know I can share the XBMC dir however since I have a Mac client I don't think that will work to well.

My question is how can I for XBMC to redownload all or all missing posters and thumbs? I know the URL for them is stored in the DB. I made a request for a plugin a few weeks ago however it's something I need now since I moved my file server it lost all the thumbs/posters and I have 2,465 files with about 75% played.

I'm running XBMCSetup-20110810-d6e73b8-master on all systems
Reply
#2
Thanks to wishie on IRC for helping my not run into this issue in the furture.

In C:\Users\.....\AppData\Roaming\XBMC\userdata\advancedsettings.xml
Code:
<advancedsettings>
    <pathsubstitution>
        <substitute>
            <from>special://masterprofile/Thumbnails/</from>
            <to>smb://user:pass@server/XBMC/userdata/Thumbnails/</to>
        </substitute>
    </pathsubstitution>
</advancedsettings>

He also said that the Thumbnails/Video/x/xxxxxx.tbn was a CRC of the path, using that I made a little php script for windows, if your one mac or linux be sure to use / for paths instead of \\
Code:
<?php
// Scotepi

// -------- Change This! ------------------------
$link = mysql_connect('192.168.0.11', 'xbmc', 'xbmc');
mysql_select_db('xbmc_video');
$pathToThumbs = "Thumbnails\\Video\\";
$pathToFanart = "Thumbnails\\Video\\Fanart\\";
$oldServer = "master-chief";
$newServer = "mario";
// ----------------------------------------------

$query = "SELECT strPath,strFilename
FROM path AS p
LEFT JOIN files AS f USING(idPath)
WHERE strFilename IS NOT NULL
AND NOT strFilename = ''";
$result = mysql_query($query);

while ( $row = mysql_fetch_assoc($result) ) {
    $newFile = strtolower($row['strPath'].$row['strFilename']);
    $newHash = thumbnailHash($newFile);
    $newThumb = $pathToThumbs.$newHash{0}."\\".$newHash.'.tbn';
    
    $oldFile = str_replace($newServer, $oldServer, $newFile);
    $oldHash = thumbnailHash($oldFile);
    $oldThumb = $pathToThumbs.$oldHash{0}.'\\'.$oldHash.'.tbn';
    
//    var_dump($oldFile,$oldHash,$oldThumb,$newFile,$newHash,$newThumb,is_file($oldThumb),is_file($newThumb));echo "<br>";
    
    echo "Looking for {$row['strFilename']}.. ";
    if ( is_file($oldThumb) ) {
        if ( !is_file($newThumb) ) {
            echo "woot :).. ";
            rename($oldThumb, $newThumb);
            echo " Done<br>\n";
        } else {
            echo " already have it :?<br>\n";
        }
    } else {
        echo " nope :(<br>\n";
    }
}

echo "\n<br>\n All Done..";

// Lets take care of Fanart and show thumbnails
$query = "SELECT c00,c16 FROM `tvshow`"; # Really devs?
$result = mysql_query($query);

while ( $row = mysql_fetch_assoc($result) ) {
    $newPath = strtolower($row['c16']);
    $newHash = thumbnailHash($newPath);
    $newThumb = $pathToThumbs.$newHash{0}."\\".$newHash.'.tbn';
    $newArt = $pathToFanart.$newHash.'.tbn';
    
    $oldPath = str_replace($newServer, $oldServer, $newPath);
    $oldHash = thumbnailHash($oldPath);
    $oldThumb = $pathToThumbs.$oldHash{0}."\\".$oldHash.'.tbn';
    $oldArt = $pathToFanart.$oldHash.'.tbn';
    
//    var_dump($row['c00'],$oldPath,$oldHash,$oldThumb,$oldArt,$newPath,$newHash,$newThumb,$newArt,is_file($oldThumb),is_file($newThumb),is_file($oldArt),is_file($newArt)); echo "<br>";
    
    if ( is_file($oldThumb) and !is_file($newThumb) ) {
        echo "Moving thumb for {$row['c00']}.";
        rename($oldThumb, $newThumb);
        echo ".<br>\n";
    }
    
    if ( is_file($oldArt) and !is_file($newArt) ) {
        echo "Moving art for {$row['c00']}.";
        rename($oldArt, $newArt);
        echo ".<br>\n";
    }
}


// Thanks to wishie - https://github.com/wishie/XBMC-MySQL-Web-Interface/blob/master/medialists/index.php
function thumbnailHash($input) {
    $chars = strtolower($input);
    $crc = 0xffffffff;
    for ($ptr = 0; $ptr < strlen($chars); $ptr++) {
            $chr = ord($chars[$ptr]);
            $crc ^= $chr << 24;
            for ($i=0; $i<8; $i++){
                    if ($crc & 0x80000000) {
                            $crc = ($crc << 1) ^ 0x04C11DB7;
                    } else {
                            $crc <<= 1;
                    }
            }
    }
    //Formatting the output in a 8 character hex
    if ($crc>=0){
            //positive results will hash properly without any issues
            return sprintf("%08s",sprintf("%x",sprintf("%u",$crc)));
    } else {
            /*
             * negative values will need to be properly converted to
             * unsigned integers before the value can be determined.
             */
            //return sprintf("%08s",gmp_strval(gmp_init(sprintf("%u",$crc)),16));
            
            // moded to remove gmp - scotepi
            return sprintf("%08s",base_convert(sprintf("%u",$crc),10,16));
    }
}

This will require a lot of editing depending on your setup. I lost my thumbs because I move from files from 1 server to another and updated my DB to reflect that. All I had to do was move the thumbnails from the crc of the old path to the new path. The old path as smb://master-chief/ and the new path is smb://mario/ as you can see by the str_replace on $oldPath
Reply
#3
Hi,

How to run this script ?
Reply
#4
I wouldn't really recommend it if you don't know php. it's vary incomplete, i posted it primarily as a base for people with a similar issue or if someone wanted to write a whole system for it.

In a few months I'm going to be moving my shares again and may revisit this and make it a proper script that would also change the paths in the DB.
Reply

Logout Mark Read Team Forum Stats Members Help
Re-Download Thumbs and Posters?0