从 iTunes 播放列表中提取 mp3 路径

发布于 2024-10-18 04:19:01 字数 218 浏览 8 评论 0原文

我想用 Python 编写一个程序,它允许我用从 iTunes 播放列表中提取的 mp3 文件填充文件夹。

原因如下:我的汽车有一个可以读取 USB 驱动器的立体声音响,因此我想将我最喜欢的歌曲(已在 iTunes 中整理)填充到我的 USB 驱动器中。

有可能吗?我检查了 iTunes API,但找不到任何有用的东西...

谢谢

Matteo - 意大利

I want to write a program in Python which would allow me to populate a folder with mp3 files extracted from an iTunes playlist.

Here's why: my car has a stereo which can read USB drives, so I want to populate my USB drive with my favourite songs which are already organized in iTunes.

Is that possibile? I've checked iTunes APIs but could not find anything useful...

Thanks

Matteo - Italy

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

鹿港巷口少年归 2024-10-25 04:19:01

我没有现成的解决方案,但我可以帮助您自己制定解决方案。

播放列表解析将是最困难的部分。使用 shutilos 模块以及其他工具填充 USB 驱动器应该很简单,因此我不会讨论该部分。

您可以在以下位置搜索 "itunes" PyPI,又名奶酪店。 “hachoir-parser”包看起来很有前途。您还可以研究 iTunes 资料库文件 的格式,并找到一个解决方案来检索您想要的信息。想。它不使用 API,但对于您的目的来说,它可能就足够了。

希望这会有所帮助,至少是一点点。

I don't have a ready-made solution, but I could help you on your way towards making a solution yourself.

The playlist parsing would be the most difficult part. Populating your USB drive should be simple with the shutil and os modules and other tools, so I won't address that part.

You could do a search for "itunes" in PyPI, a.k.a. the Cheese Shop. The "hachoir-parser" package looks promising. You could also investigate the format of the iTunes library files and cobble a solution to retrieve the information that you want. It doesn't use the API, but for your purposes, it might be adequate.

Hope this is helpful, at least a little bit.

酒废 2024-10-25 04:19:01

Ciao Matteo,

您现在可能已经有了解决方案,但是普通的旧拖放怎么样?

1)创建所有要复制的歌曲的播放列表
2) 选择全部拖放到USB上
3) 根据需要重命名/重新标记

我为 iTunes 编写了几个扩展,因此如果上述内容没有帮助,请告诉我。

西蒙娜

Ciao Matteo,

You probably have a solution by now, but how about plain old drag and drop ?

1) Create playlist of all songs to copy
2) Select all drag and drop onto USB
3) Rename/retag as needed

I wrote a couple of extensions to iTunes, so if the above does not help, let me know.

Simone

薄荷→糖丶微凉 2024-10-25 04:19:01

我在自己写完这篇文章之后偶然发现了这篇文章。因此,以制作无耻插件为代价,这里是: https://github .com/lorenzog/python_playground/tree/master/itunes-extracter

您可能感兴趣的关键部分是以下代码段(将播放列表导出为 XML 文件后):

r = etree.parse(xmlfile)
locations = r.xpath('//key[.="Location"]')
for el in locations:
    srcpath_enc_fullurl = el.getnext().text

注意 getnext() 调用:这是因为每个 Location 项后面都跟着 URL 编码格式的每个音频文件的完整路径。像 file:///Users/myself/foo/bar/music%20 directory/

我希望这对你有帮助,至少对其他人有帮助。

I stumbled on this post after having written my own. So at the cost of making a shameless plug, here it is: https://github.com/lorenzog/python_playground/tree/master/itunes-extracter

The key bit you might be interested in is the following piece of code (once you've exported the playlist as an XML file):

r = etree.parse(xmlfile)
locations = r.xpath('//key[.="Location"]')
for el in locations:
    srcpath_enc_fullurl = el.getnext().text

Notice the getnext() call: that's because each <key>Location</key> item is followed by the full path of each audio file in URL-encoded format. Something like file:///Users/myself/foo/bar/music%20 directory/

I hope this helps if not you at least somebody else.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文