Sunday, January 06, 2013

XBMC and overlapping subtitles with iPlayer addon

There's often overlapping subtitles with XBMC and BBC iPlayer addon. Rather than modify actual addon and losing changes every time it's updated I hacked up script that edits SRT file after it's downloaded from BBC site but before XBMC reads it.



# Install inotify-tools
apt-get update
apt-get -y install inotify-tools

# Download perl script to mangle sub timings
cd /home/xbmc
wget http://dump.asiantuntijakaveri.fi/le_bueno_dumpo/subeau.pl
#or
#wget https://subeautifuler.googlecode.com/svn/trunk/src/subeau.pl

# Create background processing script
cat <<'__EOF__' >/home/xbmc/iplayersubfix.sh
#!/bin/bash
#
# Default location for iplayer subs
cd "/home/xbmc/.xbmc/userdata/addon_data/plugin.video.iplayer/Subtitles/"
#
# Infinite loop
while true
do
 # Use inotify to monitor changes on disk
 inotifywait -e create,modify iplayer.srt
 # Don't proceed until xbmc has finished writing subs to file
 while lsof iplayer.srt
 do
  # wait 100ms until next check
  sleep 0.100
 done
 # fix overlapping subs
 perl ~/subeau.pl -f -u -dd iplayer.srt
 # save original subs
 mv -f iplayer.srt iplayer.original.srt 
 # and use our new fixed ones as default
 mv -f iplayer.1.srt iplayer.srt
 # Cleanup
 rm -f iplayer.1.iso8859.srt iplayer.1.notag.iso8859.srt iplayer.1.notag.srt
done
#
__EOF__

# Make script executable
chmod a+x /home/xbmc/iplayersubfix.sh

# Launch script on background when system is restarted
echo 'su -l -c "/bin/bash /home/xbmc/iplayersubfix.sh" xbmc &' >>/etc/rc.local

No comments:

Post a Comment

Got something to say?!