LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1054|回复: 3

调用mplayer播放几个在线媒体的脚本

[复制链接]
发表于 2004-7-14 11:07:40 | 显示全部楼层 |阅读模式
自己的小练习,
只为图省事,
很简陋,
请指教。:thank
谢谢!
  1. #!/bin/sh
  2. # this is a test to play some online media with mplayer
  3. # written by aaccdd<waxyxgn@hotmail.com>
  4. # any comment or modification would be appreciated

  5. # define play_bbc : play bbc online news
  6. play_bbc()
  7. {
  8.         play_ram() # play ram stream
  9.         {
  10.         wget "http://stream.servstream.com/ViewWeb/BBCTechnology/Event/BBC_World_Service.asx" -O $HOME/.live
  11.         mplayer -playlist $HOME/.live
  12.         rm $HOME/.live
  13.         }
  14.        
  15.         play_mms() # play mms stream
  16.         {
  17.         wget "http://www.bbc.co.uk/worldservice/ram/live_news.ram" -O $HOME/.live
  18.         mplayer -playlist $HOME/.live
  19.         rm $HOME/.live
  20.         }
  21. echo                                                                                
  22. echo "   Which type would you prefer, ram or mms?"
  23. echo
  24. read choice
  25. case $choice
  26. in
  27. ram) play_ram;;
  28. mms) play_mms;;
  29. esac
  30. }

  31. # define play_cnn: play cnn online news
  32. play_cnn()
  33. {
  34. echo
  35. echo "   Which would you prefer, ram or mms?"
  36. echo
  37. read type
  38. case $type
  39. in
  40. ram) mplayer mms://live.stream.aol.com/cnn_webcast4_high;;
  41. mms) mplayer rtsp://live1.stream.aol.com/farm/*/encoder/cnn_webcast4_high;;
  42. esac
  43. }

  44. # define play_cctv: play cctv online channel
  45. play_cctv()
  46. {
  47.         # change the number following live to get access to different channel
  48.         # 1-news 2-economy 3-english
  49.         echo       
  50.         echo "   You can choose 1-news, 2-economy, 3-english"
  51.         echo
  52.         read channel
  53.         case $channel
  54.         in
  55.         1) mplayer mms://winmedia.cctv.com.cn/live1;;
  56.         2) mplayer mms://winmedia.cctv.com.cn/live2;;
  57.         3) mplayer mms://winmedia.cctv.com.cn/live3;;
  58.         esac
  59. }

  60. # define play_btv: play btv online channel
  61. play_btv()
  62. {
  63.        
  64.          wget "http://211.144.23.6/program_list.asp?chan_name=%B1%B1%BE%A9%D0%C2%CE%C5#"  -O $HOME/.live
  65.         grep rtsp $HOME/.live | cut -d "(" -f2 | cut -d "," -f1 | tr -d "'" >$HOME/.live
  66.         mplayer -playlist $HOME/.live
  67.         rm $HOME/.live
  68. }

  69. # define play_cri: play cri online news, musics
  70. play_cri()
  71. {
  72.         wget [url]http://live.cri.com.cn/fm915.ram[/url] -O $HOME/.live
  73.         mplayer -playlist $HOME/.live
  74. }

  75. echo "============================================================"
  76. echo "=                                                          ="
  77. echo "=  You should install MPlayer first to use this script     ="
  78. echo "=                                                          ="
  79. echo "=  Testing ......                                          ="
  80. echo "=                                                          ="
  81. echo "============================================================"
  82. echo
  83. which mplayer 1>/dev/null 2>&1
  84. case $?
  85. in
  86. 0) echo "  OK, you have MPlayer installed. Go on";;
  87. *) echo "  Sorry, you don't have Mplayer installed. Quit";break;;
  88. esac

  89. echo
  90. echo "============================================================"
  91. echo "=                                                          ="
  92. echo "=  The Online Media to choose include:                     ="
  93. echo "=                                                          ="
  94. echo "=  bbc:  BBC online news, including ram and mms stream     ="
  95. echo "=  cnn:  CNN online news, including ram and mms stream     ="
  96. echo "=  cctv: CCTV online channel, including channel 1-3        ="
  97. echo "=  btv:  BTV online channel                                ="
  98. echo "=  cri:  CRI online news, musics                           ="
  99. echo "=                                                          ="
  100. echo "============================================================"
  101. echo
  102. echo "  Please type your choise, quit for exit"
  103. echo
  104. read choise
  105. echo
  106. case $choise
  107. in
  108. bbc)  echo "   You have chosen to play bbc online";echo;play_bbc;;
  109. cnn)  echo "   You have chosen to play cnn online";echo;play_cnn;;
  110. cctv) echo "   You have chosen to play cctv online";echo;play_cctv;;
  111. btv)  echo "   You have chosen to play btv online";echo;play_btv;;
  112. cri)  echo "   You have chosen to play cri online";echo;play_cri;;
  113. quit) break;;
  114. esac

复制代码
 楼主| 发表于 2004-7-14 11:14:33 | 显示全部楼层
一个小问题:
如果输入不是所预想的,
怎么样重新回到读取输入呢?

比如输入:
shanghai
希望反馈:
wrong input/choise, try again.
Please type your choice to play.
 楼主| 发表于 2004-7-14 12:19:36 | 显示全部楼层
问题问的不清楚~
是这样:
我想定义一个
play_help
显示帮助信息,
然后重新读取输入;
但是执行完就退出了。

如果用循环指令,哪个好呢?
发表于 2004-7-14 13:14:10 | 显示全部楼层
echo                                                                                
echo "   Which type would you prefer, ram or mms?"
echo
read choice
case $choice
in
ram) play_ram;;
mms) play_mms;;
*)      echo "input error!";exit 1;;
esac
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表