Handle playlists that group by three lines

This commit is contained in:
Shahin Agha-Ghassem 2023-03-19 21:30:18 +01:00
parent 27cf88b1d2
commit bbed9f89f2

20
iptv
View File

@ -18,19 +18,29 @@ fi
if [ ! -z "$m3u" ]; then if [ ! -z "$m3u" ]; then
printf "\nLoading channels... " printf "\nLoading channels... "
curl -s $m3u | grep EXTINF: -A 1 > $tmp_playlist curl -s $m3u | grep EXTINF: -A 2 > $tmp_playlist
printf "Done!\n" printf "Done!\n"
printf "Parsing channels... " printf "Parsing channels... "
channels=() channels=()
readarray -t lines < "$tmp_playlist" readarray -t lines < "$tmp_playlist"
for (( i=0; i<${#lines[@]}; i+=2 )); do for (( i=0; i<${#lines[@]}; i+=3 )); do
line="${lines[i]}" line1="${lines[i]}"
line2="${lines[i+1]}" line2="${lines[i+1]}"
line3="${lines[i+2]}"
if [[ "$line" =~ tvg-name=\"([^\"]+)\" ]]; then if [[ "$line2" == http* ]]; then
url="$line2"
elif [[ "$line3" == http* ]]; then
url="$line3"
fi
if [[ "$line1" =~ tvg-name=\"([^\"]+)\" ]]; then
name="${BASH_REMATCH[1]}" name="${BASH_REMATCH[1]}"
channels+=("$name [CH:$i] url:$line2") channels+=("$name [CH:$i] url:$url")
elif [[ "$line1" =~ tvg-id=\"([^\"]+)\" ]]; then
name="${BASH_REMATCH[1]}"
channels+=("$name [CH:$i] url:$url")
fi fi
done done
printf "Done!\n" printf "Done!\n"