exporting the media list to csv/excel format
#1
I created an xsl script that automates extracting a csv format file from the export of a kodi video database (videodb.xml).
If there's any interest I'll make it available. It's used from the command line so you can automate using it.

To use it you need an xsl processor. On Linux you can install 'xalan' from your software package manager. On Windows you can use the free Microsoft utility 'msxsl',

I plan to create another script which will compare two library exports, detect what's new, and automate copying new files to backup media.
Reply
#2
Oh I'd love to take a look at that if you could be so kind. The comparison feature would be great as well if you manage to figure it out.

I've been trying to think of a way to scan and insert file sizes into the kodi export/videodb.xml file. (have had some disks die in my server and I've been trying to putz around with spreadsheets to use as an easy catalog to double check my file recovery). But it's way beyond me.
Reply
#3
Hey booker,
I don't see a way to attach a file here. It's small so I'll just post it in a second reply.

It uses the xsl language which was designed to manipulate xml files.
You'll need an xsl interpreter. There are free versions for all operating systems.
For Windows one option is msxsl from microsoft: http://www.microsoft.com/en-us/download/...x?id=21714):
For Linux "xalan" should be available from your software repository

This one does television shows. It exports the title, season, episode number, and unique id. It would be very simple to add the file size if you need it.
An almost identical script can do movies. I did them separately since they're just different enough.
  • from Kodi go to Video->library->export (as one file)
  • That should create a "videodb.xml" file
  • You'll need to modify the examples below by adding a path so the "videodb.xml" file can be found

Example for Windows:

msxsl videodb.xml VideodbToTvShowsCsv.xslt -o tvshows.csv

Example for linux:

cat videodb.xml | xalan -xsl VideodbToTvShowsCsv.xslt -out tvshows.csv
Reply
#4
Code:
<!--
This xsl produces a csv format list of kodi tv show content.
It is used from the command line so it's use can be automated

Example for Windows (Assumes msxsl from microsoft is installed.   http://www.microsoft.com/en-us/download/details.aspx?id=21714):

    msxsl videodb.xml VideodbToTvShowsCsv.xslt -o tvshows.csv

    
Example for linux (Assumes "xalan" is installed. Should be available from your software repository):

    cat videodb.xml | xalan -xsl VideodbToTvShowsCsv.xslt -out tvshows.csv
    
written by Jay Sprenkle    
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="text" encoding="us-ascii"/>

    <!-- television shows-->
    <xsl:template match="tvshow/episodedetails">
         <!--show title-->
        <xsl:text>"</xsl:text>
        <xsl:value-of select='../title/text()'/>
        <xsl:text>"</xsl:text>
        <xsl:text>,</xsl:text>

        <xsl:value-of select='season/text()'/>
        <xsl:text>,</xsl:text>

        <xsl:value-of select='episode/text()'/>
        <xsl:text>,</xsl:text>

         <!--Episode title-->
        <xsl:text>"</xsl:text>
        <xsl:value-of select='title/text()'/>
        <xsl:text>"</xsl:text>
        <xsl:text>,</xsl:text>

        <xsl:value-of select='uniqueid/text()'/>

        <xsl:text>&#xa;</xsl:text>
    </xsl:template>

    <xsl:template match="/videodb">
        <xsl:text>"Show Title"</xsl:text>
        <xsl:text>,</xsl:text>

        <xsl:text>"season"</xsl:text>
        <xsl:text>,</xsl:text>

        <xsl:text>"episode"</xsl:text>
        <xsl:text>,</xsl:text>
        
        <xsl:text>"Episode Title"</xsl:text>
        <xsl:text>,</xsl:text>

        <xsl:text>"uniqueid"</xsl:text>

        <xsl:text>&#xa;</xsl:text>
        
        <xsl:apply-templates select="tvshow/episodedetails"/>
    </xsl:template>

</xsl:stylesheet>
Reply
#5
Thanks! I'll give it a go later on.

Cheers.
Reply
#6
The script to keep your backup up to date is done. It wasn't too bad to write.
This xslt script compares the content of two kodi exported video libraries to determine which movies were added to the video database.
It produces a script to copy the new content to backup media.
The copy script is an xml document used by the cpXmlCmd application.
It should be trivial to change to create batch files, shell scripts, powershell scripts, etc.

I will release all the source and binaries for the cpXmlCmd application shortly.

Save the following to a file named "Videodb.Additions.xslt"
Code:
<!--
    This xslt script compares the content of two kodi exported video libraries to determine which movies were added to the video database.
    It produces a script to copy the new content to backup media.

    Microsoft windows command line example:

      msxsl 2015-06-01\videodb.xml -o backup.xml Videodb.Additions.xslt newer="2015-06-08\videodb.xml" backup="j:\backup"

      msxsl parameters to use this script:
      1. The file name of the older kodi videodb document ( example: 2015-06-01\videodb.xml )
      2. Output file name for the copy script ( example: -o backup.xml )
      3. The file name of the newer kodi videodb document ( example: newer="2015-06-08\videodb.xml" )
      4. A path where backups go ( backup="j:\backup" )

      Notes:
      * This example uses the microsoft xsl interpreter named 'msxsl'. There are many other interpreters that this script
        will probably work with. If you use another interpreter the command line will need to be changed.
      * The first document should be produced chronologically before the newer second document.
      * The copy script is an xml document used by the cpXmlCmd application.
      * Individual movies will be placed in a separate directory for each movie in the backup.
      * uses Version 1 of the videodb.xml file.

    Linux example Using xalan:
      xalan 2015-06-01/videodb..xml -p newer "2015-06-08/videodb.xml" -p backup "/mnt/backup" Videodb.Additions.xslt -o backup.xml

    written by Jay Sprenkle
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:output omit-xml-declaration="yes" indent="yes" encoding="utf-8"/>

  <xsl:param name="newer" select="'videodb.xml'"/>
  <xsl:param name="backup" select="'j:\backup'"/>

  <!--do not copy unmatched test-->
  <xsl:template match="text()|@*" />

  <!--The first document. Not a named parameter-->
  <xsl:variable name="olderVideoDb" select="/videodb[version/text()='1']" />

  <!--The 'newer' parameter on the command line-->
  <xsl:variable name="doc1" select="document( $newer )" />
  <xsl:variable name="newerVideoDb" select="$doc1/videodb[version/text()='1']" />

  <xsl:template match="/videodb">

    <!--find all nodes in the newer document with id's not present in the older document-->
    <xsl:variable name="added" select="$newerVideoDb/movie[ not( $olderVideoDb/movie/id/text() = id/text() ) ]" />

    <cpXmlCmd xmlns="http://www.XmlCommandLine.org/cpXmlCmd/1.0">
      <Content>
        <xsl:for-each select="$added">
          <xsl:variable name="filenameandpath" select="filenameandpath/text()" />
          <xsl:variable name="filename" select="substring( $filenameandpath, string-length(path/text()) + 1 )" />
          <cp>
            <xsl:attribute name="source" >
              <xsl:value-of select="$filenameandpath"/>
            </xsl:attribute>
            <xsl:attribute name="destination" >
              <xsl:value-of select="$backup"/>
              <xsl:text>/</xsl:text>
              <xsl:value-of select="title/text()"/>
              <xsl:text>/</xsl:text>
              <xsl:value-of select="$filename"/>
            </xsl:attribute>
          </cp>
        </xsl:for-each>
      </Content>
    </cpXmlCmd>
  </xsl:template>

</xsl:stylesheet>
Reply

Logout Mark Read Team Forum Stats Members Help
exporting the media list to csv/excel format0