如何在 Mac 和 Windows 上找到 iTunes 资料库文件夹?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1962378/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I find iTunes library folder on Mac and Windows?
提问by Boris
I made an application that parse the iTunes library to retrieve its content. It works fine in most cases but if a user moved his library somewhere else than the default iTunes folder (see: http://lifehacker.com/238296/ultranewb--how-to-move-your-itunes-library-to-an-external-drive), then I need a way to find this path.
我制作了一个解析 iTunes 库以检索其内容的应用程序。在大多数情况下它工作正常,但如果用户将他的库移动到默认 iTunes 文件夹以外的其他位置(请参阅:http: //lifehacker.com/238296/ultranewb--how-to-move-your-itunes-library-to- an-external-drive),那么我需要一种方法来找到这条路径。
On Mac, I was looking into ~/Library/Preferences/com.apple.iTunes.plist. There is a setting called "alis:1:iTunes Library Location" but it contains several parameters all concatenated and converted to hexadecimal.
在 Mac 上,我正在查看 ~/Library/Preferences/com.apple.iTunes.plist。有一个名为“alis:1:iTunes Library Location”的设置,但它包含几个参数,所有参数都连接并转换为十六进制。
On Windows, I found this file "C:\Documents and Settings\\Application Data\Apple Computer\iTunes\iTunesPrefs.xml" that contains a setting "iTunes Library XML Location:1" but this one is encoded.
在 Windows 上,我找到了这个文件“C:\Documents and Settings\\Application Data\Apple Computer\iTunes\iTunesPrefs.xml”,其中包含一个设置“iTunes Library XML Location:1”,但这个文件是经过编码的。
Any help would be greatly appreciated. Thanks!
任何帮助将不胜感激。谢谢!
回答by Emerick Rogul
On Windows, the iTunes Library XML Location:1
entry in iTunesPrefs.xml
is a Base 64 encodedUnicode string, so you'll need to decode it before you can use it. On my PC, it decodes to C:\Documents and Settings\Emerick\My Documents\My Music\iTunes\iTunes Music Library.xml
.
在 Windows 上,iTunes Library XML Location:1
输入iTunesPrefs.xml
是Base 64 编码的Unicode 字符串,因此您需要先对其进行解码才能使用它。在我的电脑上,它解码为C:\Documents and Settings\Emerick\My Documents\My Music\iTunes\iTunes Music Library.xml
.
It should be relatively easy to decode this value using your language of choice; your platform may even provide utility libraries that make this trivial. In C#, for example, the decoding function would look something like this:
使用您选择的语言解码此值应该相对容易;您的平台甚至可能提供实用程序库,使这变得微不足道。例如,在 C# 中,解码函数看起来像这样:
static public string DecodeBase64(string encodedData)
{
byte[] encodedBytes = System.Convert.FromBase64String(encodedData);
return System.Text.UnicodeEncoding.Unicode.GetString(encodedBytes);
}
回答by Ken Aspeslagh
I can't help you with the Windows stuff, but on the Mac what you're seeing in that prefs file is old-school alias handle data. Take a look at or just use Chris Hanson's BDAlias class to convert it to a path.
我无法为您提供 Windows 方面的帮助,但在 Mac 上,您在该 prefs 文件中看到的是老式别名句柄数据。查看或仅使用 Chris Hanson 的 BDalias 类将其转换为路径。
回答by original_username
As the others point out "alis:1:iTunes Library Location" is alias data. Here's how I find the path from the data in OS X using Python.
正如其他人指出的那样,“alis:1:iTunes Library Location”是别名数据。这是我使用 Python 从 OS X 中的数据中找到路径的方法。
#!/usr/bin/env python
import commands, plistlib
from Carbon import File
from os.path import expanduser
PLIST_PATH = '~/Library/Preferences/com.apple.iTunes.plist'
PLIST_KEY = 'alis:1:iTunes Library Location'
def resolve_path_from_alias_data( alis ):
fs_ref = File.Alias( rawdata=alis ).FSResolveAlias( None )[0]
file_path = fs_ref.as_pathname()
return file_path
plist_str = commands.getoutput( '/usr/bin/plutil -convert xml1 -o - "' + expanduser( PLIST_PATH ) + '"' )
plist_data = plistlib.readPlistFromString( plist_str )
alis_data = plist_data[ PLIST_KEY ].data
file_path = resolve_path_from_alias_data( alis_data )
print repr( file_path )
Unfortunately, iTunes no longer uses "alis:1:iTunes Library Location"so this no longer works. Now iTunes 11 uses an entry called "RDoc:132:Documents" which seems to be completelydifferent. I have posted a similar question with the appropriate iTunes 11 details.
不幸的是,iTunes 不再使用“alis:1:iTunes Library Location”,所以这不再有效。现在 iTunes 11 使用了一个名为“RDoc:132:Documents”的条目,它似乎完全不同。我已经发布了一个类似的问题,其中包含适当的 iTunes 11 详细信息。
Actually, my answer works just fine as of OS X 10.9.1. I'm not sure whether it stopped due to some error I made, or if Apple quietly reverted something. Either way, it's working again on my Mac.
实际上,我的答案从 OS X 10.9.1 开始就很好用。我不确定它是否因为我犯的一些错误而停止,或者苹果是否悄悄地恢复了某些东西。无论哪种方式,它都可以在我的 Mac 上再次运行。