链接iTunes的ITC2文件和“iTunesLibrary.XML”。 [英] Linking iTunes' ITC2 files and "iTunesLibrary.XML"

查看:116
本文介绍了链接iTunes的ITC2文件和“iTunesLibrary.XML”。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从iTunes的.ITC2文件转储专辑图片。我能做到的女巫。但在我尝试转储图像之前,我需要记下它对应的Album / Track / Artist(三者中的任何一个)。有没有人发现他们是否改变了缓存文件的命名方式?因为文件名为2100F8A77FA24601-F2E26C349A9AB861.itc2,2100F8A77FA24601实际上是我的库ID,但在我的库的XML文件中找不到F2E26C349A9AB861。有人可以向我解释如何将itc2文件与位于XML文件中的曲目相关联。

I'm trying to dump album artwork from iTunes' .ITC2 files. Witch I can do. But before I try and dump the image, I need to make note of what Album/Track/Artist (any of the three) that it corresponds to. Has anyone found out if they changed the way the cache files are named? Because, with a file name of "2100F8A77FA24601-F2E26C349A9AB861.itc2" "2100F8A77FA24601" is in fact my Library ID but "F2E26C349A9AB861" is nowhere to be found in my Library's XML file. Can someone explain to me how to correlate itc2 files with tracks that are located in the XML file.

参考

我确实从上面的链接获得了有关如何设置iTunes的一些信息。但这篇文章已经过时,并不是100%正确到今天的iTunes版本(第11版)。

I did get a little information about how iTunes is setup from the above link. But this post is outdated and not 100% correct to today's version of iTunes (v11).

谢谢,
Throdne

Thanks, Throdne

推荐答案

实际上,.itc2文件名的第二部分应该是 iTunes Library.xml 中的track持久性id文件。也许您有已删除曲目的图稿缓存?

Well, actually, the second part of the .itc2 file name should be the track persistent id that is inside the iTunes Library.xml file. Perhaps you have the artwork cache for a deleted track?

图稿的路径可以通过以下方式从XML库中检索到的信息计算:

The path to the artwork can be calculated from information retrieved from the XML library in this way:

[itunes library folder]/Album Artwork/Cache/[Library Persistent ID]/XX/YY/ZZ/[Library Persistent ID - Track Persistent ID].itc2

其中:

    XX: First hex digit from the end in the track persistent id in decimal form
    YY: Second hex digit from the end in the track persistent id in decimal form
    ZZ: Third hex digit from the end in the track persistent id in decimal form

所以如果:

Library Persistent ID = BEAE1DB35624CB18
Track Persistent ID = 2488665ADBC5420F

然后文件夹是:

[itunes library folder]/Album Artwork/Cache/BEAE1DB35624CB18/15/00/02/BEAE1DB35624CB18-2488665ADBC5420F.itc2

iTunes XML库使用 plist xml格式,这是通过错误完成的XML。
不过,你可以通过一些XSLT法术找到你的方式。

The iTunes XML library uses the plist xml format, which is XML done wrong. Still, you can find your way thru with some XSLT sorcery.

检查下面的java代码,它将改变 iTunes Library.xml 并将计算出的图稿路径与艺术家和曲目名称一起放在 output.xml 中:

Check the java code below, that will transform the iTunes Library.xml and put the calculated artwork path, alongside artist and track name in output.xml:

Test.java:

Test.java:

import java.io.File;

import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;

public class Test {
    public static void main(String[] args) throws Exception {   
        String libraryFolder = "/Path/To/iTunes/";
        TransformerFactory factory = TransformerFactory.newInstance();
        Source xslt = new StreamSource(new File("convert.xsl"));
        Transformer transformer = factory.newTransformer(xslt);
        transformer.setParameter("library_folder", libraryFolder);
        Source text = new StreamSource(new File(libraryFolder + "iTunes Library.xml"));
        transformer.transform(text, new StreamResult(new File(libraryFolder  + "output.xml")));
    }
}

并且convert.xsl:

And convert.xsl:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output indent="yes"/>
    <xsl:param name="library_folder"/>
    <xsl:template match="plist">
        <xsl:variable name="libid">
            <xsl:value-of select="dict/key[. = 'Library Persistent ID']/following-sibling::string[1]"/>
        </xsl:variable>
        <tracks>
            <xsl:apply-templates select="dict/key[. = 'Tracks']/following-sibling::dict[1]/dict" mode="track">
                <xsl:with-param name="libid"><xsl:value-of select="$libid"/></xsl:with-param>
            </xsl:apply-templates>
        </tracks>
    </xsl:template>

    <xsl:template match="dict" mode="track">  
        <xsl:param name="libid" />
        <entry>
            <xsl:variable name="trackid">
                <xsl:value-of select="key[. = 'Persistent ID']/following-sibling::string[1]"/>
            </xsl:variable>
            <xsl:variable name="dig1">
                <xsl:call-template name="HexToDecimal">
                    <xsl:with-param name="hexNumber" select="substring($trackid, string-length($trackid))"/>
                </xsl:call-template>
            </xsl:variable>
            <xsl:variable name="dig2">
                <xsl:call-template name="HexToDecimal">
                    <xsl:with-param name="hexNumber" select="substring($trackid, string-length($trackid) - 1, 1)"/>
                </xsl:call-template>
            </xsl:variable>
            <xsl:variable name="dig3">
                <xsl:call-template name="HexToDecimal">
                    <xsl:with-param name="hexNumber" select="substring($trackid, string-length($trackid) - 2, 1)"/>
                </xsl:call-template>
            </xsl:variable>
            <artist><xsl:value-of select="key[. = 'Artist']/following-sibling::string[1]"/></artist>
            <name><xsl:value-of select="key[. = 'Name']/following-sibling::string[1]"/></name>
            <track_id><xsl:value-of select="$trackid"/></track_id>
            <artwork><xsl:value-of select="concat($library_folder, 'Album Artwork/Cache/',$libid,'/',$dig1,'/',$dig2,'/',$dig3,'/',$libid,'-',$trackid,'.itc2')"/></artwork>
        </entry>
    </xsl:template>

    <!-- Very simple hex to decimal, only one digit -->
    <xsl:template name="HexToDecimal">
        <xsl:param name="hexNumber" />
        <xsl:value-of select="format-number(number(substring-before(substring-after('00/11/22/33/44/55/66/77/88/99/A10/B11/C12/D13/E14/F15/a10/b11/c12/d13/e14/f15/', $hexNumber), '/')),'00')" />
    </xsl:template>

</xsl:stylesheet>

这篇关于链接iTunes的ITC2文件和“iTunesLibrary.XML”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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