Page 1 of 2

another radio script (updated to v2)

Posted: Mon Mar 10, 2014 11:18 pm
by pidsley
We have raffles, and we have bbqradio. Why do we need another radio script? We don't, but I wrote one anyway.

I call this "tinyradio" -- at seven lines of code, it's a tiny internet radio player. It reads a list of streams from ~/.config/tinyradio/stream-list, and uses mpg123 to play the stream you select. I included all the available streams from somafm, but you can delete some or add more if you like, and it should even work with .pls files from other players.

The script:

Code: Select all

#!/bin/bash

STREAM_FILE=~/.config/tinyradio/stream-list

[[ ! -f "$STREAM_FILE" ]] && echo "$STREAM_FILE does not exist" && exit 1

array=( $(cat "$STREAM_FILE") )

select opt in "${array[@]}"; do
    mpg123 -@ "$opt"
    break
done
Here is the stream file (put this in ~/.config/tinyradio/stream-list, or change the search path in the script). Add or remove streams, and the script should build the appropriate list:

Code: Select all

http://somafm.com/groovesalad.pls
http://somafm.com/lush.pls
http://somafm.com/earwaves.pls
http://somafm.com/deepspaceone.pls
http://somafm.com/spacestation.pls
http://somafm.com/missioncontrol.pls
http://somafm.com/dronezone.pls
http://somafm.com/poptron.pls
http://somafm.com/events.pls
http://somafm.com/dubstep.pls
http://somafm.com/indiepop.pls
http://somafm.com/folkfwd.pls
http://somafm.com/bagel.pls
http://somafm.com/digitalis.pls
http://somafm.com/sonicuniverse.pls
http://somafm.com/secretagent.pls
http://somafm.com/illstreet.pls
http://somafm.com/thetrip.pls
http://somafm.com/cliqhop.pls
http://somafm.com/covers.pls
http://somafm.com/u80s.pls
http://somafm.com/beatblender.pls
http://somafm.com/doomed.pls
Run the tinyradio script, choose the stream you want to play, and enjoy.

If you are too lazy to add this yourself, I plan to include it in my next spin.

Re: another radio script

Posted: Mon Mar 10, 2014 11:43 pm
by ChefIronBelly
added working sweet.

Re: another radio script

Posted: Tue Mar 11, 2014 12:31 am
by DebianJoe
Very good work Pidsley!

Re: another radio script

Posted: Tue Mar 11, 2014 2:08 am
by bones
Works great, currently listening to Defcon Radio (#9). Thanks, pidsley!

Re: another radio script

Posted: Tue Mar 11, 2014 9:22 am
by rhowaldt
cool shit, tiny indeed! well done :)

Re: another radio script

Posted: Tue Mar 11, 2014 10:35 am
by GekkoP
oh yes, added here too. Thanks for this one.

Re: another radio script

Posted: Tue Mar 11, 2014 3:42 pm
by ivanovnegro
Thanks for this Pid. Added to my script collection.

Re: another radio script

Posted: Wed Mar 12, 2014 10:50 am
by GekkoP
Loving it. And I have to say thanks again because I wasn't used to somafm and in those streams there is the kind of music that perfectly suits my taste.

Re: another radio script

Posted: Fri Mar 14, 2014 8:20 pm
by pidsley
Here is tinyradio v2. This one adds one line, plus a "-r" argument and streamripper -- use "tinyradio -r" to call streamripper to rip the stream to mp3 while you are listening to it. Read "man streamripper" to see how to specify the directory where streamripper puts the ripped music. Note that streamripper will tell you it is skipping the first song you listen to; once it can rip a complete song it will start.

Code: Select all

#!/bin/bash

STREAM_FILE=~/.config/tinyradio/stream-list

[[ ! -f "$STREAM_FILE" ]] && echo "$STREAM_FILE does not exist" && exit 1

array=( $(cat "$STREAM_FILE") )

select opt in "${array[@]}"; do
    [[ $1 =~ ^-r ]] && streamripper "$opt" &
    mpg123 -@ "$opt"
    break
done
https://github.com/pidsley/codemangler/ ... /tinyradio

I also should have apologized to machinebacon for not mentioning his "easy peasy radio script" much earlier. (Honestly, I forgot about it.) All the streams from that script should also work with tinyradio, and streamripper should work with his script as well. The only real difference is that tinyradio doesn't use dialog.

Re: another radio script (updated to v2)

Posted: Fri Mar 14, 2014 9:17 pm
by ivanovnegro
I use both. :) Now I really prefer yours Pidsley, maybe I find dialog just a bit annoying.
Don't kill me Bacon. :)

Re: another radio script (updated to v2)

Posted: Fri Mar 14, 2014 9:39 pm
by wuxmedia
I must be really boring, I just have 2 radio channels I listen to aliased 8)
thanks for sharing.

Re: another radio script (updated to v2)

Posted: Sat Mar 15, 2014 1:56 am
by ChefIronBelly
Updated :)

Re: another radio script (updated to v2)

Posted: Sat Mar 15, 2014 2:04 am
by dkeg
Just now doing some catching up. Great contribution pids. Thank you.

Re: another radio script (updated to v2)

Posted: Sat Mar 15, 2014 2:34 am
by pidsley
wuxmedia wrote:I must be really boring, I just have 2 radio channels I listen to aliased 8)
thanks for sharing.
NP wux -- I have one alias for listening, and one for ripping, both the same stream. Too many choices just confuses me. ;)

Re: another radio script (updated to v2)

Posted: Fri May 02, 2014 1:04 pm
by brontosaurusrex
Love the script, thanks for sharing.
p.s. I'd add a small buffer to mpg123 line like -b 2000

edit: a mpv edition, since mpv supports more audio formats;

Code: Select all

#!/bin/bash

STREAM_FILE=~/bin/radiolist

[[ ! -f "$STREAM_FILE" ]] && echo "$STREAM_FILE does not exist" && exit 1

array=( $(cat "$STREAM_FILE") )

select opt in "${array[@]}"; do
    [[ $1 =~ ^-r ]] && streamripper "$opt" &
    # mpg123 -b 2000 -@ "$opt"
    mpv --load-unsafe-playlists "$opt" --cache 1000 --msglevel=cplayer=no:ffmpeg/audio=no:ffmpeg/demuxer=no:ffmpeg/video=no:ad=no --no-video
    break
done

Re: another radio script (updated to v2)

Posted: Fri May 02, 2014 6:18 pm
by wuxmedia
^ depends on the stream, some of them really do need a 2048k buffer, others play all day without anything.
Still, BBQ philosophy asks you to season as you need. 8)

Re: another radio script (updated to v2)

Posted: Wed Jun 04, 2014 9:06 pm
by Alad
brontosaurusrex wrote:edit: a mpv edition, since mpv supports more audio formats.
Great fan of mpv, cheers for the script (and now I finally know why some streams stop randomly!)

Re: another radio script (updated to v2)

Posted: Thu Jul 24, 2014 10:26 am
by GekkoP
Still using and liking this script, so thanks Pidsley for taking the time to share it. Just one thing, if anyone is interested. I changed this line:

Code: Select all

mpg123 -@ "$opt"
to this:

Code: Select all

mpg123 -C -@ "$opt"
This one adds some control using keybindings: 'q' for quit, 's' for stop/start, etc. Just have a look at mpg123 man page for more info.

Re: another radio script (updated to v2)

Posted: Thu Jul 24, 2014 3:59 pm
by ivanovnegro
^ Nice addition Gekko.

Re: another radio script (updated to v2)

Posted: Sun Sep 20, 2015 5:21 pm
by pidsley
Added some code to run without a stream file. On my github here: https://github.com/pidsley/codemangler/ ... /tinyradio