no inputstream?

John Krukoff jkrukoff at ltgc.com
Thu May 15 11:06:32 EDT 2008


> -----Original Message-----
> From: python-list-bounces+jkrukoff=ltgc.com at python.org [mailto:python-
> list-bounces+jkrukoff=ltgc.com at python.org] On Behalf Of max
> Sent: Thursday, May 15, 2008 8:02 AM
> To: python-list at python.org
> Subject: Re: no inputstream?
> 
> On May 15, 9:51 am, castironpi <castiro... at gmail.com> wrote:
> > On May 15, 8:37 am, Marc 'BlackJack' Rintsch <bj_... at gmx.net> 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
jkrukoff at ltgc.com




More information about the Python-list mailing list