You are not logged in.
Here is a simple script to record online radio to local disk.
#!/bin/bash
URL=http://64.62.252.130:8070
WORKDIR=/home/Gez/temp/mplayerdump
mplayer -dumpstream $URL -dumpfile $WORKDIR/current.mp3
which is not satisfying enough...
I want to write a script to do this:
1.one file per song, NOT all stream recorded in one file called current.mp3
2.auto-rename "current.mp3" to "$artist_$title.mp3" everytime a song is ended
And when i run the script in terminal, i get the out put::
...
ICY Info: StreamTitle='Offspring, The - You're Gonna Go Far, Kid [Radio Edit]';StreamUrl='http://www.1.fm';
ICY Info: StreamTitle='AFI - The Leaving Song Pt. 2';StreamUrl='http://www.1.fm';
the point is, every time the stream is swithed to a new song, this output will add one line, containing "StreamTitle="
And i had no clue how tail the terminal output directly,so i used >> to write all this output into a file called xxx,then i tried:
tail xxx -n 1 | cut -d "'" -f 2 > i
the result is nice for me::
AFI - The Leaving Song Pt. 2
i think this could be used to rename the song.
and then i tried to write the script .... and with no result
i think the sign to song switch is: one line added to the terminal output, which could be described with "wc -l"
but i just have no way to do this::
while doing the stream recording "mplayer -dumpstream $URL -dumpfile $WORKDIR/current.mp3"
how to monitor on the terminal output, so as to tell mplayer to end this song at song switch??
i hope the answer is obvious to you.
help, please!
This silver ladybug at line 28...
Offline
I would do something like
mplayer stuff 2>&1 &
while read MPLAYEROUTPUT <&1; do
SONGNAME=$(echo $MPLAYEROUTPUT | tail xxx -n 1 | cut -d "'" -f 2)
rename the file
done
notes:
a) redirecting stderr to stdout might not be necessary
b) mplayer could complain about fiddling with the file while it writes to it: I would either kill and restart mplayer everytime or take note of the times leaving the song splitting part after the broadcast
c) you might want to sanitize the mplayer input since if mplayer spits out something unusual you'd be doomed
you could also look for "bash streams redirection" or something like that in order to better understand why this solution should work.
Offline
THANKS, carlocci
still got no result though...
mplayer stuff 2>&1 &
the last "&" means bring it to background,right ?
is it that without this "&" the while loop after "mplayer stuff" won't start until "mplayer stuff" is done;
while by adding this "&", the while loop is run along with the "mplayer stuff" at the same time ??
well, it seems NOT though...
here is a little script for testing,called vvv
#!/bin/bash
URL=http://64.62.252.130:8070
WORKDIR=/home/Gez/x/radioe/
mplayer -dumpstream $URL -dumpfile $WORKDIR/current.mp3 2>&1 &
while read MPLAYEROUTPUT <&1; do
echo "$MPLAYEROUTPUT" | tail -n 1 | cut -d "'" -f 2 >>$WORKDIR/xx
done
i ran this with "$sh vvv", i got the output in my terminal just like before
but when i look into the file $WORKDIR/xx, which had been manually created, i got nothing in it.
SO...it seems the while loop was never run.
especially, i don't quite understand
"while read MPLAYEROUTPUT <&1"
and ... why put a MPLAYEROUTPUT here??
"kill and restart mplayer everytime" should be done, but i guess there's little bit situation here, since when mplayer is killed, there're lines written to the stdout like "Exiting... (End of file)", thus the renaming stuff would go wrong.
as to note c) i guess i'm by far more concerned by mplayer's no-splitting than spitting.........
Last edited by lolilolicon (2009-03-13 20:29:31)
This silver ladybug at line 28...
Offline
This sounds like something that can go wrong in a lot of ways. Not to mention how hard it is to test it out.
Why not store everything in 1 file, and use audacity to cut out songs you want?
Offline
something funny.... i just ran the original script::
#!/bin/bash
URL=http://64.62.252.130:8070
WORKDIR=/home/Gez/temp/mplayerdump
mplayer -dumpstream $URL -dumpfile $WORKDIR/current.mp3
while it is doing the recording, i manually renamed the file current.mp3 to xxx.mp3, guess what? it makes no difference to mplayer!!
the file continues to grow as if nothing happened to its name.....
i find it funny, and interesting, and, confusing
any explanation?
This silver ladybug at line 28...
Offline
This sounds like something that can go wrong in a lot of ways. Not to mention how hard it is to test it out.
Why not store everything in 1 file, and use audacity to cut out songs you want?
well...:)that's ok..with audacity, but not cool i guess.
Especially now that i'm really into working it out....
This silver ladybug at line 28...
Offline
OK, how is this
while true; do mplayer -noconfig all -dumpstream -dumpfile radiodump.mp3 'http://64.62.252.130:8070' -quiet 2>&1 | awk -F\' 'BEGIN {previous="-1" } /StreamTitle/ {print $2; if ( previous == "-1" ) { previous=$2 } if ( previous != $2 ) { system("mv radiodump.mp3 \""previous"\".mp3"); system("pkill mplayer"); exit } }'; done
I am running it right now, I wonder if it will cut off anything. Also you can't run mplayer or they will get killed too, by pkill.
If there is a ' in the filename it will only rename up to there.
When a song changes it will look like this
Song A
Song B
Song B
Song C
Song C
Between a duplicate, awk will kill mplayer and it will restart, that is why.
EDIT:
It definitely cuts off too early. Sometimes up to 15 seconds before Song B starts, it will be announced.
Last edited by Procyon (2009-03-13 22:07:36)
Offline
cool!!
that works!! i'm trying to understand it .....
good job man !!
Bravo
Last edited by lolilolicon (2009-03-13 22:36:50)
This silver ladybug at line 28...
Offline
cool!!
that works!! i'm trying to understand it .....
only one thing i should mention::
when it's running python takes up to 50% of my CPU..........and my laptop is like shaking......lol..
anyway,
good job man !!
Bravo
----i guess i was wrong , the python CPU thing........this time it's all quiet, but last time when i ran it, i dont know what happened , python did freak out........
This silver ladybug at line 28...
Offline
Heh, weird. But what about pieces of songs being in different places? I'm not sure if it is possible to fix that, or if -nocache helps at all.
Offline
EDIT:
It definitely cuts off too early. Sometimes up to 15 seconds before Song B starts, it will be announced.
about 14 seconds too early ,maybe 13.5
Last edited by lolilolicon (2009-03-13 22:48:40)
This silver ladybug at line 28...
Offline
Heh, weird. But what about pieces of songs being in different places? I'm not sure if it is possible to fix that, or if -nocache helps at all.
maybe it's the broadcast designed this way?? -- song name appears prior to song itself?...
This silver ladybug at line 28...
Offline
Is it 14 seconds consistently? Maybe this can be as simple as adding system("sleep 14"); before the other systems.
Offline
Is it 14 seconds consistently? Maybe this can be as simple as adding system("sleep 14"); before the other systems.
by now, likely it is stable here~
let me try it
This silver ladybug at line 28...
Offline
added system("sleep 13.6");
seems working fine
This silver ladybug at line 28...
Offline
it's weird, no as supposed,
while a song begins at the reasonable time, it ends 13.6s too late...meaning these 13.6 seconds are double recorded
haha guess it's the cache thing as you mentioned, Procyon
This silver ladybug at line 28...
Offline
I noticed that too using -nocache
Offline
The alternative could be instead of putting the sleep 13.6 in awk, to put it after the entire command (so I mean it will become the second command in the while loop)
Offline
Procyon, i'm wondering if this is possible::
often when i listen to a .ape file, which is large and containing the whole album, there will be a .cue file along with it. using the .cue file, it's convenient to go around the .ape file.
.cue is to .ape what an index is to a book.
so,, i think it's best not to dice the mp3 file into blocks. what's better is keep it as a whole, while write an index file to it. that would be perfect !!
Procyon, can you help? really looking forward to it! pity i can't do it myself, by now..
Last edited by lolilolicon (2009-03-14 00:59:36)
This silver ladybug at line 28...
Offline
Yeah that is a good idea too.
What does a cue file look like? I have a few and I think it comes down to
Start
REM COMMENT "Radio Station rip"
FILE "radiodump.mp3" MP3
Per track
TRACK 01 AUDIO
TITLE "To be filled in"
PERFORMER "To be filled in"
INDEX 01 00:00:00
TRACK 02 AUDIO
TITLE "To be filled in"
PERFORMER "To be filled in"
INDEX 01 xx:xx:xx
Try this
mplayer -nocache -noconfig all -dumpstream -dumpfile radiodump.mp3 'http://64.62.252.130:8070' -quiet 2>&1 | awk -F\' '
BEGIN {
tracknumber=1;
print "REM COMMENT \"Radio Station rip\"";
print "FILE \"radiodump.mp3\" MP3";
previous=systime()
}
/StreamTitle/ {
if ( tracknumber != 1 ) {
now=systime()+13.6-previous;
}
else {
now=systime()-previous;
}
printf(" TRACK %d AUDIO\n",tracknumber);
tracknumber+=1;
artist=$2;
title=$2;
gsub(" - .*", "", artist);
gsub(".* - ", "", title);
printf(" TITLE \"%s\"\n",title);
printf(" PERFORMER \"%s\"\n",artist);
printf(" INDEX 01 %s\n", strftime("%H:%M:%S", now, 1));
}'
EDIT
Wait, the Index is minute, second, centisecond?
One moment
Last edited by Procyon (2009-03-14 10:03:14)
Offline
Well, awk stuff doesn't have smaller than seconds, but date does, so this has become quite interesting with getline.
mplayer -nocache -noconfig all -dumpstream -dumpfile radiodump.mp3 'http://64.62.252.130:8070' -quiet 2>&1 | awk -F\' '
BEGIN {
print "REM COMMENT \"Radio Station rip\"";
print "FILE \"radiodump.mp3\" MP3";
"date +%s.%2N" | getline previous
close("date +%s.%2N")
tracknumber=1
}
/StreamTitle/ {
if ( tracknumber != 1 ) {
"date +%s.%2N" | getline now
close("date +%s.%2N")
now=now+13.6-previous;
}
else {
now=0;
}
printf(" TRACK %02d AUDIO\n",tracknumber);
tracknumber+=1
artist=$2;
title=$2;
gsub(" - .*", "", artist);
gsub(".* - ", "", title);
printf(" TITLE \"%s\"\n",title);
printf(" PERFORMER \"%s\"\n",artist);
minutes=int(now/60)
seconds=int(now%60)
centiseconds=int(100*(now-int(now)))
printf(" INDEX 01 %02d:%02d:%02d\n", minutes, seconds, centiseconds);
}'
Now the limit of 24 hours is also gone.
EDIT
I turned all the %d into %02d, so they appear as 01, 00, etc
Last edited by Procyon (2009-03-14 10:51:05)
Offline
Procyon! Awesome, man!!
it's now played on audacious easily,
you're good, man:)
This silver ladybug at line 28...
Offline