Retrieving folder.jpg thumbnails: PHP Script

When using XBMC we usually use the ‘Files’ menu. The folder icons under ‘Files’ do not show a preview thumbnail unless there is an image in the folder named ‘folder.jpg’. I could manually search for folder images for each movie but decided that would be time-consuming so I put together a wee PHP script – getMovieThumbs.php – to retrieve the image from and save it into the appropriate directory as folder.jpg

Running this script saved over 230 new thumbnail images for me in one folder alone.

php get folder.jpg for xbmc

$directories = glob('*' , GLOB_ONLYDIR);
$arrStripFrom=array("19", "20","1080p","720p","1080","720","DTS","HDTV","RETAIL","LIMITED","BDRip","BRip","WebDL","Widescreen","XVid","PROPER","X264","Xvid","AVI","Unrated","REPACK","S01","HD","TS", "LIMITED","DVD");
function my_strpos($haystack, $needle) {
if (is_array($needle)) {
foreach ($needle as $need) {
if (strpos($haystack, $need) !== false) {
return strpos($haystack, $need);
return false;

foreach($directories as $directory){
$img = $directory_unmodified.'/folder.jpg';
if (file_exists($img)){
printf("folder.jpg already exists - skipping ".$directory_unmodified."...\n");

$symbols = array(".", "-", "_","[","]","(",")");
$directory = str_replace($symbols, " ", $directory);
// Check the string to see if there is a year that can be added to the search to improve accuracy

if(preg_match("/[1,2][9,0][0-9][0-9]/", $directory_unmodified, $matches)==true){

$pos = my_strpos($directory, $arrStripFrom);
printf("\n-----------".$DirectoryToCheck."/".$directory_unmodified."------------------------------- \n");
if ($pos !== false) {
$directory=substr($directory, 0, $pos-1);
printf("Checking ".$directory." .... \n");
$jsonurl = "".$strSearchYear."i=&s=".$directory;
echo $jsonurl;
$json = file_get_contents($jsonurl,0,null,null);
$json_output = json_decode($json, true);
printf("\nNo Results found .. move on\n");
$jsontitleurl = "".$json_output['Search'][0]['imdbID'];
$jsontitle = file_get_contents($jsontitleurl,0,null,null);
$json_title_output = json_decode($jsontitle,true);
printf("\nSaving to folder.jpg image URL: \n".$json_title_output['Poster']."\n");
//Now save the image as folder.jpg in the appropriate directory
$img = $directory_unmodified.'/folder.jpg';
file_put_contents($img, file_get_contents($json_title_output['Poster']));
printf("folder.jpg saved\n");

} // end if folder.jpg does not exist
printf("\n------------------------------------------ \n");

Leave a Reply

  • (will not be published)

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>