Python解析iTunes XML / COM [英] Python parsing iTunes XML/COM

查看:50
本文介绍了Python解析iTunes XML / COM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将iTunes''XML文件中包含的URL转换为与iTunes''COM接口返回的文件名相当的

表格。


我正在用Python写一个播客分类器;我现在正在Windows下使用iTunes

。 iTunes''COM提供了我的大部分数据输入和我的所有

mp3 / aac编辑功能;我无法通过COM访问的一件事

是发布日期,这是我的主要排序字段。所以我通过COM阅读了

所有内容,然后从

iTunes XML文件中读取所有发布日期,然后尝试将两者结合在一起...但到目前为止我

没有成功。


有没有_any_方法匹配iTunes COM和iTunes之间的曲目

XML?我在这方面花了太多精力。我不会停止使用

文件名,如果这是个坏主意......但我还没有找到任何其他的东西

有效,文件名似乎是一个明显的解决方案。


-Wm

I''m trying to convert the URLs contained in iTunes'' XML file into a
form comparable with the filenames returned by iTunes'' COM interface.

I''m writing a podcast sorter in Python; I''m using iTunes under Windows
right now. iTunes'' COM provides most of my data input and all of my
mp3/aac editing capabilities; the one thing I can''t access through COM
is the Release Date, which is my primary sorting field. So I read
everything in through COM, then read all the release dates from the
iTunes XML file, then try to join the two together... But so far I
have zero success.

Is there _any_ way to match up tracks between iTunes COM and iTunes
XML? I''ve spent far too much effort on this. I''m not stuck on using
filenames, if that''s a bad idea... But I haven''t found anything else
that works, and filenames seem like an obvious solution.

-Wm

推荐答案

要问另一种方式:我该如何转换从文件:// URL到标准方式的本地

路径,以便来自两个不同来源的文件路径

将在字典中以相同的方式工作? />

现在我正在使用以下来源:


track_id = url2pathname(urlparse(track_id).path)


url2pathname来自urllib; urlparse来自urlparse模块。


当文件名中有非ascii字符时会出现问题

他们 - 我怀疑这些URL有一些编码放在

上,Python的解码器不知道。


提前谢谢大家,谢谢你的Python。 br />

-Wm
To ask another way: how do I convert from a file:// URL to a local
path in a standard way, so that filepaths from two different sources
will work the same way in a dictionary?

Right now I''m using the following source:

track_id = url2pathname(urlparse(track_id).path)

url2pathname is from urllib; urlparse is from the urlparse module.

The problems occur when the filenames have non-ascii characters in
them -- I suspect that the URLs are having some encoding placed on
them that Python''s decoder doesn''t know about.

Thank you all in advance, and thank you for Python.

-Wm


7月30日凌晨3:53,william tanksley< wtanksle ... @ gmail.comwrote:
On Jul 30, 3:53 am, william tanksley <wtanksle...@gmail.comwrote:

问另一种方式:如何以标准方式从file:// URL转换为本地

路径,所以来自两个不同来源的文件路径

将在字典中以相同的方式工作吗?


现在我正在使用以下来源:


track_id = url2pathname(urlparse(track_id).path)


url2pathname来自urllib; urlparse来自urlparse模块。


当文件名中有非ascii字符时会出现问题

他们 - 我怀疑这些URL有一些编码放在

上,Python的解码器不知道。
To ask another way: how do I convert from a file:// URL to a local
path in a standard way, so that filepaths from two different sources
will work the same way in a dictionary?

Right now I''m using the following source:

track_id = url2pathname(urlparse(track_id).path)

url2pathname is from urllib; urlparse is from the urlparse module.

The problems occur when the filenames have non-ascii characters in
them -- I suspect that the URLs are having some encoding placed on
them that Python''s decoder doesn''t know about.



什么问题?什么非ASCII字符?考虑例如


#track_id = url2pathname(urlparse(track_id).path)

print repr(track_id)

parse_result = urlparse (track_id).path

print repr(parse_result)

track_id_replacement = url2pathname(parse_result)

print repr(track_id_replacement)


并将结果复制/粘贴到下一个帖子中。

WHAT problems? WHAT non-ASCII characters?? Consider e.g.

# track_id = url2pathname(urlparse(track_id).path)
print repr(track_id)
parse_result = urlparse(track_id).path
print repr(parse_result)
track_id_replacement = url2pathname(parse_result)
print repr(track_id_replacement)

and copy/paste the results into your next posting.


如果要转换使用标准URL编码的文件名

(%20用于空间等)使用:


来自urllib import unquote

new_filename = unquote(filename)


我发现这不会转换形式为

''& #CC;''的编码字符,因此您可能需要手动执行此操作。我认为这些只是用十六进制表示的b $ b ascii编码。
If you want to convert the file names which use standard URL encoding
(with %20 for space, etc) use:

from urllib import unquote
new_filename = unquote(filename)

I have found this does not convert encoded characters of the form
''&#CC;'' so you may have to do that manually. I think these are just
ascii encodings in hexadecimal.


这篇关于Python解析iTunes XML / COM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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