469,932 Members | 2,765 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,932 developers. It's quick & easy.

RE: no inputstream?

-----Original Message-----
From: py***********************************@python.org [mailto:python-
li****************************@python.org] On Behalf Of max
Sent: Thursday, May 15, 2008 8:02 AM
To: py*********@python.org
Subject: Re: no inputstream?

On May 15, 9:51*am, castironpi <castiro...@gmail.comwrote:
On May 15, 8:37*am, Marc 'BlackJack' Rintsch <bj_...@gmx.netwrote:
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
jk******@ltgc.com

Jun 27 '08 #1
11 1506
"John Krukoff" <jk******@ltgc.comwrites:
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/...putStream.html -- no
seeking there.
Jun 27 '08 #2
max
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 <hnik...@xemacs.orgwrote:
"John Krukoff" <jkruk...@ltgc.comwrites:
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.
Jun 27 '08 #3
On May 15, 9:00 pm, max <maxwell.newla...@gmail.comwrote:
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.
Jun 27 '08 #4
max
On May 15, 6:18*pm, MRAB <goo...@mrabarnett.plus.comwrote:
On May 15, 9:00 pm, max <maxwell.newla...@gmail.comwrote:
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...
Jun 27 '08 #5

On Thu, 2008-05-15 at 15:35 -0700, max wrote:
On May 15, 6:18 pm, MRAB <goo...@mrabarnett.plus.comwrote:
On May 15, 9:00 pm, max <maxwell.newla...@gmail.comwrote:
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?%3Aactio...&submit=search

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

--
John Krukoff <jk******@ltgc.com>
Land Title Guarantee Company

Jun 27 '08 #6

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...@mrabarnett.plus.comwrote:
On May 15, 9:00 pm, max <maxwell.newla...@gmail.comwrote:
>
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?%3Aactio...&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 <jk******@ltgc.com>
Land Title Guarantee Company

Jun 27 '08 #7

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...@mrabarnett.plus.comwrote:
On May 15, 9:00 pm, max <maxwell.newla...@gmail.comwrote:

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?%3Aactio...&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 <jk******@ltgc.com>
Land Title Guarantee Company

Jun 27 '08 #8

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...@mrabarnett.plus.comwrote:
On May 15, 9:00 pm, max <maxwell.newla...@gmail.comwrote:
>
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?%3Aactio...&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 <jk******@ltgc.com>
Land Title Guarantee Company

Jun 27 '08 #9
On May 15, 6:42*pm, John Krukoff <jkruk...@ltgc.comwrote:
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...@mrabarnett.plus.comwrote:
On May 15, 9:00 pm, max <maxwell.newla...@gmail.comwrote:
you're right, my java implementation does indeed parse for Id3v2
(sorry for the confusion). *i'm using the getrawid3v2() methodof 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?%3Aactio...&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 <jkruk...@ltgc.com>
Land Title Guarantee Company- Hide quoted text -

- Show quoted text -
I'm supposed to question "time.toomuch.spend". NAMERS!
Jun 27 '08 #10
On May 15, 6:49*pm, castironpi <castiro...@gmail.comwrote:
On May 15, 6:42*pm, John Krukoff <jkruk...@ltgc.comwrote:


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...@mrabarnett.plus.comwrote:
On May 15, 9:00 pm, max <maxwell.newla...@gmail.comwrote:
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 thismight
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 toconvert
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?%3Aactio...&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 <jkruk...@ltgc.com>
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!
Jun 27 '08 #11
max
On May 15, 10:31*pm, castironpi <castiro...@gmail.comwrote:
On May 15, 6:49*pm, castironpi <castiro...@gmail.comwrote:
On May 15, 6:42*pm, John Krukoff <jkruk...@ltgc.comwrote:
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...@mrabarnett.plus.comwrote:
On May 15, 9:00 pm, max <maxwell.newla...@gmail.comwrote:
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 inputstreamthat 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?%3Aactio...&submit=search
Possibly one with actual documentation, since that would also be astep
up from mutagen.
After a bit of time looking around, looks like nearly all the pythonid3
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 <jkruk...@ltgc.com>
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...
Jun 27 '08 #12

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Seong Jin, Cho | last post: by
1 post views Thread by Charles.Deisler | last post: by
7 posts views Thread by Steve Drake | last post: by
reply views Thread by bvasanth123 | last post: by
reply views Thread by bvasanth123 | last post: by
1 post views Thread by samtilden | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.