43 lines
1.5 KiB
Bash
43 lines
1.5 KiB
Bash
#!/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"
|
|
|
|
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 '<tv source-info-name="UpTele">'
|
|
xmlstarlet sel -t -c "//channel[$channel_id_xpath]" "$raw"
|
|
xmlstarlet sel -t -c "//programme[$programme_channel_xpath]" "$raw"
|
|
echo '</tv>'
|
|
} > "$parse_output"
|
|
|
|
if [ -f "/tmp/newtmpxmltv.xml" ]; then
|
|
rm /tmp/newtmpxmltv.xml
|
|
fi
|
|
|
|
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 format le xml pour un bon indent
|
|
xmlstarlet fo -t $update_output > $format_output |