-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathvalidate.php
More file actions
108 lines (89 loc) · 2.95 KB
/
Copy pathvalidate.php
File metadata and controls
108 lines (89 loc) · 2.95 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
namespace Metadata;
require __DIR__ . '/functions.php';
init();
$opt = getopt('u', ['update']);
$updateStatus = isset($opt['update']) || isset($opt['u']);
if ($updateStatus) {
$listIndex = new \SplFileObject( __DIR__ . '/indexes/list.csv', 'w');
$listIndex->setCsvControl(',', '"', '\\');
$listIndex->fputcsv(['file', 'gallery']);
$byErrorIndex = new \SplFileObject( __DIR__ . '/indexes/errors.csv', 'w');
$byErrorIndex->setCsvControl(',', '"', '\\');
$byErrorIndex->fputcsv(['error', 'file']);
$byDownloadSourceIndex = new \SplFileObject( __DIR__ . '/indexes/downloadSource.csv', 'w');
$byDownloadSourceIndex->setCsvControl(',', '"', '\\');
$byDownloadSourceIndex->fputcsv(['source', 'id', 'file']);
$byUrlSourceIndex = new \SplFileObject( __DIR__ . '/indexes/urlSource.csv', 'w');
$byUrlSourceIndex->setCsvControl(',', '"', '\\');
$byUrlSourceIndex->fputcsv(['source', 'url', 'file']);
$byTitleIndex = new \SplFileObject( __DIR__ . '/indexes/title.csv', 'w');
$byTitleIndex->setCsvControl(',', '"', '\\');
$byTitleIndex->fputcsv(['title', 'file']);
$bySeriesIndex = new \SplFileObject( __DIR__ . '/indexes/series.csv', 'w');
$bySeriesIndex->setCsvControl(',', '"', '\\');
$bySeriesIndex->fputcsv(['title', 'file']);
$byTagIndex = new \SplFileObject( __DIR__ . '/indexes/tags.csv', 'w');
$byTagIndex->setCsvControl(',', '"', '\\');
$byTagIndex->fputcsv(['tag', 'count']);
$byTagArray = [];
}
$files = listFiles();
$status = new StatusReport();
$status->total = count($files);
$first = true;
foreach ($files as $yamlFn) {
$spec = Spec::fromFile($yamlFn);
$baseName = $spec->getBaseName();
$title = $spec->Title;
if ($updateStatus) {
$baseNameCbz = $spec->getBaseNameCbz();
$downloadSource = $spec->DownloadSource;
$downloadSourceId = $spec->DownloadSourceId();
$listIndex->fputcsv([$baseName, $baseNameCbz]);
$byDownloadSourceIndex->fputcsv([$downloadSource, $downloadSourceId, $baseName]);
if (!empty($spec->URL)) {
foreach ($spec->URL as $source => $url) {
$byUrlSourceIndex->fputcsv([$source, $url, $baseName]);
}
}
if (!empty($spec->Series)) {
foreach ($spec->Series as $series) {
$bySeriesIndex->fputcsv([$series, $baseName]);
}
}
$byTitleIndex->fputcsv([$title, $baseName]);
if (!empty($spec->Tags)) {
foreach ($spec->Tags as $tag) {
if (empty($byTagArray[$tag])) {
$byTagArray[$tag] = 0;
}
$byTagArray[$tag]++;
}
}
}
$errors = $spec->validate();
$status->push($spec);
if ($errors->empty()) {
$status->pushOk($spec);
} else {
$status->pushError($spec, $errors);
if ($first) {
echo "Key\tError\tFilename\n";
$first = false;
}
echo $errors->tsv($baseName);
if ($updateStatus) {
foreach ($errors->errors as $error) {
$byErrorIndex->fputcsv([$error->error, $baseName]);
}
}
}
}
if ($updateStatus) {
uksort($byTagArray, 'strnatcasecmp');
foreach ($byTagArray as $tag => $count) {
$byTagIndex->fputcsv([$tag, strval($count)]);
}
$status->updateStatusFile();
}