wissel.net

Usability - Productivity - Business - The web - Singapore & Twins

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):
  1. First you download the feed: curl -G -L -o notesin9.xml http://feeds.feedburner.com/notesin9/iTunes
  2. Run the transformation: xslt notesin9.xml feedburner2curl.xslt getXPagesTV.sh (on Windows you would use .cmd)
  3. Make the script executable: chmod +x getXPagesTV.sh
  4. Fetch the movies: ./getXPagesTV.sh
This technique works for any media RSS feed (ATOM wouldn need a different XSLT), so it is worth to be added to the toolbox. There are a few moving parts (which you should have anyway): You need to have curl and a XSLT shell script (that uses a jar file) as well as the stylesheet to convert the feed into a command file. The XSLT command file looks like this:
#!/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):
<?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 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 on 02 March 2012 | Comments (3) | categories: XML XPages

Comments

  1. posted by Ulrich Krause on Saturday 03 March 2012 AD:
    Getting an error; any advice?

    C:\tools\ni9>java -jar XSLTHelper.jar notesin9.xml feedburner2curl.xslt getXPagesTV.sh
    FEHLER: 'Fehler beim ???berpr³fen des Typs des Ausdrucks 'funcall(tokenize, [step("attribute", 15), literal-expr(/)])'.'
    SCHWER WIEGENDER FEHLER: 'Die Formatvorlage konnte nicht kompiliert werden.'
    javax.xml.transform.TransformerConfigurationException: Die Formatvorlage konnte nicht kompiliert werden.
    at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTemplates(Unknown Source)
    at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTransformer(Unknown Source)
    at com.ibm.tools.XSLTHelper.transform(XSLTHelper.java:126)
    at com.ibm.tools.XSLTHelper.main(XSLTHelper.java:80)
    Transformed notesin9.xml with feedburner2curl.xslt into getXPagesTV.sh
  2. posted by Thomas Gumz on Saturday 03 March 2012 AD:
    If using iTunes for this is for warmduscher, then... using curl + XSLT + a jar + CSS + shellscripts is *clearly* for masochists Emoticon rolleyes.gif
  3. posted by Stephan H. Wissel on Monday 05 March 2012 AD:
    @Ulrich: Script corrected, got the wrong one there initially

    @Thomas: Yes, absolutely. But I would still claim it is less masochistic than sitting through 2 hours of American Idol or Survivor on TV.

    Emoticon biggrin.gif stw