diff --git a/misc/testing/PostProc/extractTVCovers.php b/misc/testing/PostProc/extractTVCovers.php new file mode 100644 index 000000000..ff14e1c7c --- /dev/null +++ b/misc/testing/PostProc/extractTVCovers.php @@ -0,0 +1,46 @@ +queryDirect("SELECT rageid, imgdata FROM tvrage WHERE rageid > 0"); + +if ($shows instanceof \Traversable) { + echo "\n"; + $imgSavePath = NN_COVERS . 'tvrage' . DS; + echo $pdo->log->header("Extracting " . number_format($shows->rowCount()) . " tv show covers and saving them to ${imgSavePath}." . PHP_EOL); + + $failCnt = $succCnt = $badCnt = 0; + + foreach ($shows as $show) { + + if (!empty($show['imgdata']) && !is_null($show['imgdata'])) { + + // Store it on the hard drive. + $coverPath = $imgSavePath . (int)$show['rageid'] . '.jpg'; + $coverSave = @file_put_contents($coverPath, $show['imgdata']); + + // Check if it's on the drive. + if ($coverSave === false || !is_file($coverPath)) { + $failCnt++; + echo "."; + // Check if the image is formatted properly and useable + } else if (imagecreatefromjpeg($coverPath) === false) { + @unlink($coverPath); + $failCnt++; + echo "#"; + } else { + $succCnt++; + echo "!"; + } + } else { + $badCnt++; + echo "!"; + } + } + echo PHP_EOL . PHP_EOL . $pdo->log->header("Successfully exported " . number_format($succCnt) . " tv show covers. " . number_format($failCnt) . " failed to save and " . number_format($badCnt) . " entries had bad imgdata." . PHP_EOL); +} else { + exit(PHP_EOL . $pdo->log->error("No shows found to extract images.")); +} \ No newline at end of file