Subversion Repositories cheapmusic

Rev

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