Skip to content

Instantly share code, notes, and snippets.

@d8ahazard
Last active December 26, 2018 02:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save d8ahazard/fa95d120598b406821ceaee66fa5ab07 to your computer and use it in GitHub Desktop.
Save d8ahazard/fa95d120598b406821ceaee66fa5ab07 to your computer and use it in GitHub Desktop.
PlexProfileScraper
<?php
$files = glob("./profiles/*.xml");
$profiles = [];
$types = [];
$names = [];
foreach($files as $file) {
$data = new SimpleXMLElement(file_get_contents($file));
$flat = json_decode(json_encode($data), true);
$name = $flat['@attributes']['name'];
$dpTypes = [];
$dpv = $flat['DirectPlayProfiles']['VideoProfile'] ?? [];
$dpa = $flat['DirectPlayProfiles']['AudioProfile'] ?? [];
// Check if dpv has attributes, then we know it's a single item
if (isset($dpv['@attributes'])) {
$vals = $dpv['@attributes'];
$cont = $vals['container'];
$vc = explode(",", $vals['codec']);
$ac = explode(",", $vals['audioCodec']);
foreach($vc as $c) if (trim($c)) array_push($dpTypes, "$cont - $c");
foreach($ac as $c) if (trim($c)) array_push($dpTypes, "$cont - $c");
} else { // Otherwise, it's an array of codecs
foreach($dpv as $type) {
$vals = $type['@attributes'];
$cont = $vals['container'];
$vc = explode(",", $vals['codec']);
$ac = explode(",", $vals['audioCodec']);
foreach($vc as $c) if (trim($c)) array_push($dpTypes, "$cont - $c");
foreach($ac as $c) if (trim($c)) array_push($dpTypes, "$cont - $c");
}
}
// Repeat for audio codecs
if (isset($dpa['@attributes'])) {
$vals = $dpa['@attributes'];
$cont = $vals['container'];
$vc = explode(",", $vals['codec']);
foreach($vc as $c) if (trim($c)) array_push($dpTypes, "$cont - $c");
} else {
foreach($dpa as $type) {
$vals = $type['@attributes'];
$cont = $vals['container'];
$vc = explode(",", $vals['codec']);
foreach($vc as $c) if (trim($c)) array_push($dpTypes, "$cont - $c");
}
}
array_push($names, $name);
// Push all types to an array so we have a full list...
foreach($dpTypes as $type) array_push($types, $type);
$profiles[$name] = ['direct' => array_unique($dpTypes)];
}
$types = array_unique($types);
sort($types);
$out = [];
// Take the array of codecs for each device, loop over the full array, set "true/false" for supported values
foreach($profiles as $name => $profile) {
$dpSet = [];
$dp = $profile['direct'];
foreach($types as $type) {
$dpSet[$type] = in_array($type, $dp);
}
$out[$name] = $dpSet;
}
// Build some HTML
$table = "";
$table .= "<table>";
$table .= "<tr><th></th>";
foreach($names as $name) {
$table .= "<th>$name</th>";
}
$i = 0;
$len = count($types);
while ($i < $len) {
$table .= "<tr><td>".$types[$i]."</td>";
foreach($out as $name => $profile) {
$keys = array_values($profile);
$class = ($keys[$i]) ? "green" : "red";
$name = ($keys[$i]) ? "Supported" : "Not supported";
$table .= "<td class='$class'>$name</td>";
}
$table .= "</tr>";
$i++;
}
echo "
<html>
<head>
<style>
.red {
background-color: red;
}
.green {
background-color: #00c300;
}
</style>
</head>
<body>
$table
</body>
</html>
";
@d8ahazard
Copy link
Author

Put this in a directory. Create a directory in that directory called "profiles". Copy your Plex profiles into profiles.

Load index.php in a browser.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment