NoPaste Service
DOWNLOAD
Language: Bash
Author: Matrix86
Description: Bash Script per la registrazione di stream radio
Date: 26/02/08 16:56
  1. #!/bin/sh
  2. # Semplice script per registrare le streaming radio in rete in file mp3 o ogg.
  3. # Digitare sh recordradio.sh -h per maggiori info.
  4. # Esempio di uso: sh recordradio.sh -u mms://fastreal.fastweb.it/RDS -o prova -c ogg
  5.  
  6.  
  7. red='\e[0;31m'
  8. RED='\e[1;31m'
  9. blue='\e[0;34m'
  10. BLUE='\e[1;34m'
  11. cyan='\e[0;36m'
  12. CYAN='\e[1;36m'
  13.  
  14. banner (){
  15.         echo -e $RED"**********************************"
  16.         echo -e     "*     Record Stream Radio        *"
  17.         echo -e     "*     Bash Script                *"
  18.         echo -e     "*     Coded By Matrix86          *"
  19.         echo -e     "*     http://www.tuxmealux.net   *"
  20.         echo -e     "**********************************"
  21. }
  22.  
  23.  
  24. usage=$BLUE'Usage: $0 [OPTION] [FILE] \nOptions:\n\t-h\t show this help\n\t-u\t radio url\n\t-o\t output filename\n\t-c\t use codec type (ogg,mp3) default mp3\n'
  25.  
  26. codec="mp3"
  27. outfile="radiorec"
  28.  
  29. if [ $# -eq 0 ];then
  30.         banner
  31.         echo -e $usage
  32.         tput sgr0
  33.         exit 0
  34. fi
  35.  
  36. while getopts ":h:u:o:c:" option
  37. do
  38.    case $option in
  39.     h)
  40.         banner
  41.         echo -e $usage
  42.         tput sgr0 # Ripristina il colore normale della shell
  43.         exit 0
  44.     ;;
  45.     u)
  46.         url=$OPTARG
  47.     ;;
  48.     o)
  49.         outfile=$OPTARG
  50.     ;;
  51.     c)
  52.         codec=$OPTARG
  53.     ;;
  54.     *)
  55.         banner
  56.         echo -e $usage
  57.         tput sgr0
  58.         exit 0
  59.     ;;
  60.    esac
  61. done
  62.  
  63. banner
  64. tput sgr0
  65.  
  66. mplayer $url -cache 128 -ao pcm:file=$outfile.wav >/dev/null 2>&1 &
  67. PID=$(ps aux | grep "mplayer $url -cache 128 -ao pcm:file=$outfile.wav" | grep -v grep | cut -c10-14)
  68. echo -e "Start Recording...\nTo Stop Recording Press a Key!"
  69. read key
  70.  
  71. kill -3 $PID && echo -e "Stop Recording"
  72.  
  73. sleep 2
  74.  
  75. if [ -e $outfile.wav ];then
  76.         case $codec in
  77.         mp3)
  78.                 lame -b 192 -vbr-new $outfile.wav $outfile_`date "+%d%m%Y_%H%M%S"`.mp3 >/dev/null 2>&1 && echo -e "Encoding to MP3...Wait a While"
  79.         ;;
  80.         ogg)
  81.                 oggenc $outfile.wav -o $outfile_`date "+%d%m%Y_%H%M%S"`.ogg >/dev/null 2>&1 && echo -e "Encoding to OGG...Wait a While"
  82.         ;;
  83.         esac
  84.  
  85.         rm $outfile.wav
  86.         echo "DONE"
  87. else
  88.         echo $outfile".wav not found!"
  89. fi
  90.  
  91. tput sgr0
  92. exit 0
  93.