python-musicbrainz: Difference between revisions

From MusicBrainz Wiki
Jump to navigationJump to search
((Imported from MoinMoin))
 
(deleted old comments since this is now deprecated (Imported from MoinMoin))
Line 1: Line 1:
=Python MusicBrainz=
=Python MusicBrainz=

==Introduction==


'''python-musicbrainz''' is a python wrapper for the [[libmusicbrainz]]. It is a straight python to c binding, and uses [http://starship.python.net/crew/theller/ctypes/ ctypes] to avoid having to write c code. You'll have to get and download the ctypes module from the author, or if you have debian unstable, you can apt-get it. This project is now a part of the [[MusicBrainz]] Client library [[libmusicbrainz]].
'''python-musicbrainz''' is a python wrapper for the [[libmusicbrainz]]. It is a straight python to c binding, and uses [http://starship.python.net/crew/theller/ctypes/ ctypes] to avoid having to write c code. You'll have to get and download the ctypes module from the author, or if you have debian unstable, you can apt-get it. This project is now a part of the [[MusicBrainz]] Client library [[libmusicbrainz]].
<ul><li style="list-style-type:none">[[Image:Attention.png]] '''PythonMusicbrainz is deprecated''', and replaced by the new client bindings [[python-musicbrainz2|PythonMusicBrainz2]]. Please use the new python bindings in new projects, since the old RDF Web Service will be moved out of service soon. For more details see [[Web Service|WebService]].
<ul><li style="list-style-type:none">[[Image:Attention.png]] '''PythonMusicbrainz is deprecated''', and replaced by the new client bindings [[python-musicbrainz2|PythonMusicBrainz2]]. Please use the new python bindings in new projects, since the old RDF Web Service will be moved out of service soon. For more details see [[Web Service|WebService]].
</ul>

==Comments==

Are there any docs available for PM? Offers the mb_client similar functions?? - [[Flo K|FloK]]

Any ideas to this error?

<pre>flo@groovesurfer examples $ ./cdid.py
Insert CD and hit enter...

querying musicbrainz.org to see if this cd is on there...
Traceback (most recent call last):
File "./cdid.py", line 54, in ?
main()
File "./cdid.py", line 42, in main
url = mb.GetWebSubmitURL()
File "/home/httpd/musicbrainz/python-musicbrainz/examples/musicbrainz.py", line 149, in GetWebSubmitURL
if not mbdll.mb_GetWebSubmitURL(self.mb, url, BUFSIZE):
TypeError: while constructing argument 2:
string expected instead of c_char_Array_1024 instance
</pre>

In regard to the above error, I have some good news and some bad news. First, the good news. That particular error is caused by your ctypes being horribly old. The one in debian unstable is 0.6.3, in contrast to the 0.9.0 that's shipping from [[SourceForge]]. Upgrade and the error magically disappears. --[[User:MatthewDaniel|MatthewDaniel]]

Now the bad news: after upgrading ctypes, I get a different error using python-musicbrainz 1.0b1: <pre>Traceback (most recent call last):
File "./examples/cdlookup.py", line 12, in ?
main()
File "./examples/cdlookup.py", line 7, in main
mb = musicbrainz.mb()
File "/usr/lib/python2.3/site-packages/musicbrainz.py", line 42, in __init__
mbdll.mb_UseUTF8(self.mb, True)
TypeError: while constructing argument 1:
wrong type
Exception exceptions.AttributeError: "mb instance has no attribute 'mbdll'" in <bound method mb.__del__ of <musicbrainz.mb instance at 0x401eb6cc>> ignored
</pre>

Never one content to let sleeping dogs lie, I played around with ctypes and figured out that (at least with ctypes 0.9.0 on Python 2.3.4) it does not do very much (if any) implicit casting. I wrapped the <code><nowiki>self.mb</nowiki></code> above with a call to the <code><nowiki>c_void_p</nowiki></code> constructor: <code><nowiki>c_void_p(self.mb)</nowiki></code> and it fired right up (after I wrapped all the other calls, too, naturally). I will submit a patch in [[SourceForge]] in a bit, but wanted to update this so the trail wasn't a dead-end for other folks. --[[User:MatthewDaniel|MatthewDaniel]]

----

What is PythonMusicbrainz? Could someone please add a short note here and on the homepage? Thanks --[[User:DonRedman|DonRedman]]
<ul><li style="list-style-type:none">PythonMusicbrainz exposes the libmusicbrainz API calls via a Python object interface. This allows clients to leverage the Musicbrainz mb_client functions without <dfn title="Technical terminology">mucking around</dfn> with malloc, integer return codes and other miscellaneous C fun. --[[User:MatthewDaniel|MatthewDaniel]]
</ul>
</ul>



Revision as of 22:28, 22 April 2007

Python MusicBrainz

python-musicbrainz is a python wrapper for the libmusicbrainz. It is a straight python to c binding, and uses ctypes to avoid having to write c code. You'll have to get and download the ctypes module from the author, or if you have debian unstable, you can apt-get it. This project is now a part of the MusicBrainz Client library libmusicbrainz.

  • Attention.png PythonMusicbrainz is deprecated, and replaced by the new client bindings PythonMusicBrainz2. Please use the new python bindings in new projects, since the old RDF Web Service will be moved out of service soon. For more details see WebService.