Ok, I faced a problem that I had few times recently: as with ssh tunneling, I couldn’t find how to make a crontab and record an on-line radio station! I made it some years ago, one year ago I used it again, and I couldn’t find it any more! So, now that I did once again my research I write down the results.
My first thought was mencoder, but after few tries I didn’t make it work. Then I looked for ffmpeg which worked pretty easy and fast. I ended up with the following command:
ffmpeg -i https://radiostreaming.linkk/audiofile -t 10 trito.mp3
The -i is for the link of the streaming
the -t is the duration in seconds!
and trito.mp3 is the filename it will be saved. You can even have full path there, like /home/doin/mymusic.mp3
After I had a working command, as I spoke with one friend, he suggested the mencoder with -dumpstream parameter. I did some research and figured that -dumpstream is supported in mplayer command and not in mencoder. so, the above command will become:
mplayer https://radiostreaming.linkk/audiofile -dumpstream -dumpfile trito.mp3
mplayer (or mencoder) has a parameter -endstream (or something like that) which might have similar functionality as -t in ffmpeg. I didn’t try it.
Now that my tests worked fine I wrote a shell script with the name trito.sh, just to have things neat:
#!/bin/bash
# writes the STREAM for specific DURATION in seconds to DLDIR/FILENAME
STREAM=”https://radiostreaming.linkk/audiofile”
DLDIR=”/home/doin/mymusic.mp3″
FILENAME=”trito_date +%Y%m%d_%H%M%S
.mp3″
DURATION=”7300″
ffmpeg -i $STREAM -t $DURATION $DLDIR$FILENAME
Finally, let’s add it to a crontab:
59 12 * * 5 /home/doin/bin/trito.sh >/dev/null 2>&1
For setting up a crontab you can help youself here:
https://duckduckgo.com/?q=make+crontab+web&t=h_&ia=web
Also, these two links:
https://crontab.guru/
https://crontab-generator.org/
Check out you made chmod 755 trito.sh.
One final Idea: make the save directory at your web server and you will have them immediately ready to download them from anywhere!