Refactor parsing to not use readarray

This commit is contained in:
Shahin Agha-Ghassem 2023-04-02 20:19:22 +02:00
parent 44c3cd2a0c
commit 83922cc823

28
iptv
View File

@ -30,26 +30,18 @@ save_channels() {
printf "Parsing channels... " printf "Parsing channels... "
channels=() channels=()
readarray -t lines < "$tmp_playlist" url=""
for (( i=0; i<${#lines[@]}; i++ )); do
line1="${lines[i]}"
line2="${lines[i+1]}"
line3="${lines[i+2]}"
if [[ "$line2" == http* ]]; then while IFS= read -r line; do
url="$line2" if [[ "$line" == http* ]]; then
elif [[ "$line3" == http* ]]; then url="$line"
url="$line3" elif [[ "$line" =~ tvg-name=\"([^\"]+)\" || "$line" =~ tvg-id=\"([^\"]+)\" ]]; then
fi name="${BASH_REMATCH[1]}"
channels+=("$name [CH:${#channels[@]}] url:$url")
url=""
fi
done < "$tmp_playlist"
if [[ "$line1" =~ tvg-name=\"([^\"]+)\" ]]; then
name="${BASH_REMATCH[1]}"
channels+=("$name [CH:$i] url:$url")
elif [[ "$line1" =~ tvg-id=\"([^\"]+)\" ]]; then
name="${BASH_REMATCH[1]}"
channels+=("$name [CH:$i] url:$url")
fi
done
printf "Done!\n" printf "Done!\n"
printf "%s\n" "${channels[@]}" > $channels_file printf "%s\n" "${channels[@]}" > $channels_file