#!/bin/sh
#
# ==============================================================================
# SVT Play by Sveriges Television for Xtreamer Media Player & Streamer
# ==============================================================================
#
# This project allows to watch content brom SVT Play is the brand used for the
# video on demand service offered by Sveriges Television.
#
# Scraper based on SVT Play plugin for XBMC, xbmc-svtplay, code.google.com/p/xbmc-svtplay/
#
# Licence: GNU General Public License v2
# http://www.gnu.org/licenses/gpl.html
#
# Do not remove or change any header comments! Respect our work!
#
# If you are satisfied with my work you can support it with small donation
#   https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=SB8WDDAWY5YZE&lc=SI&item_name=xJukebox&item_number=ak5349jgdr&currency_code=EUR&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted  *
#
# Author: vpeter
#  http://forum.xtreamer.net/user/34082-vpeter/
#
# ==============================================================================
#

  # check number of arguments
  if [ $# -ne 1 ]; then
    exit
  fi

  OUTFILE="/tmp/usbmounts/sda1/x_SVTPLAY_SUBTITLE_x.srt"

  rm -f $OUTFILE
    
  # WSRT="http://media.svt.se/download/mcc/kluster/20110106/PG-1135329-001A-KSPECIALNILSP-06_sv.wsrt"
  WSRT=$1
  
  wget -O ${OUTFILE}.tmp $WSRT

	# wsrt have different timestamp format ('.' instead of ',')
	#   00:01:35.120 --> 00:01:40,720  
  sed 's|\([0-9]\{2\}:[0-9]\{2\}:[0-9]\{2\}\).\([0-9]\{3\}\) --> \([0-9]\{2\}:[0-9]\{2\}:[0-9]\{2\}\).\([0-9]\{3\}\).*|\1,\2 --> \3,\4|' ${OUTFILE}.tmp > ${OUTFILE}
  rm -f ${OUTFILE}.tmp
