no inputstream?

John Krukoff jkrukoff at ltgc.com
Thu May 15 19:48:53 EDT 2008


On Thu, 2008-05-15 at 17:42 -0600, John Krukoff wrote:
> On Thu, 2008-05-15 at 17:32 -0600, John Krukoff wrote:
> > On Thu, 2008-05-15 at 17:11 -0600, John Krukoff wrote:
> > > On Thu, 2008-05-15 at 15:35 -0700, max wrote:
> > > > On May 15, 6:18 pm, MRAB <goo... at mrabarnett.plus.com> wrote:
> > > > > On May 15, 9:00 pm, max <maxwell.newla... at gmail.com> wrote:
> > > > >
> > > > > > you're right, my java implementation does indeed parse for Id3v2
> > > > > > (sorry for the confusion).  i'm using the getrawid3v2() method of this
> > > > > > bitstream class (http://www.javazoom.net/javalayer/docs/docs0.4/
> > > > > > javazoom/jl/decoder/Bitstream.html) to return an inputstream that then
> > > > > > i buffer and parse.  apologies if i misrepresented my code!
> > > > >
> > > > > > back to python, i wonder if i'm misusing the mutagen id3 module.  this
> > > > > > brief tutorial (http://www.sacredchao.net/quodlibet/wiki/Development/
> > > > > > Mutagen/Tutorial) leads me to believe that something like this might
> > > > > > work:
> > > > >
> > > > > > from mutagen.mp3 import MP3
> > > > > > id3tags = MP3(urllib2.urlopen(URL))
> > > > >
> > > > > > but this gives me the following TypeError: "coercing to Unicode: need
> > > > > > string or buffer, instance found".  does this mean i need to convert
> > > > > > the "file-like object" that is returned by urlopen() into a unicode
> > > > > > object?  if so, do i just decode() with 'utf-8', or is this more
> > > > > > complex?  as of now, doing so gives me mostly "No such file or
> > > > > > directory" errors, with a few HTTP 404s.
> > > > >
> > > > > [snip]
> > > > > I think it's expecting the path of the MP3 but you're giving it the
> > > > > contents.
> > > > 
> > > > cool, so how do i give it the path, if not in the form of a URL
> > > > string?  maybe this is obvious...
> > > > --
> > > > http://mail.python.org/mailman/listinfo/python-list
> > > 
> > > It doesn't look like you can, with mutagen. So, time to find a different
> > > library that supports arbitrary file objects instead of only file paths.
> > > I'd suggest starting here:
> > > http://pypi.python.org/pypi?%3Aaction=search&term=id3&submit=search
> > > 
> > > Possibly one with actual documentation, since that would also be a step
> > > up from mutagen.
> > > 
> > 
> > After a bit of time looking around, looks like nearly all the python id3
> > modules expect to work with filenames, instead of file objects.
> > 
> > I can't vouch for it, and the documentation still looks sparse, but this
> > module at least looks capable of accepting a file object:
> > http://pypi.python.org/pypi/tagpy
> > 
> > Looks like it'd be a challenge to build if you're on windows, since it
> > depends on an external library.
> > 
> > Alternately, you could probably create a subclass of the mutagen stuff
> > that used an existing file object instead of opening a new one. No idea
> > what that might break, but seems like it would be worth a try.
> > 
> > As last ditch option, could write the first few kb of the file out to a
> > temp file and see if mutagen will load the partial file.
> > 
> 
> Okay, now I'm officially spending too much time looking through this
> stuff.
> 
> However, looks like the "load" method of the MP3 class is what you'd
> want to override to change mutagen's file loading behavior. Probably
> pass the URL as the filename, and take a cut & paste version of the
> default load method from ID3FileType and change it to use urllib2 to
> open it instead of a local file open.
> 
> Might work. Might not. No warranty express or implied.

Hrm, damn, looks like you'd also have to create a custom ID3 class and
override load there too, since that gets called from the ID3FileType
load method. Definitely looks like work.
-- 
John Krukoff <jkrukoff at ltgc.com>
Land Title Guarantee Company




More information about the Python-list mailing list