#########################################################################################
#							
# RSS feed data converter for Auto DL software package.
#
# For: Public service of YLE Areena Finland																									#
#
# © Copyright 2012 Arto Jääskeläinen <temp001(at)pp.inet.fi>
# Part of Auto DL software package. All rights reserved.
# The program is distributed under the terms of the GNU General Public License
#
#    Auto DL is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    Auto DL is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with Auto DL.  If not, see <http://www.gnu.org/licenses/>.
#
# V1.0  2012-07-27
# V1.1  2012-10-11  Bux fixes &|
# V1.11 2012-10-16  Remove trailing \n
#
xml2tsv()
{
sed '/<?xml/,/item/d' $1 | grep -vie "<media" \
-e "<itunes" -e "dcterms:valid" -e "tvLicense" -e "<item>" -e "</rss>" -e "channel" \
| tr -d '[]!\r' |  tr '\t' ' ' | tr -s '\n '| sed 's/^[ \t]*//;s/[ \t]*$//' \
| tr '\n' '^' | sed 's/\^>/>/g; s/\^</</g' | tr '^' '\n' \
| sed 's/><\//<\//g;s/></>/g;s/CDATA//g;s/^[ \t]*//g;s/<\/item>/\n/g' \
| sed 's/^<//g' \
| sed 's/<[^>]*>/\t/g' \
| sed 's/guid[^>]*>/guid>/g' \
| sed 's/<\/.*//g; s/>/=/g;' \
| tr -s '\n' > $1.tsv
}
