Me gusta que los nombres de los archivos que descargo sean correctos y sea fácil, buscarlos. Esto significa que los nombres deben tener el numero de capitulo, la serie/anime en cuestión y el nombre del capítulo.
El problema, es que a veces se consiguen con nombres de archivos que parecen el resultado de alguna función random, por lo que tenemos una ardua labor de renombrar cada uno de los archivos a mano.
Así que hice un pequeño script en PHP para facilitarme la vida:
Código :
<?php
class files
{
private $total;
private $archivos;
private $serie;
private $nombre;
private $ext;
private $report;
private $sep;
function __construct() {
$directorio = getcwd();
$me = $_SERVER['SCRIPT_NAME'];
$me = basename($me);
$this->report = '';
$dire = opendir($directorio);
if ($dire)
{
while($nombre_archivo = readdir($dire))
{
if ((is_file($nombre_archivo)) && ($nombre_archivo != $me))
{
$this->archivos[] = $nombre_archivo;
}
}
}
sort($this->archivos);
$this->total = count($this->archivos);
$this->ext = substr($this->archivos[0], -3, 3);
}
public function getTotal()
{
return $this->total;
}
public function getName($value)
{
return $this->archivos[$value];
}
public function getReport()
{
return $this->report;
}
public function setSerie($value)
{
$this->serie = $value;
}
public function setSep($value)
{
$this->sep = ' ' . $value . ' ';
}
public function setExt($value)
{
$this->ext = '.' . $value;
}
public function getExt()
{
return $this->ext;
}
public function setName($i, $value, $uppercase)
{
if ($value != '') {
if ($uppercase) {
$value = ucfirst(strtolower($value));
}
$this->nombre[$i] = $this->setCapitulo($i + 1) . $this->sep . $this->serie . $this->sep . $value . $this->ext;
} else {
$this->nombre[$i] = $this->archivos[$i];
}
}
private function setCapitulo($value)
{
if ($value <= 9) {
return '0' . $value;
} else {
return $value;
}
}
public function renombrar()
{
for ($x=0; $x < $this->total; $x++) {
rename($this->archivos[$x], $this->nombre[$x]);
$this->report .= 'Cambie: "' . $this->archivos[$x] . '" por "' . $this->nombre[$x] . '" <br />';
}
}
}
$archi = new files();
if ($_POST)
{
$caps = $_POST['cap'];
$formats = $_POST['format'];
$archi->setSerie($_POST['serie']);
$archi->setSep($_POST['sep']);
$archi->setExt($_POST['ext']);
for ($i=0; $i < $archi->getTotal(); $i++) {
$archi->setName($i, $caps[$i], $formats[$i]);
}
$archi->renombrar();
echo $archi->getReport();
}
else
{
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Renombrando archivos</title>
</head>
<body>
</body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" />
Serie: <input type="text" name="serie" /><br />
Separador: <input type="text" name="sep" value="-" /><br />
Extension: <input type="text" name="ext" value="<?php echo $archi->getExt(); ?>" /><br />
<?php for ($i=0; $i < $archi->getTotal(); $i++) { ?>
Capitulo <?php echo $i + 1; ?>: <?php echo $archi->getName($i); ?> -> Nombre nuevo: <input type="text" name="cap[<?php echo $i; ?>]" /> Formatear texto <input type="checkbox" value="true" checked="checked" name="format[<?php echo $i; ?>]" /><br />
<?php } ?>
<input type="submit" value="Renombrar" />
</form>
</html>
<?php
}
?>