好吧,实际上,.itc2 文件名的第二部分应该是iTunes Library.xml文件中的曲目持久 id。也许您有已删除曲目的图稿缓存?
可以通过以下方式从 XML 库中检索到的信息计算出艺术品的路径:
[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 魔法找到自己的出路。
检查下面的 java 代码,它将转换iTunes Library.xml并将计算出的艺术品路径以及艺术家和曲目名称放在output.xml中:
测试.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")));
}
}
和转换.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>