Merge pull request #2 from shahin8r/refactor-parsing-to-not-use-readarray

Refactor parsing to not use readarray
This commit is contained in:
Shahin Agha-Ghassem 2023-04-02 20:20:43 +02:00 committed by GitHub
commit f2c5095721
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

26
iptv
View File

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