From c60bfc874a3dbda07836940c93c134767c5a5950 Mon Sep 17 00:00:00 2001 From: Gogs Date: Tue, 7 Jul 2026 14:28:35 +0200 Subject: [PATCH] Phase 2 done --- app/tools/xmltv-analyze.php | 93 +++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 app/tools/xmltv-analyze.php diff --git a/app/tools/xmltv-analyze.php b/app/tools/xmltv-analyze.php new file mode 100644 index 0000000..154eb02 --- /dev/null +++ b/app/tools/xmltv-analyze.php @@ -0,0 +1,93 @@ +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"; +}