#!/bin/bash wget "ftp://uptele:JCtHc3mQ866QL8rd@ftp.tvmedia.ca/xmltv.xml" -O /data/xmltv.xml id_list="/data/channel_keep_list.txt" raw="/data/xmltv.xml" parse_output="/data/parsed_new_epg.xml" update_output="/data/updated_new_epg.xml" format_output="/data/formatted_new_epg.xml" final_output="/data/ep_corrected_new_epg.xml" rm $parse_output $update_output $format_output # XPATHs pour trouver les channels/programmes dans id_list channel_id_xpath=$(awk '{printf "@id='\''%s'\'' or ", $0}' "$id_list" | sed 's/ or $//') programme_channel_xpath=$(awk '{printf "@channel='\''%s'\'' or ", $0}' "$id_list" | sed 's/ or $//') # Parse les XMLs complets avec les XPATHs pour copier seulement les channels et programmes dans id_list { echo '' xmlstarlet sel -t -c "//channel[$channel_id_xpath]" "$raw" xmlstarlet sel -t -c "//programme[$programme_channel_xpath]" "$raw" echo '' } > "$parse_output" if [ -f "/tmp/newtmpxmltv.xml" ]; then rm /tmp/newtmpxmltv.xml fi # On change les channels-id d'UpTélé pour concorder avec ceux dans notre Ministra cp $parse_output /tmp/tmpxmltv.xml while read LINE; do OLD_CHANNEL_ID=$(echo $LINE | awk '{print $1}') NEW_CHANNEL_ID=$(echo $LINE | awk '{print $2}') #sed -i "s/$OLD_CHANNEL_ID/$NEW_CHANNEL_ID/g" xmltv.xml awk -v old="$OLD_CHANNEL_ID" -v new="$NEW_CHANNEL_ID" '{gsub(old, new); print}' /tmp/tmpxmltv.xml >> /tmp/newtmpxmltv.xml rm /tmp/tmpxmltv.xml mv /tmp/newtmpxmltv.xml /tmp/tmpxmltv.xml done < channels_translate.txt mv /tmp/tmpxmltv.xml $update_output # On ajuste/ajoute l'élément pour être en format S00E00 xmlstarlet tr -s /opt/tmpl.xsl $update_output > $format_output # On format le xml pour un bon indent xmlstarlet fo -t $format_output > $final_output