{"id":136,"date":"2006-06-07T10:11:27","date_gmt":"2006-06-07T10:11:27","guid":{"rendered":"http:\/\/dev.gregbueno.com\/wp\/sakufu\/2006\/06\/07\/musicbrainz_mys\/"},"modified":"2006-06-07T10:11:27","modified_gmt":"2006-06-07T10:11:27","slug":"musicbrainz_mys","status":"publish","type":"post","link":"https:\/\/gregbueno.com\/sakufu\/2006\/06\/07\/musicbrainz_mys\/","title":{"rendered":"Musicbrainz: MySQL mirror vs. web service"},"content":{"rendered":"<p>Remember how I toiled away at <a href=\"http:\/\/www.gregbueno.com\/sakufu\/?entry_id=2559\">loading a Musicbrainz mirror into MySQL<\/a>? Well, I deleted that mirror.<!-- ckey=\"64920D16\" --><\/p>\n<p>Running queries on a database as large as Musicbrainz was remarkably sluggish with PHP, and joins were practically impossible.<\/p>\n<p>Musicbrainz does offer an <a href=\"http:\/\/wiki.musicbrainz.org\/XMLWebService\">XML web service<\/a>. So it wasn&#8217;t a terrible leap to write a simple class in PHP to query the service and parse the results.<\/p>\n<p><!--more--><\/p>\n<p>I didn&#8217;t find much PHP development out there for Musicbrainz &#8212; <a href=\"http:\/\/www.last.fm\/\">Last.fm<\/a> is probably the most visible Musicbrainz user developing in PHP &#8212; so I had to start from scratch. Want to see the source? <a href=\"http:\/\/www.gregbueno.com\/files\/musicbrainz.php.txt\">Of course you do<\/a>.<\/p>\n<p><strong>Note:<\/strong> I use the <a href=\"http:\/\/www.gregbueno.com\/files\/Snoopy.class.inc\">Snoopy class<\/a> to connect to the web service, and the <a href=\"http:\/\/www.gregbueno.com\/files\/XMLParser.class.inc\">XMLParser<\/a> class to parse the results. I couldn&#8217;t get the <a href=\"http:\/\/www.php.net\/manual\/en\/ref.simplexml.php\">SimpleXML<\/a> library to work with my Windows installation of PHP (my development environment), so I went with a library that mimicked SimpleXML.<\/p>\n<p>To query Musicbrainz for a list of artists matching a particular name:<\/p>\n<p><tt>$mbSearch = new Musicbrainz_WebService;<\/p>\n<p>$mbSearch-&gt;QueryArtist(&quot;Number Girl&quot;);<\/p>\n<p>$artistList = $mbSearch-&gt;results-&gt;{'artist-list'}[0]-&gt;artist;<\/tt><\/p>\n<p>If you know the GID of an artist, you can also query for the artist&#8217;s releases:<\/p>\n<p><tt>$mbSearch = new Musicbrainz_WebService;<\/p>\n<p>$mbSearch-&gt;GetArtistById(&quot;808fe413-ff00-4a68-99fe-0ab265a7e2be&quot;, &quot;sa-Official release-rels&quot;);<\/tt><\/p>\n<p>And you can limit the number of results:<\/p>\n<p><tt>$mbSearch = new Musicbrainz_WebService;<\/p>\n<p>$mbSearch-&gt;GetArtistById(&quot;808fe413-ff00-4a68-99fe-0ab265a7e2be&quot;, &quot;sa-Official release-rels&quot;, 100);<\/tt><\/p>\n<p>You can also query by release or track and their respective IDs:<\/p>\n<p><tt>$mbSearch = new Musicbrainz_WebService;<\/p>\n<p>$mbSearch-&gt;GetReleaseById(&quot;92348049-331a-480c-921b-61e420b98d2d&quot;, &quot;release-events&quot;);<\/tt><\/p>\n<p>The web service does not offer all the relationships in the Musicbrainz database &#8212; no Amazon ASINs, no freedb indeces &#8212; but it is a quick and easy way to leverage the power of Musicbrainz. I use the web service to retrieve track information for <a href=\"http:\/\/www.musicwhore.org\/\">Musicwhore.org<\/a>. The Japanese track listing for <a href=\"http:\/\/archive.musicwhore.org\/artists\/tracks.php?detailID=398\">this release<\/a> is provided by Musicbrainz.<\/p>\n<p>At some point, I&#8217;ll have to write some more thorough documentation, and I need to investigate ways to cache requests to the service. For now, I&#8217;ll let Musicbrainz power part of my content.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Remember how I toiled away at loading a Musicbrainz mirror into MySQL? Well, I deleted that mirror.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[6],"tags":[],"class_list":["post-136","post","type-post","status-publish","format-standard","hentry","category-technophilia-professional"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p4Bkjq-2c","_links":{"self":[{"href":"https:\/\/gregbueno.com\/sakufu\/wp-json\/wp\/v2\/posts\/136","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gregbueno.com\/sakufu\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gregbueno.com\/sakufu\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gregbueno.com\/sakufu\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gregbueno.com\/sakufu\/wp-json\/wp\/v2\/comments?post=136"}],"version-history":[{"count":0,"href":"https:\/\/gregbueno.com\/sakufu\/wp-json\/wp\/v2\/posts\/136\/revisions"}],"wp:attachment":[{"href":"https:\/\/gregbueno.com\/sakufu\/wp-json\/wp\/v2\/media?parent=136"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gregbueno.com\/sakufu\/wp-json\/wp\/v2\/categories?post=136"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gregbueno.com\/sakufu\/wp-json\/wp\/v2\/tags?post=136"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}