Create nfo files from tags
#1
I was a bit disappointed that no scraper allowed using file tags to populate library so decided to try a workaround: a script that generates NFO files based on tags. I'm sharing it in hope it will be useful to someone else. You can run it directly on Linux, possibly Mac OS, for Windows it requires setting up WSL. It comes with two files:

1) an actual script that you run musicvideo-nfo

sh:

#!/bin/sh

change_extension() {
    local ext path dir file out
    ext=$1 path=$2
    case $path in
        */*)
            dir=${path%/*}
            file=${path##*/}
            out=$dir/${file%.*}
            ;;
        *)
            out=${arg%.*}
    esac
    printf %s "$out.$ext"
}

for arg; do
    ! [ -f "$arg" ] && {
        echo >&2 "Error: Argument doesn't exist or is not a regular file: $arg"
        exit 1
    }
    out=$(change_extension nfo "$arg")
    ffprobe -v fatal -show_entries format_tags -of xml -- "$arg" |
    xsltproc -o "$out" ~/src/kodi/musicvideo-nfo.xslt -
done

2) XML transformation stylesheet which you need to put in fixed location: ~/src/kodi/musicvideo-nfo.xslt (or you can change the path to some other in the script above)

xml:

<?xml version="1.0" encoding="UTF-8"?>
<xslConfusedtylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
    <xslConfusedtrip-space elements="*" />
    <xsl:template match="/ffprobe/format">
        <musicvideo>
            <artist><xsl:value-of select="tag[@key='artist' or @key='ARTIST']/@value" /></artist>
            <title><xsl:value-of select="tag[@key='title' or @key='TITLE']/@value" /></title>
            <year><xsl:value-of select="tag[@key='date' or @key='DATE_RELEASED']/@value" /></year>
            <album><xsl:value-of select="tag[@key='album']/@value" /></album>
            <track><xsl:value-of select="tag[@key='track' or @key='PART_NUMBER']/@value" /></track>
            <genre><xsl:value-of select="tag[@key='genre' or @key='GENRE']/@value" /></genre>
            <plot><xsl:value-of select="tag[@key='comment' or @key='COMMENT']/@value" /></plot>
        </musicvideo>
    </xsl:template>    
</xslConfusedtylesheet>

Before you use it make sure you have ffmpeg and xsltproc packages installed. Then you can run script by giving it paths to video files e.g. ./musicvideo-nfo ~/Videos/*.mp4 ~/Videos/*.webm. Be careful because it will overwrite any existing nfo files so don't use it if you hand written them!
Reply

Logout Mark Read Team Forum Stats Members Help
Create nfo files from tags0