Some of you out there may know, I am using Ember MM to scrape my movies and TV episodes. One thing about that is, that Ember MM is kinda stupid doing so.

After the 9.10-release of XMBC, they apparently changed the XML format, introducting durationinseconds, which is basically like duration, just … yeah you guessed right, in seconds.

Now Ember MM doesn’t know that, and still writes the old duration-tag. Now, everytime when something goes kaboom! with my library, I do have to rescrape all my episodes and movies, which isn’t a big deal since the NFO’s are still on disk. However, since I didn’t watch them (as Ember doesn’t know about the lastplayed-tag) XBMC is not showing any runtime in the GUI. Now this isn’t annoying per se, but it was just bugging me (and since I got lots of spare time, due to being chained to the sofa).

So I ended up comparing exports of movie databases before and after playing back an episode and came up with a smallish shell script to do the rescanning and replacing of stuff for me.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/bash

if [ "$1" = "--force" ] ; then
        RESCAN_ALL=1
fi

IFS="
"

if [ $RESCAN_ALL ] ; then
        FILES="`grep -rl 'episodedetails' */*/*.nfo`"
else
        # Get a list of all NFO files having incorrect information
        FILES="`egrep -rli '((|0)|duration>)' */*/*.nfo`"
fi

for episode in $FILES; do
        # figure out the episode file extension
        tvepisode="`ls ${episode%.*}.* | egrep -i '(mkv|avi|mp4)'`"
        runtime="`mediainfo --Inform='Video;%Duration%' ${tvepisode} | cut -d  -f1-2`"
        runtime_in_s=`echo "scale=0; $runtime/1000" | bc`

        # Get the old duration if possible
        old_line="`grep duration $episode | cut -d  -f9- | tail -n1`"
        new_line="$runtime_in_s"

        shopt -q -s extglob
        echo "Updating episode information in $episode"
        if [ -z $old_line ] ; then
                sudo sed -i "s,0,$new_line," $episode
                sudo sed -i "s,,$new_line," $episode
        else
                sudo sed -i "s,${old_line##+([[:space:]])},$new_line,g" $episode
        fi
        shopt -q -u extglob
done

Since Ember doesn’t provide anything like hooks or “post-scraping”, this is the only way I can think of doing this. If anyone has a smarter idea, I’m all ears.