Phase 2 done
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
$file = $argv[1] ?? '/var/www/epg/guide.xml';
|
||||
|
||||
if (!file_exists($file)) {
|
||||
fwrite(STDERR, "Datei nicht gefunden: {$file}\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$xml = simplexml_load_file($file);
|
||||
|
||||
if (!$xml) {
|
||||
fwrite(STDERR, "XML konnte nicht gelesen werden.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$tagCounts = [];
|
||||
$programmeTagCounts = [];
|
||||
$attributeCounts = [];
|
||||
$samples = [];
|
||||
|
||||
function countNode(SimpleXMLElement $node, string $path): void
|
||||
{
|
||||
global $tagCounts, $attributeCounts, $samples;
|
||||
|
||||
$name = $node->getName();
|
||||
$fullPath = $path === '' ? $name : $path . '/' . $name;
|
||||
|
||||
$tagCounts[$fullPath] = ($tagCounts[$fullPath] ?? 0) + 1;
|
||||
|
||||
$text = trim((string)$node);
|
||||
if ($text !== '' && !isset($samples[$fullPath])) {
|
||||
$samples[$fullPath] = mb_substr($text, 0, 120);
|
||||
}
|
||||
|
||||
foreach ($node->attributes() as $attrName => $attrValue) {
|
||||
$attrPath = $fullPath . '[@' . $attrName . ']';
|
||||
$attributeCounts[$attrPath] = ($attributeCounts[$attrPath] ?? 0) + 1;
|
||||
|
||||
$value = trim((string)$attrValue);
|
||||
if ($value !== '' && !isset($samples[$attrPath])) {
|
||||
$samples[$attrPath] = mb_substr($value, 0, 120);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($node->children() as $child) {
|
||||
countNode($child, $fullPath);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($xml->children() as $child) {
|
||||
countNode($child, '');
|
||||
}
|
||||
|
||||
foreach ($xml->programme as $programme) {
|
||||
foreach ($programme->children() as $child) {
|
||||
$name = $child->getName();
|
||||
$programmeTagCounts[$name] = ($programmeTagCounts[$name] ?? 0) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
ksort($tagCounts);
|
||||
ksort($attributeCounts);
|
||||
arsort($programmeTagCounts);
|
||||
|
||||
echo "XMLTV Analyse\n";
|
||||
echo "=============\n\n";
|
||||
echo "Datei: {$file}\n";
|
||||
echo "Channels: " . count($xml->channel) . "\n";
|
||||
echo "Programme: " . count($xml->programme) . "\n\n";
|
||||
|
||||
echo "Programme-Tags nach Häufigkeit\n";
|
||||
echo "------------------------------\n";
|
||||
|
||||
foreach ($programmeTagCounts as $tag => $count) {
|
||||
echo str_pad($tag, 24) . $count . "\n";
|
||||
}
|
||||
|
||||
echo "\nAlle Tags\n";
|
||||
echo "--------\n";
|
||||
|
||||
foreach ($tagCounts as $path => $count) {
|
||||
$sample = isset($samples[$path]) ? ' Beispiel: ' . $samples[$path] : '';
|
||||
echo str_pad($path, 45) . str_pad((string)$count, 8, ' ', STR_PAD_LEFT) . $sample . "\n";
|
||||
}
|
||||
|
||||
echo "\nAttribute\n";
|
||||
echo "---------\n";
|
||||
|
||||
foreach ($attributeCounts as $path => $count) {
|
||||
$sample = isset($samples[$path]) ? ' Beispiel: ' . $samples[$path] : '';
|
||||
echo str_pad($path, 45) . str_pad((string)$count, 8, ' ', STR_PAD_LEFT) . $sample . "\n";
|
||||
}
|
||||
Reference in New Issue
Block a user