Subversion Repositories cheapmusic

Rev

Rev 58 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
18 - 1
<?php
2
require_once('php/XmlStreamer.php');
3
require_once('php/tools.php');
78 - 4
require_once('php/constants.php');
18 - 5
ini_set("memory_limit", "256M");
6
 
7
$cnt = 0;
8
 
9
class LabelsXmlStreamer extends XmlStreamer
10
{
11
	public function processNode($xmlString, $elementName, $nodeIndex)
12
	{
13
		global $cnt;
14
		global $fh;
15
		global $fhUrls;
16
 
17
		$xml = simplexml_load_string($xmlString, 'simple_xml_extended');
18
 
19
		if ($elementName == 'label') {
20
			++$cnt;
21
 
22
			$id = $xml->id;
23
			$name = cleanName($xml->name);
24
			$profile = $xml->profile;
25
			$contactInfo = $xml->contactinfo;
26
			$parentLabel = $xml->parentLabel;
27
 
28
			$sublabels = [];
29
			if (isset($xml->sublabels)) {
30
				foreach ($xml->sublabels->label as $n) {
31
					$sublabels[] = cleanName($n);
32
				}
33
			}
34
 
35
			if (isset($xml->urls)) {
36
				foreach ($xml->urls->url as $n) {
44 - 37
					if (!empty($n)) {
38
						fputcsv2($fhUrls, array($id, $n), ',', '"');
39
					}
18 - 40
				}
41
			}
42
 
43
			$arr = array(
44
				$id,
45
				$name,
46
				$parentLabel,
47
				join(", ", $sublabels)
48
			);
49
 
44 - 50
			fputcsv2($fh, $arr, ',', '"');
18 - 51
		}
52
 
53
		return true;
54
	}
55
}
56
 
78 - 57
$xmlfile = "./in/discogs_" . XMLFILEDATE . "_labels.xml.gz";
18 - 58
 
59
$fh = fopen("out/labels.load", "w+");
60
$fhUrls = fopen("out/labelUrls.load", "w+");
61
 
62
$xmlstream = "compress.zlib://$xmlfile";
63
$xmlfileSize = gzfilesize($xmlfile);
64
 
65
$streamer = new LabelsXmlStreamer($xmlstream, $xmlfileSize, true);
66
if ($streamer->parse()) {
67
	echo "Finished $cnt labels." . PHP_EOL;
68
} else {
69
	echo "Couldn't find root node" . PHP_EOL;
70
}
71
 
72
fclose($fh);
73
fclose($fhUrls);