【问题标题】:How do I find iTunes library folder on Mac and Windows?如何在 Mac 和 Windows 上找到 iTunes 资料库文件夹?
【发布时间】:2010-12-30 01:28:56
【问题描述】:

我制作了一个应用程序来解析 iTunes 库以检索其内容。它在大多数情况下都可以正常工作,但如果用户将他的资料库移动到默认 iTunes 文件夹以外的其他位置(请参阅:http://lifehacker.com/238296/ultranewb--how-to-move-your-itunes-library-to-an-external-drive),那么我需要一种方法来找到此路径。

在 Mac 上,我正在查看 ~/Library/Preferences/com.apple.iTunes.plist。有一个名为“alis:1:iTunes Library Location”的设置,但它包含几个参数,所有参数都连接起来并转换为十六进制。

在 Windows 上,我发现此文件“C:\Documents and Settings\\Application Data\Apple Computer\iTunes\iTunesPrefs.xml”包含设置“iTunes Library XML Location:1”,但此文件已编码。

任何帮助将不胜感激。 谢谢!

【问题讨论】:

标签: windows macos itunes


【解决方案1】:

我无法帮助您处理 Windows 的内容,但在 Mac 上,您在该 prefs 文件中看到的是老式别名句柄数据。看看或只是使用 Chris Hanson 的 BDAlias 类将其转换为路径。

http://github.com/rentzsch/bdalias

【讨论】:

  • 非常感谢。我会试一试的。
【解决方案2】:

在 Windows 上,iTunesPrefs.xml 中的 iTunes Library XML Location:1 条目是 Base 64 encoded Unicode 字符串,因此您需要先对其进行解码才能使用它。在我的电脑上,它解码为C:\Documents and Settings\Emerick\My Documents\My Music\iTunes\iTunes Music Library.xml

使用您选择的语言解码此值应该相对容易;您的平台甚至可能提供实用程序库,使这变得微不足道。例如,在 C# 中,解码函数如下所示:

static public string DecodeBase64(string encodedData)
{
  byte[] encodedBytes = System.Convert.FromBase64String(encodedData);
  return System.Text.UnicodeEncoding.Unicode.GetString(encodedBytes);
}

【讨论】:

  • 谢谢,我会试一试!我看到了 .pref 文件,但不确定它是如何编码的。
【解决方案3】:

正如其他人指出的那样,“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 )

很遗憾,iTunes 不再使用“alis:1:iTunes Library Location”,因此这不再有效。现在 iTunes 11 使用了一个名为“RDoc:132:Documents”的条目,它似乎完全不同。我已经发布了a similar question with the appropriate iTunes 11 details

实际上,我的答案在 OS X 10.9.1 中运行良好。我不确定它是否由于我犯的一些错误而停止,或者苹果是否悄悄地恢复了某些东西。无论哪种方式,它都能在我的 Mac 上再次运行。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-07
    • 2021-01-15
    • 2013-07-11
    • 2011-04-07
    相关资源
    最近更新 更多