Pimp my bash script!


Recommended Posts

Been working for the last couple of hours on a bash script to play online radio streams. The user is presented with a list of streams, organized by name and makes the selection.

snap2l.jpg

Here's the current code:

#!/bin/bash


#Radio names list
RADIO_NAME_ARRAY=(
"60s"
"70s"
"80s"
"chillout"
"dance"
"jazz"
"rock"
"soft"
)

#Radio URL list
RADIO_URL_ARRAY=(
"http://scfire-mtc-aa05.stream.aol.com:80/stream/1094"
"http://happywave.nl:8006/AAC-HE"
"http://streaming28.radionomy.com:80/Vintage-Radio"
"http://72.13.81.178:8010"
"http://airfm.hu:8000/airfm"
"http://rs21.stream24.org:8000/stream2"
"http://92.61.113.195:80/rockfm192.mp3"
"http://live7.avf.ch:8000/ipmusicslow256"
)




#Generate radios list
gen_list() {
local TOTAL_MEMB=${#RADIO_NAME_ARRAY[@]}
for (( i=0;i<$TOTAL_MEMB;i++));do
    echo -n ${RADIO_NAME_ARRAY[${i}]} " "
    echo -n ${RADIO_URL_ARRAY[${i}]} " "
done
}


#Get the URL
get_radio_url() {
local TOTAL_MEMB=${#RADIO_NAME_ARRAY[@]}
for (( i=0;i<$TOTAL_MEMB;i++));do
    if [ "$1" == ${RADIO_NAME_ARRAY[${i}]} ];then
    VARRAD=${RADIO_URL_ARRAY[${i}]}
    break
    fi
done
}

#Show the menu
show_menu() {
dialog --backtitle "radiotunner" \
       --title "Radio stations" \
       --menu "Choose your station" 13 60 6 $VARRAD 2> .tempfile

output=`cat .tempfile`
rm -f .tempfile
clear
}

#Play the stream
tune_radio() {
if [ $output ];then
get_radio_url $output
mplayer -nolirc $VARRAD
else
exit 0 
fi
}


export VARRAD=$(gen_list)

show_menu
tune_radio

I'm using dialog to show the list (ncurses would probably be a better solution). How can I loop this so that after mplayer exits it shows the menu again?

Any help is appreciated. Let's pimp this script! :D

Link to comment
https://www.neowin.net/forum/topic/961792-pimp-my-bash-script/
Share on other sites

  On 18/12/2010 at 14:14, Lechio said:

Been working for the last couple of hours on a bash script to play online radio streams. The user is presented with a list of streams, organized by name and makes the selection.

I'm using dialog to show the list (ncurses would probably be a better solution). How can I loop this so that after mplayer exits it shows the menu again?

Any help is appreciated. Let's pimp this script! :D

Looks pretty sweet ;) You could use a while loop I suppose, and exit if the user presses cancel on the dialog.

show_menu
# loop while the exit status of the dialog is EXIT_SUCCESS
while [$? = 1]
do
 tune_radio
 show_menu
done

Or something along those lines. You'll probably need to restructure show_menu though so the last exit status is that returned from the dialog function.

You could even write it in python with a Tkinter or pygtk interface ;)

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Shell Extensions\Blocked] "{e2bf9676-5f8f-435c-97eb-11607a5bedf7}"="Share" [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Shell Extensions\Blocked] "{e2bf9676-5f8f-435c-97eb-11607a5bedf7}"="Share" [-HKEY_CLASSES_ROOT\*\shellex\ContextMenuHandlers\ModernSharing] Remove that Share text.
    • Meh could never use the UWP as I use WhatsApp business and it's features are available on the standard. Thos this applies to both windows and macos+ipad versions. So I'm stuck on using web versions for whatever platform.
    • I hardly have issues with my ipad pro 4's faceid while holding it on Portrait
    • Sure, one example: Two computers side by side. Your main system is connected to a sound bar or a high end TV with good audio built in. Your secondary machine is the one you play music, movies, YouTube, check email, etc. on another monitor while you work/play games on your main system. In this case, the main computer converts all audio to Dolby Atmos which goes out to the main TV/soundbar (or your bluetooth/headphones), no matter if it comes from the main machine or the secondary...with no latency issues. And whatever you'd be doing on the secondary computer isn't hitting your main computer's CPU or GPU if, say, gaming some serious FPS or at 4k etc. That's just one home use case for a networked audio solution. I'm sure others can think up more of them.
    • Yeah, I've looked at all of these. Dante is a pro and expensive program, of course. I'm just looking for simple audio/music sharing from one PC/device to another. Voicemeeter is a lovely bit of kit, but the interface is NOT user friendly to set up initially, unless you are an audio engineer who thinks the way the program does. It works though. I just didn't feel the juice was worth the squeeze on that one. The other ones you mention each have problems, like no longer maintained/updated, blocks auto-audio switching on receiving computer from say headphones to HDMI, etc. Spotify does this, but only for music played by Spotify. Multiplicity does this (but isn't free) for all audio on one PC (like you'd want) but hiccups the audio on the source PC if too much CPU is used (so you really can't use a very old PC as a music/video/youtube player). Oh, and because of how the old version (I haven't tried the newly released one because it still has a showstopping bug that's not been addressed) shares the mouse between screens, it interferes (and can crash) video games on the server/main machines, etc. Multiplicity Pro was the best of the normal solutions, however. If the two machines are side by side, you can use analog line out to analog line in, but then you are getting analog noise/problems. It's the simplest and most solution, of course.
  • Recent Achievements

    • Rookie
      Snake Doc went up a rank
      Rookie
    • First Post
      nobody9 earned a badge
      First Post
    • One Month Later
      Ricky Chan earned a badge
      One Month Later
    • First Post
      leoniDAM earned a badge
      First Post
    • Reacting Well
      Ian_ earned a badge
      Reacting Well
  • Popular Contributors

    1. 1
      +primortal
      496
    2. 2
      Michael Scrip
      205
    3. 3
      ATLien_0
      201
    4. 4
      Xenon
      136
    5. 5
      +FloatingFatMan
      117
  • Tell a friend

    Love Neowin? Tell a friend!