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 ArtistsXmlStreamer extends XmlStreamer
10
{
11
	public function processNode($xmlString, $elementName, $nodeIndex)
12
	{
13
		global $cnt;
14
		global $fh;
15
		global $fhVariations;
16
		global $fhAlias;
17
		global $fhGroups;
18
		global $fhMembers;
19
		global $fhUrls;
20
		global $fhProfiles;
21
 
22
		$xml = simplexml_load_string($xmlString, 'simple_xml_extended');
23
 
24
		if ($elementName == 'artist') {
25
			++$cnt;
26
 
27
			$id = $xml->id;
28
			$name = cleanName($xml->name);
29
			$realname = $xml->realname;
30
 
31
			if (isset($xml->profile) && !empty($xml->profile)) {
32
				$profile = str_replace("\r", '', $xml->profile);
33
				$profile = rtrim($profile);
44 - 34
				if (!empty($profile)) {
35
					fputcsv2($fhProfiles, array($id, $profile), ',', '"');
36
				}
18 - 37
			}
38
 
39
			if (isset($xml->namevariations)) {
40
				foreach ($xml->namevariations->name as $n) {
44 - 41
					$cn = cleanName($n);
42
					if (!empty($cn)) {
43
						fputcsv2($fhVariations, array($id, $cn), ',', '"');
44
					}
18 - 45
				}
46
			}
47
 
48
			if (isset($xml->aliases)) {
49
				foreach ($xml->aliases->name as $n) {
44 - 50
					$cn = cleanName($n);
51
					if (!empty($cn)) {
52
						fputcsv2($fhAlias, array($id, $cn), ',', '"');
53
					}
18 - 54
				}
55
			}
56
 
57
			if (isset($xml->members)) {
58
				foreach ($xml->members as $n) {
44 - 59
					if (!empty($n->id)) {
60
						fputcsv2($fhMembers, array($id, $n->id), ',', '"');
61
					}
18 - 62
				}
63
			}
64
 
65
			if (isset($xml->groups)) {
66
				foreach ($xml->groups->name as $n) {
44 - 67
					$cn = cleanName($n);
68
					if (!empty($cn)) {
69
						fputcsv2($fhGroups, array($id, $cn), ',', '"');
70
					}
18 - 71
				}
72
			}
73
 
74
			if (isset($xml->urls)) {
75
				foreach ($xml->urls->url as $n) {
44 - 76
					if (!empty($n)) {
77
						fputcsv2($fhUrls, array($id, $n), ',', '"');
78
					}
18 - 79
				}
80
			}
81
 
82
			$arr = array(
83
				$id,
84
				$name,
85
				$realname
86
			);
87
 
44 - 88
			fputcsv2($fh, $arr, ',', '"');
18 - 89
		}
90
 
91
		return true;
92
	}
93
}
94
 
78 - 95
$xmlfile = "./in/discogs_" . XMLFILEDATE . "_artists.xml.gz";
18 - 96
 
97
$fh = fopen("out/artists.load", "w+");
98
$fhVariations = fopen("out/artistVariations.load", "w+");
99
$fhAlias = fopen("out/artistAliases.load", "w+");
100
$fhGroups = fopen("out/artistGroups.load", "w+");
101
$fhMembers = fopen("out/artistMembers.load", "w+");
102
$fhUrls = fopen("out/artistUrls.load", "w+");
103
$fhProfiles = fopen("out/artistProfiles.load", "w+");
104
 
105
$xmlstream = "compress.zlib://$xmlfile";
106
$xmlfileSize = gzfilesize($xmlfile);
107
 
108
$streamer = new ArtistsXmlStreamer($xmlstream, $xmlfileSize);
109
if ($streamer->parse()) {
110
	echo "Finished $cnt artists." . PHP_EOL;
111
} else {
112
	echo "Couldn't find root node" . PHP_EOL;
113
}
114
 
115
fclose($fh);
116
fclose($fhVariations);
117
fclose($fhAlias);
118
fclose($fhGroups);
119
fclose($fhMembers);
120
fclose($fhUrls);
121
fclose($fhProfiles);