-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextractcalibrebooks.php
More file actions
47 lines (38 loc) · 1.46 KB
/
extractcalibrebooks.php
File metadata and controls
47 lines (38 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/php
<?php
$ignoreFiles = array('metadata.opf', 'cover.jpg', '.DS_Store', 'metadata.db');
function copyFiles($calibreDirectory, $targetDirectory) {
$iterator = new DirectoryIterator($calibreDirectory);
foreach ($iterator as $fileinfo)
{
global $ignoreFiles;
if (!$fileinfo->isDot() && $fileinfo->isDir())
{
copyFiles($fileinfo->getPathname(), $targetDirectory);
} else if ($fileinfo->isFile() && (!in_array($fileinfo->getFilename(), $ignoreFiles)))
{
if (file_exists($targetDirectory . '/' . $fileinfo->getFilename())) {
echo 'SKIPPING FILE: ' . $fileinfo->getPathname() . ' (already exist)' . PHP_EOL;
}else {
echo 'COPIYNG FILE: ' . $fileinfo->getPathname() . PHP_EOL;
echo $fileinfo->getPathname().' , '. $targetDirectory . '/' . $fileinfo->getFilename();
copy($fileinfo->getPathname(), $targetDirectory . '/' . $fileinfo->getFilename());
}
}
}
}
function showUsage() {
echo PHP_EOL;
echo 'Extract Calibre Books' . PHP_EOL;
echo 'Extracts the books from the Calibre Directory into a diferent directory.' . PHP_EOL . PHP_EOL;
echo 'Usage:' . PHP_EOL;
echo ' extractcalibrebooks.php [calibre directory] [target directory]' . PHP_EOL . PHP_EOL;
echo 'Example: extractcalibrebooks.php "/users/perico/Calibre Library/" "./"' . PHP_EOL . PHP_EOL;
exit(1);
}
if ($argv[1] === null or $argv[2] === null) {
showUsage();
}
$calibreDirectory = $argv[1];
$targetDirectory = $argv[2];
copyFiles($calibreDirectory, $targetDirectory);