Currently we have a template.xml that is loaded by TG then filled with infos and then rendered using the rendering engine.
Optionally it is possible now to place a template.xslt file near the template.xml. This will change the processing flow as following:
Template.xml (with tokens)-> TG fills the tokens -> if template.xslt exists -> TG applies the XSL to the filled-up xml -> render the result
Author of the template/XSL must be very careful with the result of his transformation as that one is sent to the rendering engine. I recommend doing an identity copy and then processing individual cases.
I also recommend checking log.txt when something goes wrong as most of the errors are logged there.
The XSL transformation is optional and may help defining conditions and other tasks right before rendering.
Here is a sample of an XSL file (it is complete, you can use it as start point):
- Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="//Elements">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
<xsl:choose>
<xsl:when test="//tokens/token[@name='%SUBTITLES4%'] = '' ">
<TextElement Name="Sub4Missing" X="150" Y="100" Width="1076" Height="51" AutoSize="False" Multiline="False" Font="Arial Narrow,22,True,False,False,False,Point,,0" ForeColor="-16728065" StrokeColor="-16777216" StrokeWidth="0" Text="Subtitle 4 is empty" TextAlignment="TopLeft" TextQuality="AntiAlias"/>
</xsl:when>
</xsl:choose>
<TextElement Name="AddedViaTemplate" X="150" Y="0" Width="1076" Height="51" AutoSize="False" Multiline="False" Font="Arial Narrow,41,True,False,False,False,Point,,0" ForeColor="-16728065" StrokeColor="-16777216" StrokeWidth="0" Text="I AM A DYNAMIC ELEMENT" TextAlignment="TopLeft" TextQuality="AntiAlias"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Basically the transformation copies the initial XML, then if the token named %SUBTITLES4% is empty adds a new TextElement and at the end add always a TextElement with some demo text inside.
The input XML processed by this transformation looks like: (the content was stripped out to show just interesting elements)
- Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<ImageDrawTemplate SDKVersion="2.0">
<OutputImageSettings ColorDepth="Format32bppAlpha" ImageFormat="Jpeg" JpegCompressionLevel="80" Dpi="96" />
<Canvas AutoSize="False" CenterElements="False" Height="720" Width="1280" Fill="Solid,16777215,-16777216,BackwardDiagonal,-1,-16777216,0,,Tile,None,50,100,,,,0,0,0,0,Line,True" />
<Elements>
<ImageElement Name="Background" X="0" Y="0" Width="1280" Height="720" Source="File" Offset="0" MultiPageIndex="-1" SourceData="C:\Documents and Settings\Radu\My Documents\Visual Studio 2008\Projects\ThumbGen(1)\bin\Debug\Templates\NeatSheet_AllBlack_1280x720\black.bmp" NullImageUrl="" />
<ImageElement Name="S" X="237" Y="615" Width="50" Height="50" Source="File" Offset="0" MultiPageIndex="-1" SourceData="C:\Documents and Settings\Radu\My Documents\Visual Studio 2008\Projects\ThumbGen(1)\bin\Debug\Templates\NeatSheet_AllBlack_1280x720\s.png" NullImageUrl="" />
</Elements>
<tokens>
<token name="%STUDIOS%">Barbarian Films</token>
<token name="%EXTERNALSUBTITLESTEXT%">Espa&#241;ol/Rom&#226;na</token>
<token name="%SUBTITLESTEXT%">Rom&#226;na</token>
<token name="%VIDEOFORMATTEXT%" />
<token name="%AUDIOCHANNELSTEXT%">2</token>
<token name="%EPISODE%" />
<token name="%FRAMERATETEXT%">23.976</token>
<token name="%CONTAINERTEXT%">Matroska</token>
<token name="%AUDIOCODECTEXT%">MP3</token>
<token name="%FANART1%">c:\temp\8e1324a0-e184-4848-b7b8-0915fb2d12e8.jpg</token>
<token name="%PATH%">C:\Documents and Settings\Radu\My Documents\Visual Studio 2008\Projects\ThumbGen(1)\bin\Debug\Templates\NeatSheet_AllBlack_1280x720</token>
<token name="%RUNTIME%">97</token>
<token name="%COVER%">c:\temp\d5bba67f-eae3-4bfd-942c-80eb8ab38d37.jpg</token>
<token name="%YEAR%">2009</token>
<token name="%MEDIAFORMATTEXT%">MKV</token>
<token name="%TITLE%">Spread</token>
<token name="%RATING%">6.1/10</token>
<token name="%SUBTITLES2%" />
<token name="%EXTERNALSUBTITLES4%" />
<token name="%EXTERNALSUBTITLES3%" />
<token name="%DURATIONTEXT%">1h 36m</token>
<token name="%VIDEORESOLUTIONTEXT%">768x576</token>
<token name="%AUDIOBITRATETEXT%">128 Kbps</token>
<token name="%TITLEPATH%">D:\Test\Spread</token>
<token name="%DIRECTORS%">David Mackenzie</token>
<token name="%SUBTITLES3%" />
<token name="%SUBTITLES4%" />
<token name="%EXTERNALSUBTITLES2%">Romanian</token>
<token name="%ORIGINALTITLE%">Spread</token>
<token name="%FANART2%">c:\temp\1339521c-cd5d-4ae4-b373-60c42eb870ff.jpg</token>
<token name="%SUBTITLES5%" />
<token name="%SOUNDFORMATTEXT%">All Mpeg</token>
<token name="%PLOT%">A sex comedy centered on a serial womanizer and his jilted lover.</token>
<token name="%COUNTRIES%">USA</token>
<token name="%GENRES%">Comedy, Drama, Romance</token>
<token name="%CERTIFICATION%">R</token>
<token name="%SUBTITLES%">Romanian</token>
<token name="%FILESIZETEXT%">781.95 MB</token>
<token name="%BACKGROUND%">c:\temp\784256ad-7c68-4c4f-95fc-ff8e45629907.jpg</token>
<token name="%MPAA%">Rated R for strong sexual content, nudity and language</token>
<token name="%SUBTITLES1%">Romanian</token>
<token name="%FRAMERATE%">23_976</token>
<token name="%EXTERNALSUBTITLES1%">Spanish</token>
<token name="%VIDEOCODECTEXT%">AVC</token>
<token name="%CERTIFICATIONTEXT%">R</token>
<token name="%ASPECTRATIO%">16-9</token>
<token name="%ACTORS%">Ashton Kutcher, Anne Heche, Margarita Levieva, Sebastian Stan</token>
<token name="%RELEASEDATE%">17.01.2009</token>
<token name="%ASPECTRATIOTEXT%">16:9</token>
<token name="%VIDEORESOLUTION%">768x576</token>
<token name="%VIDEOBITRATETEXT%">977 Kbps</token>
<token name="%RESOLUTIONTEXT%" />
<token name="%EXTERNALSUBTITLES5%" />
<token name="%SEASON%" />
<token name="%FANART3%">c:\temp\0271d22d-d4f2-41b4-92bb-345daba0c679.jpg</token>
<token name="%EXTERNALSUBTITLES%">Spanish/Romanian</token>
</tokens>
</ImageDrawTemplate>
The XML sent to the rendering engine after applying the transformation can be seen in the new "Test template" dialog in ThumbGen and will look like (the content was stripped out to show just interesting elements):
- Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<ImageDrawTemplate SDKVersion="2.0">
<OutputImageSettings ColorDepth="Format32bppAlpha" ImageFormat="Jpeg" JpegCompressionLevel="80" Dpi="96"/>
<Canvas AutoSize="False" CenterElements="False" Height="720" Width="1280" Fill="Solid,16777215,-16777216,BackwardDiagonal,-1,-16777216,0,,Tile,None,50,100,,,,0,0,0,0,Line,True"/>
<Elements>
<ImageElement Name="Background" X="0" Y="0" Width="1280" Height="720" Source="File" Offset="0" MultiPageIndex="-1" SourceData="C:\Documents and Settings\Radu\My Documents\Visual Studio 2008\Projects\ThumbGen(1)\bin\Debug\Templates\NeatSheet_AllBlack_1280x720\black.bmp" NullImageUrl=""/>
<ImageElement Name="S" X="237" Y="615" Width="50" Height="50" Source="File" Offset="0" MultiPageIndex="-1" SourceData="C:\Documents and Settings\Radu\My Documents\Visual Studio 2008\Projects\ThumbGen(1)\bin\Debug\Templates\NeatSheet_AllBlack_1280x720\s.png" NullImageUrl=""/>
<TextElement Name="Sub4Missing" X="150" Y="100" Width="1076" Height="51" AutoSize="False" Multiline="False" Font="Arial Narrow,22,True,False,False,False,Point,,0" ForeColor="-16728065" StrokeColor="-16777216" StrokeWidth="0" Text="Subtitle 4 is empty" TextAlignment="TopLeft" TextQuality="AntiAlias"/>
<TextElement Name="AddedViaTemplate" X="150" Y="0" Width="1076" Height="51" AutoSize="False" Multiline="False" Font="Arial Narrow,41,True,False,False,False,Point,,0" ForeColor="-16728065" StrokeColor="-16777216" StrokeWidth="0" Text="I AM A DYNAMIC ELEMENT" TextAlignment="TopLeft" TextQuality="AntiAlias"/>
</Elements>
<tokens>
<token name="%STUDIOS%">Barbarian Films</token>
............
</tokens>
</ImageDrawTemplate>
In the near future I will add near the <tokens> node a new <mediainfo> node will COMPLETE data extracted from mediainfo. That way inside the XSL transformation you have access to all media flags as they are generated by mediainfo.



