RE: no inputstream?

Discussion in 'Python' started by John Krukoff, May 15, 2008.

  1. John Krukoff

    John Krukoff Guest

    > -----Original Message-----
    > From: python-list-bounces+jkrukoff= [mailto:python-
    > list-bounces+jkrukoff=] On Behalf Of max
    > Sent: Thursday, May 15, 2008 8:02 AM
    > To:
    > Subject: Re: no inputstream?
    >
    > On May 15, 9:51 am, castironpi <> wrote:
    > > On May 15, 8:37 am, Marc 'BlackJack' Rintsch <> wrote:
    > >
    > > > On Thu, 15 May 2008 06:08:35 -0700, max wrote:
    > > > > i currently have locations of the mp3s in question as strings, which
    > > > > works for parsing local files, but gives me a "No such file or
    > > > > directory" error when it tries to process URLs.  it seems terribly
    > > > > inefficient to download each mp3 just to get at that small tag data,
    > > > > and i assume there's a way to do this with file() or open() or
    > > > > something, i just can't get it to work.

    > >
    > > > You can use `urllib2.urlopen()` to open URLs as files.  But if you

    > deal
    > > > with ID3 V1 tags you'll have to download the file anyway because those

    > are
    > > > in the last 128 bytes of an MP3 file.

    > >
    > > > Ciao,
    > > >         Marc 'BlackJack' Rintsch

    > >
    > > Just don't import time.  What would you do with an autolocking timer,
    > > such as time.sleep( ) on a thread?  I am tongue tied in the presence
    > > of a lady.

    >
    > thanks guys. i guess i just figured there'd be a way to get at those
    > id3 bytes at the end without downloading the whole file. if java can
    > do this, seems like i should just stick with that implementation, no?
    > --
    > http://mail.python.org/mailman/listinfo/python-list


    First off, ignore castironpi, it's a turing test failure.

    Second, I'm curious as to how Java manages this. I'd think their streams
    would have to be pretty magic to pull this off after the HTTP connection has
    already been built.

    Anyway, as I see it, this is more of a HTTP protocol question. I think what
    you need to do is set the HTTP Range header to bytes=-128, see the urllib2
    documentation for how. It's not that hard. Only down side is that not all
    HTTP servers support the Range header, and it's an optional part of the HTTP
    spec anyway. As far as I know it's the only way to get partial transfers,
    though.

    Also, are you sure you're dealing with v1 tags and not v2? Since v2 tags are
    stored at the beginning (or sometimes end with v2.4) of the file. You might
    be better off just opening the file with urllib2 and handing it off to
    whatever id3 tag reading library you're using. As long as it's reasonably
    smart, it should only download the part of the file it needs (which if the
    tag happens to be v1, will be the whole file).

    I'd love to know how Java handles all that automatically through a generic
    stream interface, though.
    --
    John Krukoff
     
    John Krukoff, May 15, 2008
    #1
    1. Advertising

  2. "John Krukoff" <> writes:

    > I'd love to know how Java handles all that automatically through a
    > generic stream interface, though.


    It could be that their stream interface supports seek(), and that
    seek()ing on HTTP connection sends the appropriate range request and,
    if it fails, throws an appropriate exception which the client code
    interprets as "seeking impossible, read the whole file".

    But that doesn't apply to the InputStream interface described at
    http://java.sun.com/j2se/1.5.0/docs/api/java/io/InputStream.html -- no
    seeking there.
     
    Hrvoje Niksic, May 15, 2008
    #2
    1. Advertising

  3. John Krukoff

    max Guest

    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.

    anyway, thanks again....


    On May 15, 1:02 pm, Hrvoje Niksic <> wrote:
    > "John Krukoff" <> writes:
    > > I'd love to know how Java handles all that automatically through a
    > > generic stream interface, though.

    >
    > It could be that their stream interface supports seek(), and that
    > seek()ing on HTTP connection sends the appropriate range request and,
    > if it fails, throws an appropriate exception which the client code
    > interprets as "seeking impossible, read the whole file".
    >
    > But that doesn't apply to the InputStream interface described athttp://java.sun.com/j2se/1.5.0/docs/api/java/io/InputStream.html-- no
    > seeking there.
     
    max, May 15, 2008
    #3
  4. John Krukoff

    MRAB Guest

    On May 15, 9:00 pm, max <> 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.
     
    MRAB, May 15, 2008
    #4
  5. John Krukoff

    max Guest

    On May 15, 6:18 pm, MRAB <> wrote:
    > On May 15, 9:00 pm, max <> 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...
     
    max, May 15, 2008
    #5
  6. John Krukoff

    John Krukoff Guest

    On Thu, 2008-05-15 at 15:35 -0700, max wrote:
    > On May 15, 6:18 pm, MRAB <> wrote:
    > > On May 15, 9:00 pm, max <> 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?:action=search&term=id3&submit=search

    Possibly one with actual documentation, since that would also be a step
    up from mutagen.

    --
    John Krukoff <>
    Land Title Guarantee Company
     
    John Krukoff, May 16, 2008
    #6
  7. John Krukoff

    John Krukoff Guest

    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 <> wrote:
    > > > On May 15, 9:00 pm, max <> 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?:action=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.

    --
    John Krukoff <>
    Land Title Guarantee Company
     
    John Krukoff, May 16, 2008
    #7
  8. John Krukoff

    John Krukoff Guest

    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 <> wrote:
    > > > > On May 15, 9:00 pm, max <> 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?:action=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.
    --
    John Krukoff <>
    Land Title Guarantee Company
     
    John Krukoff, May 16, 2008
    #8
  9. John Krukoff

    John Krukoff Guest

    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 <> wrote:
    > > > > > On May 15, 9:00 pm, max <> 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?:action=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 <>
    Land Title Guarantee Company
     
    John Krukoff, May 16, 2008
    #9
  10. John Krukoff

    castironpi Guest

    On May 15, 6:42 pm, 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 <> wrote:
    > > > > > On May 15, 9:00 pm, max <> 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?:action=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.
    > --
    > John Krukoff <>
    > Land Title Guarantee Company- Hide quoted text -
    >
    > - Show quoted text -


    I'm supposed to question "time.toomuch.spend". NAMERS!
     
    castironpi, May 16, 2008
    #10
  11. John Krukoff

    castironpi Guest

    On May 15, 6:49 pm, castironpi <> wrote:
    > On May 15, 6:42 pm, 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 <> wrote:
    > > > > > > On May 15, 9:00 pm, max <> 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?:action=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.
    > > --
    > > John Krukoff <>
    > > Land Title Guarantee Company- Hide quoted text -

    >
    > > - Show quoted text -

    >
    > I'm supposed to question "time.toomuch.spend".  NAMERS!- Hide quoted text -
    >
    > - Show quoted text -


    Is there a way 'time.toomuch.spend' can be scanned for in code? If
    not, let's play!
     
    castironpi, May 16, 2008
    #11
  12. John Krukoff

    max Guest

    On May 15, 10:31 pm, castironpi <> wrote:
    > On May 15, 6:49 pm, castironpi <> wrote:
    >
    >
    >
    > > On May 15, 6:42 pm, 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 <> wrote:
    > > > > > > > On May 15, 9:00 pm, max <> 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?:action=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.
    > > > --
    > > > John Krukoff <>
    > > > Land Title Guarantee Company- Hide quoted text -

    >
    > > > - Show quoted text -

    >
    > > I'm supposed to question "time.toomuch.spend".  NAMERS!- Hide quoted text -

    >
    > > - Show quoted text -

    >
    > Is there a way 'time.toomuch.spend' can be scanned for in code?  If
    > not, let's play!


    really, really appreciate your help, john. gonna have to ponder my
    next move here...
     
    max, May 16, 2008
    #12
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brian Birtle
    Replies:
    2
    Views:
    2,098
    John Saunders
    Oct 16, 2003
  2. steven shingler

    Email attachment from InputStream?

    steven shingler, Jan 19, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    387
    Shiv Kumar
    Jan 20, 2004
  3. karahan celikel

    changing Request.InputStream

    karahan celikel, Mar 2, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    4,535
    Karahan Celikel
    Mar 4, 2004
  4. Steve Drake

    ASP.NET InputStream is not a stream

    Steve Drake, Oct 13, 2004, in forum: ASP .Net
    Replies:
    7
    Views:
    7,147
    Gabe Garza
    Oct 18, 2004
  5. R
    Replies:
    5
    Views:
    2,127
    Kevin McMurtrie
    Mar 13, 2005
Loading...

Share This Page