You are not logged in.

#1 2008-07-22 05:32:06

jr_dwj
Member
Registered: 2008-07-22
Posts: 2

request: script to stream music for given amount of time

I'm looking for a bash script (or anything that will get the job done) that will:

-stream music from my favorite internet radio station (ie: di.fm)
-play stream for a given time in increments of 1hr (ie: 1 hr, 3 hrs, etc)
-at the end of the given time, fade out the music then terminate stream after fade out is complete.
-terminate script (or application that is performing these tasks)

Ideally, the script will take in the internet radio station and time as arguments. I have Rhythmbox which I currently use to stream.  I don't care if the script opens applications for use in this process.  Can anyone help me with this?  Or at least get me pointed in the right direction?

PS: I plan on using this as my music to listen to while I'm trying to go to sleep, hence the time limit and fade out.  If the music stopped abruptly I would most likely wake up.

Thanks guys.

Offline

#2 2008-07-22 12:46:57

Pnevma
Member
Registered: 2008-04-11
Posts: 112

Re: request: script to stream music for given amount of time

I know in mplayer, you can do most of that.

For example, running this from console will play Lounging Sound radio for exactly one hour;

mplayer -endpos 01:00:00  http://67.159.44.146:8002/

I'm not sure about the fade out effect, you might have to Google for that information. I'd recommend the 'mplayer-svn-nogui' package in AUR (or check out the one here) if you decide to go this route.

Oh, you might want to check out MPD too... it could possibly do something like this.

Last edited by Pnevma (2008-07-22 12:56:30)

Offline

#3 2008-07-22 17:47:02

Daenyth
Forum Fellow
From: Boston, MA
Registered: 2008-02-24
Posts: 1,244

Re: request: script to stream music for given amount of time

MPD can't play from streams. I second mplayer

Offline

#4 2008-07-22 18:17:51

rson451
Member
From: Annapolis, MD USA
Registered: 2007-04-15
Posts: 1,233
Website

Re: request: script to stream music for given amount of time

Geez, I would have suggested something along the lines of

$ mplayer; sleep 20m && killall mplayer

i should probably look at options for the more robust applications from now on.


archlinux - please read this and this — twice — then ask questions.
--
http://rsontech.net | http://github.com/rson

Offline

#5 2008-07-22 19:21:28

Pnevma
Member
Registered: 2008-04-11
Posts: 112

Re: request: script to stream music for given amount of time

Daenyth wrote:

MPD can't play from streams. I second mplayer

I'm pretty sure it can, I used to play streams all the time with MPD + Sonata.

Offline

#6 2008-07-22 23:38:41

Daenyth
Forum Fellow
From: Boston, MA
Registered: 2008-02-24
Posts: 1,244

Re: request: script to stream music for given amount of time

Sonata can play streams. MPD cannot.

Offline

#7 2008-07-26 02:36:39

smurnjiff
Member
Registered: 2007-06-25
Posts: 211

Re: request: script to stream music for given amount of time

I've been thinking about this a while.  I was messing with Sox and mplayer for a while but I think this is the simplest method.

Save this as sleep_stream.sh and chmod +x on it.

#!/bin/bash

# ./sleep_stream.sh <stream> <time_in_minutes>

time=$2m

mpc clear

ext=${1##*.}

case "$ext" in
  "m3u" )
  cat $1 | mpc add
  mpc play
  ;;

  "pls" )
  grep '^File[0-9]*' $1 | sed -e 's/^File[0-9]*=//' | mpc add
  mpc play
  ;;
  
      * )
  echo $1 | mpc add
  mpc play
  ;;

esac

sleep $time

while [ "`mpc | sed -n '/^volume/ { s/^volume:\s\([0-9]*\).*/\1/p }'`" -gt 0 ]; do
  mpc volume -1 > /dev/null
  sleep 1
done

The script will not sanitise the input but this works beautifully.

Offline

#8 2008-07-26 03:39:49

Daenyth
Forum Fellow
From: Boston, MA
Registered: 2008-02-24
Posts: 1,244

Re: request: script to stream music for given amount of time

You know for the filetype checking that you can just

case $1 in
  *.m3u) do_playlist ;;
  *.mp3) do_mp3 ;;
  *) do_default ;;
esac

No need to mess with bash string functions.

Offline

#9 2008-07-26 04:46:51

smurnjiff
Member
Registered: 2007-06-25
Posts: 211

Re: request: script to stream music for given amount of time

Daenyth wrote:

You know for the filetype checking that you can just

case $1 in
  *.m3u) do_playlist ;;
  *.mp3) do_mp3 ;;
  *) do_default ;;
esac

No need to mess with bash string functions.

I didn't know but it's not a show stopper for me.  The most important part was deciding how to play a stream _and_ fadeout after a set amount of time.

Offline

Board footer

Powered by FluxBB