Subversion Repositories cheapmusic

Rev

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