RE:没有输入流? [英] RE: no inputstream?

查看:94
本文介绍了RE:没有输入流?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

-----原始消息-----

-----Original Message-----


来自:py **************** *******************@python.org [mailto:python-

li ************* ***************@python.org]代表max

发送时间:2008年5月15日星期四上午8:02

要: py*********@python.org

主题:回复:没有输入流?


5月15日9:51 * am,castironpi< castiro ... @ gmail.comwrote:
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:

5月15日早上8点37分,Marc''BlackJack''Rintsch< bj _... @ gmx.netwrote:
On May 15, 8:37*am, Marc ''BlackJack'' Rintsch <bj_...@gmx.netwrote:

On Thu,2008年5月15日06:08:35 -0700,max写道:

i目前有问题的mp3的位置为字符串,这是

的工作原理解析本地文件,但给我一个没有这样的文件或

目录尝试处理URL时出错。 *为了获得那些小标签数据,下载每个mp3效率似乎非常低......

我认为有办法用file()或打开()或

的东西,我无法让它工作。
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.


您可以使用`urllib2.urlopen()`打开URL作为文件。 *但是,如果你
You can use `urllib2.urlopen()` to open URLs as files. *But if you



交易

deal


with ID3 V1标签你无论如何都要下载文件,因为那些
with ID3 V1 tags you''ll have to download the file anyway because those




are


在MP3文件的最后128个字节中。
in the last 128 bytes of an MP3 file.


Ciao,

* * * * Marc''BlackJack''Rintsch
Ciao,
* * * * Marc ''BlackJack'' Rintsch



只是不要输入时间。 *你会对自动锁定计时器做什么,

如线程上的time.sleep()? *在一位女士面前,我的舌头被绑在一起


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.



谢谢你们。我想我只是觉得有办法在最后得到那些

id3字节而不下载整个文件。如果java可以执行此操作,看起来我应该坚持使用该实现,不是吗?

-
http://mail.python.org/mailman/listinfo/python-list



首先,忽略castironpi,这是测试失败。


其次,我很好奇Java如何管理它。在HTTP连接已经建好后,我认为他们的流

必须是非常神奇的。


无论如何,正如我所看到的,这更像是一个HTTP协议问题。我想你需要做的是将你的HTTP范围标头设置为bytes = -128,请参阅urllib2

文档。这并不难。唯一不足的是,并非所有的HTTP服务器都支持Range标头,而且它仍然是HTTP

规范的可选部分。据我所知,它是获得部分转移的唯一途径,但是,这是



此外,你确定你正在处理v1标签而不是v2?由于v2标签是存储在文件开头(或有时以v2.4结尾)的
。你可能只需用urllib2打开文件并将其交给

,无论你正在使用什么id3标签读取库,都可以更好。只要它是合理的b $ b b b smart,它应该只下载它所需的文件部分(如果

标签碰巧是v1,那将是整个文件)。


我很想知道Java如何通过通用的

流接口自动处理所有这些。

-

John Krukoff
jk******@ltgc.com

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

推荐答案

" John Krukoff" < jk ****** @ ltgc.comwrites:
"John Krukoff" <jk******@ltgc.comwrites:

我很想知道Java如何通过
$自动处理所有这些但是b $ b通用流接口。
I''d love to know how Java handles all that automatically through a
generic stream interface, though.



可能是他们的流接口支持seek(),并且

seek()在HTTP连接上发送适当的范围请求并且,

如果失败,抛出一个适当的例外,客户代码

解释为寻求不可能,读取整个文件。

但这并不适用于
http://java.sun.com/j2se/1.5.0/docs/...putStream.html - 没有

在那里寻找。

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.


你是对的,我的java实现确实解析了Id3v2

(对不起混淆)。我正在使用这个

比特流类的getrawid3v2()方法( http://www.javazoom.net/javalayer/docs/docs0.4/

javazoom / jl / decoder / Bitstream.html)返回输入流然后

i缓冲区和解析。如果我歪曲了我的代码,我会道歉!


回到python,我想知道我是否在滥用mutagen id3模块。这个

简要教程( http:// www .sacredchao.net / quodlibet / wiki / Development /

Mutagen / Tutorial)让我相信这样的事情可能会工作:

工作:


来自mutagen.mp3导入MP3

id3tags = MP3(urllib2.urlopen(URL))


但这给了我以下TypeError:强制转换为Unicode:需要

字符串或缓冲区,找到实例。这是否意味着我需要转换

类似文件的对象 urlopen()返回到unicode

对象?如果是这样,我只是用''utf-8''解码(),或者这是更多的

复合体?截至目前,这样做主要是没有这样的文件或

目录。错误,有几个HTTP 404.


无论如何,再次感谢....

5月15日,1:02 * pm,Hrvoje Niksic< hnik ... @ xemacs.orgwrote:
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:
"John Krukoff" <jkruk...@ltgc.comwrites:

我很想知道Java如何通过

自动处理所有这些但是,通用流接口。
I''d love to know how Java handles all that automatically through a
generic stream interface, though.



可能是他们的流接口支持seek(),并且

seek()在HTTP连接上发送适当的范围请求并且,

如果失败,抛出一个适当的例外,客户代码

解释为寻求不可能,读取整个文件。

但是这并不适用于描述的输入:http://java.sun.com/j2se/1.5.0/docs/api/java/io/InputStream.html-- no

在那里寻找。


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.


5月15日晚上9点,max< maxwell.newla ... @ gmail.comwrote:
On May 15, 9:00 pm, max <maxwell.newla...@gmail.comwrote:

你是对的,我的java实现确实解析了Id3v2

(对不起混淆)。我正在使用这个

比特流类的getrawid3v2()方法( http://www.javazoom.net/javalayer/docs/docs0.4/

javazoom / jl / decoder / Bitstream.html)返回输入流然后

i缓冲区和解析。如果我歪曲了我的代码,我会道歉!


回到python,我想知道我是否在滥用mutagen id3模块。这个

简要教程( http:// www .sacredchao.net / quodlibet / wiki / Development /

Mutagen / Tutorial)让我相信这样的事情可能会工作:

工作:


来自mutagen.mp3导入MP3

id3tags = MP3(urllib2.urlopen(URL))


但这给了我以下TypeError:强制转换为Unicode:需要

字符串或缓冲区,找到实例。这是否意味着我需要转换

类似文件的对象 urlopen()返回到unicode

对象?如果是这样,我只是用''utf-8''解码(),或者这是更多的

复合体?截至目前,这样做主要是没有这样的文件或

目录。错误,有几个HTTP 404.
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]

我认为它是期待MP3的路径,但你' '给它

的内容。

[snip]
I think it''s expecting the path of the MP3 but you''re giving it the
contents.


这篇关于RE:没有输入流?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆