#!/bin/bash exe_path="$(dirname "$0")"/"$(basename "$0")" fav_path="$exe_path".saved base_url='https://streema.com/radios/' user_agent="Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Firefox/78.0" page=1 loaded=0 volume=25 saved_radios(){ saved=(`cat "$fav_path"`) while true; do for i in ${!saved[@]};do if ((i % 2 == 0));then name[$i]=${saved[$i]} url[$i]=${saved[(($i+1))]} fi done fav_choice=$(printf "%s\n" "${name[@]}" | sed -e '$a ' -e '$a ...' | fzf --cycle) if [[ "$fav_choice" == "" || "$fav_choice" == "..." ]]; then break elif [[ "$fav_choice" == "" ]]; then remove_choice=$(printf "%s\n" "${saved[@]}" | sed -e '$a ...' | fzf --cycle) if [[ "$fav_choice" != "..." ]]; then saved=( "${saved[@]/$remove_choice*/}" ) echo "${saved[0]}" > $fav_path for i in "${saved[@]:1:${#saved[@]}}"; do echo "$i" >> $fav_path done continue fi fi echo $fav_choice for index in "${!name[@]}"; do [[ "${name[$index]}" = "${fav_choice}" ]] && break done station=${url[$index]} echo $station mpv $station --volume=$volume done } while true; do if [[ "$#" == 0 && -e $fav_path ]]; then saved_radios elif [[ "$#" != 0 ]]; then if [[ "$loaded" == 0 ]]; then if [[ "$page" == 1 ]]; then url="https://streema.com/radios/search/?q="$(echo $@|tr ' ' +) else url="https://streema.com/radios/search/?q="$(echo $@|tr ' ' +)"&page=$page" fi # radios=($(cat tmp/search.html | grep -e propagation -B 2 -e item-rating -A 2 ...)) radios=($(curl -A $user_agent -s $url | grep -e propagation -B 2 -e item-rating -A 2 | grep -e href -e Listens | grep -e radios -e "

")) j=0 for i in "${!radios[@]}";do line=$(echo ${radios[i]} | grep href | cut -d'/' -f 3 | sed 's/"\+$//') if [[ -n $line ]]; then lines[j]=$line ((j++)) else listen=$(echo ${radios[i]} | grep -e "

" | cut -d">" -f 2) if [[ -n $listen ]];then lisrs[j-1]=$listen lines[j-1]=${lines[j-1]}" ("${lisrs[j-1]}")" fi fi done items=$(printf "%s\n" "${lines[@]}" | sed -e '$a ' -e '$a ' -e '$a ' -e '$a ...') loaded=1 fi choice=$(printf "%s\n" "${items[@]}" | fzf --cycle) stripped_choice=$(echo $choice | cut -d ' ' -f 1) else printf "%s\n" "Usage: streema or streema with no arguments to open saved radios. You can save the last played station with option." break fi if [[ "$choice" == "" || "$choice" == "..." ]]; then break fi if [[ "$choice" == "" ]]; then echo $((page++)) loaded=0 continue fi if [[ "$choice" == "" && -n "$last_choice" ]]; then echo $last_choice" "$last_url >> $fav_path elif [[ "$choice" == "" ]]; then saved_radios else ub=$( curl -A $user_agent -s $base_url$stripped_choice | grep -e "url:" -e "Kbps" ) bitrate=$( echo $ub | cut -d'>' -f 2 | cut -d'<' -f 1) station=$( echo $ub | cut -d'"' -f 4 | cut -d';' -f 1) check=$(echo $station | grep -e static) if [[ -n $station && -z $check ]]; then echo $stripped_choice echo $station" at "$bitrate mpv $station --volume=$volume last_choice=$stripped_choice last_url=$station else printf "\nNo URL available for $stripped_choice\n\n" sleep 1 fi fi done