Beispiel #1
0
 public static function to_array_from_path($filepath)
 {
     $dom = new DomDocument();
     $dom->load($filepath);
     return plist::parse_dom($dom);
 }
Beispiel #2
0
/**
 * @package callumacrae/plist
 * @version 1.1.0
 * @copyright (c) Callum Macrae 2011 - 3012
 * @license http://creativecommons.org/licenses/by-sa/3.0/ CC by-sa
 *
 * Demo: iTunes library parser
 *
 * DO NOT USE THIS ON A LIVE SERVER, EVER!
 * The file name is NOT escaped
 */
require './plist.php';
// Default file to parse
$default = '/Users/callumacrae/Music/iTunes/iTunes Music Library.xml';
$array = plist::parse(isset($_GET['path']) ? $_GET['path'] : $default);
$total_time = 0;
foreach ($array['Tracks'] as $track) {
    if (!empty($track['Play Count']) && !empty($track['Total Time'])) {
        $total_time += $track['Total Time'] * $track['Play Count'];
    }
}
$total_time = round($total_time / 1000);
echo PHP_EOL;
echo 'Total time in seconds: ' . $total_time . PHP_EOL;
echo 'Total time in hours: ' . round($total_time / 3600, 2) . PHP_EOL;
echo PHP_EOL;
$units = array('year' => 29030400, 'month' => 2419200, 'week' => 604800, 'day' => 86400, 'hour' => 3600, 'minute' => 60, 'second' => 1);
$diff = $total_time;
$output = '';
foreach ($units as $unit => $mult) {