#This script will convert Youtube xml timed text into standard SRT format, which most players can read. #Usage: ./script.sh inputfile sed '1,/body/d' <$1 | tr '\n' ' ' | sed "s/<\/p> /\n/"g > tempfile.txt finalfile=$(echo "$1" | rev | cut -c 5- | rev ).srt while read -r line; do let linenumber=linenumber+1 initialtime=$(echo $line | awk '{print $2}' | cut -c 4- | rev | cut -c 2- | rev) duration=$(echo $line | awk '{print $3}' | cut -c 4- | rev | cut -c 2- | rev) phrase=$(echo $line | grep -o -P '(?<=\>).*') printf "$linenumber\n$(date -d @$(echo "scale=2; $initialtime/1000" | bc | awk '{printf "%f", $0}' ) -u +%H:%M:%S,%3N) --> $(date -d @$(echo "scale=2; ($initialtime+$duration)/1000" | bc | awk '{printf "%f", $0}' ) -u +%H:%M:%S,%3N)\n" printf '%s\n\n' "$phrase" | sed "s/\'/\'/"g | sed "s/\"\;/\"/"g | sed "s/\>/\-/"g | sed "s/\&/\&/"g done "$finalfile" rm tempfile.txt