Preparing for a boring flight - XPages.tv offline (Extract media from a feed)
David Leedy provides us with the incredible useful Notes in 9 (a.k.a XPages.tv) tutorials and insights about XPages and Notes. The feed with all the videos is hosted by feedburner. To enjoy them while off the grid you can subscribe to them using iTunes, but that's for Warmduscher .
I'll show you how to use curl and a shell script (easy to translate to a cmd file):
Update: Got a little carried away and used the wrong script, it only did XSLT 1.0, now corrected using Saxon and XSLT 2.0. Thx Ulrich for noticing.
As usual YMMV
I'll show you how to use curl and a shell script (easy to translate to a cmd file):
- First you download the feed:
curl -G -L -o notesin9.xml http://feeds.feedburner.com/notesin9/iTunes
- Run the transformation:
xslt notesin9.xml feedburner2curl.xslt getXPagesTV.sh
(on Windows you would use .cmd) - Make the script executable:
chmod +x getXPagesTV.sh
- Fetch the movies:
./getXPagesTV.sh
#!/bin/bash
notify-send -t 500 -u low -i gtk-dialog-info "Transforming $1 with $2 into $3 ..."
java -cp /home /stw /bin /saxon9he.jar net.sf.saxon.Transform -t -s: $1 -xsl: $2 -o: $3
notify-send -t 1000 -u low -i gtk-dialog-info "Extraction into $3 done!"
(where only the line with "java..." is relevant, the rest is eye candy). The XSLT stylesheet isn't much more complicated (the statements are in one line each, so check the download version to get them right):
notify-send -t 500 -u low -i gtk-dialog-info "Transforming $1 with $2 into $3 ..."
java -cp /home /stw /bin /saxon9he.jar net.sf.saxon.Transform -t -s: $1 -xsl: $2 -o: $3
notify-send -t 1000 -u low -i gtk-dialog-info "Extraction into $3 done!"
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:media="http://search.yahoo.com/mrss/"
version="2.0">
<xsl:output indent="no" method="text"/>
<xsl:template match="/">#!/bin/bash <xsl:apply-templates select="//media:content" /></xsl:template>
<xsl:template match="media:content">
curl -C - -G <xsl:value-of select="@url"/> -L -o <xsl:value-of select="reverse(tokenize(@url,'/'))[1]"/>
</xsl:template>
</xsl:stylesheet>
The only interesting part is <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:media="http://search.yahoo.com/mrss/"
version="2.0">
<xsl:output indent="no" method="text"/>
<xsl:template match="/">#!/bin/bash <xsl:apply-templates select="//media:content" /></xsl:template>
<xsl:template match="media:content">
curl -C - -G <xsl:value-of select="@url"/> -L -o <xsl:value-of select="reverse(tokenize(@url,'/'))[1]"/>
</xsl:template>
</xsl:stylesheet>
reverse(tokenize(@url,'/'))[1]
which I use to get the file name - basically the String after the last /. "tokenize" and "reverse" need a XSLT 2.0 processor.
Update: Got a little carried away and used the wrong script, it only did XSLT 1.0, now corrected using Saxon and XSLT 2.0. Thx Ulrich for noticing.
As usual YMMV
Posted by Stephan H Wissel on 02 March 2012 | Comments (3) | categories: XML XPages