Rewrite to use fzf
This commit is contained in:
parent
d7f7c4c263
commit
8e851a5f8f
51
iptv
51
iptv
@ -1,36 +1,33 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
m3u=$1
|
m3u=$1
|
||||||
search=$2
|
|
||||||
|
|
||||||
echo -en "\nLoading channels... "
|
tmp_playlist="/tmp/iptvtemp"
|
||||||
OUTPUT=$(curl -s $m3u | grep EXTINF: -A 1 | grep -i "$search" -A 1)
|
tmp_channels="/tmp/iptvchannels"
|
||||||
echo -e "Done!\n"
|
|
||||||
|
|
||||||
|
printf "\nLoading channels... "
|
||||||
|
curl -s $m3u | grep EXTINF: -A 1 > $tmp_playlist
|
||||||
|
printf "Done!\n"
|
||||||
|
|
||||||
|
printf "Parsing channels... "
|
||||||
channels=()
|
channels=()
|
||||||
while read line && read line2; do
|
readarray -t lines < "$tmp_playlist"
|
||||||
name=$(echo "$line" | sed -n 's/.*tvg-name="\([^"]*\)".*/\1/p')
|
for (( i=0; i<${#lines[@]}; i+=2 )); do
|
||||||
url=$line2
|
line="${lines[i]}"
|
||||||
|
line2="${lines[i+1]}"
|
||||||
|
|
||||||
if [[ -n "$name" ]]; then
|
if [[ "$line" =~ tvg-name=\"([^\"]+)\" ]]; then
|
||||||
channels+=("$name url:$url")
|
name="${BASH_REMATCH[1]}"
|
||||||
fi
|
channels+=("$name [CH:$i] url:$line2")
|
||||||
done <<< "$OUTPUT"
|
fi
|
||||||
|
|
||||||
for index in "${!channels[@]}"; do
|
|
||||||
id=$((index + 1))
|
|
||||||
name=$(echo "${channels[$index]}" | sed 's/\(.*\) url:.*/\1/')
|
|
||||||
|
|
||||||
echo "($id) $name"
|
|
||||||
done
|
done
|
||||||
|
printf "Done!\n"
|
||||||
|
|
||||||
echo ""
|
printf "%s\n" "${channels[@]}" > $tmp_channels
|
||||||
|
selected=$(cat "$tmp_channels" | sed 's/ [^ ]*$//' | fzf)
|
||||||
|
selected_channel=$(echo "$selected" | sed 's/.*\(\[CH:[0-9]\+\]\).*/\1/')
|
||||||
|
selected_channel_line=$(cat "$tmp_channels" | grep -F "$selected_channel")
|
||||||
|
selected_channel_url=$(echo "$selected_channel_line" | grep -oP 'url:\K.*' | tr -d '\r')
|
||||||
|
selected_channel_name=$(echo "$selected_channel_line" | sed 's/\(.*\) url:.*/\1/')
|
||||||
|
|
||||||
read -p "Select a channel: " selected
|
printf "Playing %s from %s" "$selected_channel_url" "$selected_channel_name"
|
||||||
index=$((selected - 1))
|
mpv "$selected_channel_url" > /dev/null 2>&1 &
|
||||||
|
|
||||||
name=$(echo "${channels[$index]}" | sed 's/\(.*\) url:.*/\1/')
|
|
||||||
url=$(echo "${channels[$index]}" | grep -oP 'url:\K.*' | tr -d '\r')
|
|
||||||
|
|
||||||
mpv "$URL" > /dev/null 2>&1 &
|
|
||||||
|
|
||||||
echo "Playing $url from $name"
|
|
||||||
|
Loading…
Reference in New Issue
Block a user