6

如果Itunes:Preferences:Advanced:Keep iTunes Folder Organized在 Windows 上以编程方式设置,我该如何解决,我与 iTunes 交互的 Java 应用程序需要知道这一点。

不幸的是,iTunes xml File 或 Itunes COM API 似乎都没有提供此信息,我认为是因为它们是存储在其他地方的首选项,但我如何才能确定是否启用,我还需要知道这一点,以便将文件复制到 iTunes Media添加到库时的文件夹

更新: 注册表中没有任何内容,但我找到了一个首选项文件

C:\Users\用户名\AppData\Roaming\Apple Computer\iTunes

但是它似乎是加密/编码的,我不知道如何读取这些值

更新 2:

保存了文件的副本,在添加到库时更改了 Copy files to iTunes Media Folder 的值并进行比较并获得了更改

<key>Documents:132</key>
<data>
AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAA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QAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAACwf6jgsOrUhX8BAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
</data>

但是你可以看到很难发现差异,我担心如果我破解了这个 valkue 它可能会在 iTunes 版本之间中断,有没有办法解码这个文件?

更新 3

我发现Apache Commons Configuration支持 Apples plist 格式作为 Xml 格式http://commons.apache.org/proper/commons-configuration/apidocs/org/apache/commons/configuration/plist/XMLPropertyListConfiguration.html但不幸的是二进制格式在这里使用。

我编写了列出所有键的代码,然后尝试解码 location 属性,因为我知道它只包含一个 base64 编码器文件路径。

public File getITunesXMLFile()
    {
        String homedir = System.getProperty("user.home");

        File prefsFile = new File(homedir,"AppData/Roaming/Apple Computer/iTunes/iTunesPrefs.xml");
        try
        {
            XMLPropertyListConfiguration xpc = new XMLPropertyListConfiguration(prefsFile);
            xpc.load();
            Iterator<String> keys = xpc.getKeys();
            while(keys.hasNext())
            {
                String nextKey = keys.next();
                System.out.println(nextKey+":"+xpc.getProperty(nextKey).getClass());
            }
            ArrayList location = (ArrayList)xpc.getProperty("User Preferences.iTunes Library XML Location:1");
            System.out.println("Location:"+location.get(0).getClass());
            System.out.println("Location:"+location.get(1).getClass());

            System.out.println("Location1:"+ new BASE64Decoder().decodeBuffer(location.get(0).toString()));
            System.out.println("Location2:"+ new BASE64Decoder().decodeBuffer(location.get(1).toString()));
        }
        catch(Exception ex)
        {
            MainWindow.logger.log(Level.SEVERE,"Unable to open iTunes Prefs file:"+prefsFile.getName(),ex);
        }
        File xmlFile = new File(homedir + "/Music/iTunes/iTunes Music Library.xml");
        if (!xmlFile.exists())
        {
            return null;
        }
        return xmlFile;
    }

但不幸的是没有工作,因为数据作为 [B 类型的类的 ArrayList 返回,这对我来说没有意义,它不是类的有效名称。

输出是

EQ Preferences.EQPresets:129:class java.util.ArrayList
User Preferences.Documents:132:class java.util.ArrayList
User Preferences.Gracenote User ID:1:class java.util.ArrayList
User Preferences.Music Store:1:class java.util.ArrayList
User Preferences.Pairing Preferences:301:class java.util.ArrayList
User Preferences.Preferences:130:class java.util.ArrayList
User Preferences.Radio Tuner Categories:131:class java.util.ArrayList
User Preferences.Touch Remote Preferences:400:class java.util.ArrayList
User Preferences.iTunes Library XML Location:1:class java.util.ArrayList
User Preferences.iTunes..exe:AAC Encoder:class java.util.ArrayList
User Preferences.iTunes..exe:iTunes Classic Visualiser:class java.util.ArrayList
User Preferences.license-agreements.EA0962:class java.util.ArrayList
User Preferences.storefront:class java.util.ArrayList
Location:class [B
Location:class [B
Location1:[B@58a7a
Location2:[B@2893bb6f
+++++++++++++++++++++++++++++++++++++++++++++++

并且还发现了这个问题https://issues.apache.org/jira/browse/CONFIGURATION-262

更新 4

找到了一个已经支持二进制代码的库。google.com/p/plist 看起来很有希望

更新 5

我已经设法使用这个库来解码 Xml 文件位置,如下所示(来自 Apache Commons Codec 1.8 的 Base64 类)

public File getITunesXMLFile()
    {
        System.getProperties().list(System.out);
        String homedir = System.getProperty("user.home");
        File prefsFile = new File(homedir,"AppData/Roaming/Apple Computer/iTunes/iTunesPrefs.xml");
        File xmlFile;
        try
        {
            NSDictionary rootDict = (NSDictionary) PropertyListParser.parse(prefsFile);
            NSDictionary userPrefs = (NSDictionary) rootDict.objectForKey("User Preferences");
            if(userPrefs!=null)
            {
                NSData iTunesLocation = (NSData) userPrefs.objectForKey("iTunes Library XML Location:1");
                if(iTunesLocation!=null)
                {
                    String base64 = iTunesLocation.getBase64EncodedData();
                    String filepath = new String(Base64.decodeBase64(base64),"UTF-16LE");
                    xmlFile = new File(filepath);
                    System.out.println(filepath+":File Exists:"+xmlFile.exists());
                    if (xmlFile.exists())
                    {
                        return xmlFile;
                    }
                }
            }
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
            //Use default then
            xmlFile = new File(homedir + "/Music/iTunes/iTunes Music Library.xml");
            if (xmlFile.exists())
            {
                return xmlFile;
            }
        }
        return null;
    }

更新 6

我试图对我真正感兴趣的数据执行此操作,我能够从 Documents:132 密钥中提取 base64 编码的数据,但不幸的是,尝试解码这个 base64 编码并没有真正让我到任何地方,也许我只需要看看启用/禁用标志时 base64 编码数据的差异。

 public boolean isiTunesCopyFolderToMediaFolder()
    {
        String homedir = System.getProperty("user.home");
        File prefsFile = new File(homedir,"AppData/Roaming/Apple Computer/iTunes/iTunesPrefs.xml");
        try
        {
            NSDictionary rootDict = (NSDictionary) PropertyListParser.parse(prefsFile);
            NSDictionary userPrefs = (NSDictionary) rootDict.objectForKey("User Preferences");
            if(userPrefs!=null)
            {
                NSData options = (NSData) userPrefs.objectForKey("Documents:132");
                if(options!=null)
                {
                    String base64 = options.getBase64EncodedData();
                    System.out.println("optionBase54Data:"+base64);
                    String optionData = new String(Base64.decodeBase64(base64));
                    System.out.println("optionData:"+optionData);
                    return true;
                }
            }
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
        return false;
    }

主要输出空格(AAAA)

选项Base54Data:AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAV09SQjQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAADUXX4fAc2UWH8BAAAAAAAAAAAAAAAAAAAAAAAAAAAA啊啊啊啊啊啊啊啊啊=

加上嵌入在输出中

WORB4

�]~͔X

可以在此处找到 iTunes 首选项文件的示例

http://www.jthink.net/jaikoz/scratch/iTunesPrefs.xml

4

1 回答 1

0

我复制了设置打开和关闭的 iTunesPrefs.xml,然后比较了差异。

选中它(真)

Base64 编码:AAAAAAAAAAEAAAAGAQAA/////wEAAHoAAP////8EAEYAbABhAHQAAAAAAAAA

十六进制值:02 01 06 01 01 7a 04 46 6c 61 74

没有检查它(假)

Base64编码:AAAAAAAAAAEAAAAGAQAA/////wEAAHsAAP////8EAEYAbABhAHQAAAAAAAAA

十六进制值:02 01 06 01 01 7b 04 46 6c 61 74

这包含在 Preferences:130 下,这些值是如何存储的我不知道,也许你可以在这找到一些东西。考虑使用命令行来查找文件中的差异,diff适用于 linux 或fcwindows。

我知道这不是答案,但这不适合评论。

于 2013-09-21T22:55:53.283 回答