链接iTunes的ITC2文件和“iTunesLibrary.XML”

前端之家收集整理的这篇文章主要介绍了链接iTunes的ITC2文件和“iTunesLibrary.XML”前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试从iTunes的.ITC2文件中转储专辑图片.我能做到的女巫.但在我尝试转储图像之前,我需要记下它对应的Album / Track / Artist(三者中的任何一个).有没有人发现他们是否改变了缓存文件的命名方式?因为文件名为“2100F8A77FA24601-F2E26C349A9AB861.itc2”,“2100F8A77FA24601”实际上是我的库ID,但在我的库的 XML文件中找不到“F2E26C349A9AB861”.有人可以向我解释如何将itc2文件与位于XML文件中的曲目相关联.

reference

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

谢谢,
Throdne

解决方法

实际上,.itc2文件名的第二部分应该是iTunes Library.xml文件中的track persistent 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 format,即XML完成wrong.
不过,你可以通过一些XSLT巫术找到自己的方式.

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

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:

<?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,'-',$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>
原文链接:https://www.f2er.com/iOS/333535.html

猜你在找的iOS相关文章