sh/bash/dash/ksh/zsh等Shell脚本
-
qqttdh
- 帖子: 896
- 注册时间: 2007-07-20 22:15
#1
帖子
由 qqttdh » 2008-10-13 22:25
尝试时请保持player和pause的名称
欢迎补充功能~~
版本:1.1(添加初级歌词显示功能)
版本:1.0(添加一定的记忆功能,修复了几个bug)
AB版差别不大,个人偏好使用B版,符合0.8版以前的使用习惯
版本:0.9 (添加了多队列)
根据 33 楼 linee 的提议添加播放mms://等网络协议列表。。。
列表需手动编辑放到./mplayer/plist目录下,格式如下
代码: 全选
mms://mms.cnr.cn/live1 /中国之声
根据 29 楼 linee 的提议使脚本能运行在任意模式。。。添加目录播放
根据 19 楼 linee 的提议对主脚本做了些调整。。。
脚本说明
代码: 全选
建议使用nautilus-scripts方式的脚本
player ── -_- 最好保持名称 创建播放列表并播放或继续播放或向当前播放列表中添加新文件
# player 可以由 pause 和 add_new_list 组合代替
player_now ──名称可修改_ 向正在播放的列表添加文件并立即切换
add_new_list ──名称可修改_ 向已有的列表中添加文件或创建新列表
--------------------------------------------------------------------------
辅助脚本
choice_list ──名称可修改_ 选择播放列表
choice_sone ──名称可修改_ 选择列表中指定文件播放
conky_check ──名称可修改_ 在conky中显示相关信息
init ──名称可修改_ 不停止队列就注销账户,在重新登录时可能会有一个假死的player和mplayer
list_edit ──名称可修改_ 删除播放队列中被选种的文件
loop_list ──名称可修改_ 列表是否循环-----默认循环
loop_sone ──名称可修改_ 单个循环-----默认不循环
manage_list ──名称可修改_ 删除选种列表(可多选)或重命名指定列表
next ──名称可修改_ 下一个
pause ── -_- 最好保持名称_ 暂停/继续播放,或继续上次的播放(集成player部分功能)
previous ──名称可修改_ 上一个
random ──名称可修改_ 乱序播放(排序结果不会被写入原始列表)
stop ──名称可修改_ 停止队列
-
附件
-
- mplayer_queue_player.1.0.pub.A.tar.bz2
- (6.86 KiB) 已下载 107 次
-
- mplayer_queue_player.1.0.pub.B.tar.bz2
- (6.84 KiB) 已下载 112 次
-
- mplayer_queue_player.09.fixed.5.tar.bz2
- (6.76 KiB) 已下载 98 次
-
- nautilus-scripts.tar.bz2
- (1.39 KiB) 已下载 124 次
上次由
qqttdh 在 2009-06-11 22:17,总共编辑 56 次。
-
qqttdh
- 帖子: 896
- 注册时间: 2007-07-20 22:15
#3
帖子
由 qqttdh » 2008-10-21 14:06
最新主脚本代码展示
代码: 全选
#!/bin/sh
#子程序功能:生成列表
list_out ()
{
if [ -e ~/.mplayer/plist/"$list_name" ];then
cp ~/.mplayer/plist/"$list_name" /dev/shm/mqueue
fi
while [ $# -gt 0 ]; do
for i in $@; do
if [ `echo "$1"|grep -vicE '(.jpg)|(.srt)'` = 0 ];then break;fi
d="`pwd`"
if [ -e /dev/shm/mqueue ];then
if [ `grep -c "${d##*\/}/${1##*\/}" /dev/shm/mqueue` != 0 ];then break;fi
fi
if ! [ -e ~/.mplayer/plist ];then
mkdir ~/.mplayer/plist
fi
if [ "`echo "$1" | grep '/'`" ];then
if [ -f "$1" ];then
echo "$1" >> /dev/shm/mqueue
else
echo "`find "$1" -type f`" >> /dev/shm/mqueue
fi
else
if [ -f "$d/$1" ];then
echo "$d/$1" >> /dev/shm/mqueue
else
if(zenity --question --text="添加子目录$1?")then
echo "`find "$d/$1" -type f |grep -viE '(.jpg)|(.srt)'`" >> /dev/shm/mqueue
else
echo "$d/$1" >> /dev/shm/mqueue
fi
fi
fi
break
done
shift
cp /dev/shm/mqueue ~/.mplayer/plist/"$list_name"
done
}
#################################################
# PROGRAMME
#环境初始化
if [ -e /dev/shm/mlol ];then
rm /dev/shm/mlol
fi
if [ -e /dev/shm/mloop ];then
rm /dev/shm/mloop
fi
#播放/添加到当前列表/退出/继续播放
if [ $# != 0 ];then
#生成和添加播放队列
if [ "`ps aux |grep ' mplayer '|grep -v grep|grep -c "/dev/shm/mfifo"`" = 0 ];then
#if [ -e ~/.mplayer/plist/$list_name ];then rm ~/.mplayer/plist/$list_name;fi
if [ -e /dev/shm/mqueue ];then rm /dev/shm/mqueue;fi
#list_name=`zenity --entry --text="列表名称"`
###self-use /*
list_name=default
if [ -e ~/.mplayer/plist/"$list_name" ];then
rm ~/.mplayer/plist/"$list_name"
fi
###self-use */
echo "$list_name" > ~/.mplayer/list_name
if [ "$list_name" ];then list_out "$@";fi
else
read list_name < ~/.mplayer/list_name
list_out "$@"
exit
fi
elif [ "`ps aux |grep ' mplayer '|grep -v grep|grep -c "/dev/shm/mfifo"`" != 0 ];then
zenity --info --text="队列已存在" &
exit
else
if [ -s ~/.mplayer/list_name ];then
read list_name < ~/.mplayer/list_name
cp ~/.mplayer/plist/"$list_name" /dev/shm/mqueue
fi
fi
#列表名称为空时的处理
if ! [ "$list_name" ];then
list_name="`ls ~/.mplayer/plist -1|sed 1q`"
echo "$list_name" > ~/.mplayer/list_name
cp ~/.mplayer/plist/"$list_name" /dev/shm/mqueue
if ! [ "$list_name" ];then
list_name=default
echo "$list_name" > ~/.mplayer/list_name
list_out "$@"
fi
fi
#恢复播放曲目
if [ -e ~/.mplayer/pnum/"$list_name"mnum ];then
cp ~/.mplayer/pnum/"$list_name"mnum /dev/shm/mnum
fi
#排除异己:)
if [ "`ps aux |grep -E '(/player)|(/pause)'|grep -vcE '(grep)|(player_now)|(file:)'`" != 2 ];then
kill -9 `ps aux |grep -E '(/player)|(/pause)'|grep -vE '(grep)|(player_now)|(file:)'|awk {'print $2'}|grep -v $$`
fi
#建立/清理 管道
if [ -e /dev/shm/mfifo ];then
if [ "`ps aux |grep ' mplayer '|grep -v grep|grep -c "/dev/shm/mfifo"`" != 0 ];then
echo quit > /dev/shm/mfifo
sleep 0.1
if [ "`ps aux |grep ' mplayer '|grep -v grep|grep -c "/dev/shm/mfifo"`" != 0 ];then
kill -9 `ps aux |grep ' mplayer '|grep -v grep|grep "/dev/shm/mfifo"|awk {'print $2'}`
fi
fi
else
mkfifo /dev/shm/mfifo
fi
sleep 0.5
#建立曲目记忆目录
if ! [ -e ~/.mplayer/pnum ];then
mkdir ~/.mplayer/pnum
fi
if [ -s /dev/shm/mnum ];then
read i < '/dev/shm/mnum'
fi
#################################################
# MAIN PROGRAMME
MAX=0
s=0
list_name_old="$list_name"
while [ ture ]; do
#error manage
if ! [ -s /dev/shm/mqueue ];then zenity --timeout 10 --info --text="列表为空--队列停止" &
echo "" > ~/.mplayer/list_name;exit;fi;
##**##check1
if [ x"$list_name_old" != x"$list_name" ];then
read i < ~/.mplayer/pnum/"$list_name"mnum
cp ~/.mplayer/plist/"$list_name" /dev/shm/mqueue
if [ $? = 0 ];then
list_name_old="$list_name"
else
echo "$list_name_old" > ~/.mplayer/list_name
zenity --info --text="列表不存在恢复至上一个" &
fi
fi
#check2
MAX=`grep -c "" /dev/shm/mqueue`
if [ $i -gt $MAX ];then
#是否循环列表 默认循环
if [ -s /dev/shm/mlol ];then
read lo < '/dev/shm/mlol'
if [ $lo = 0 ];then
exit
else
i=1;
fi
else
i=1;
fi
elif ! [ $i ]||[ $i -eq 0 ];then
i=1;
fi;
#
sone="`awk 'NR=='$i'' /dev/shm/mqueue`"
echo $i > /dev/shm/mnum
#echo $i > ~/.mplayer/mnum
if [ -e ~/.mplayer/plist/"$list_name" ];then
cp /dev/shm/mnum ~/.mplayer/pnum/"$list_name"mnum
fi
echo 0 > /dev/shm/mstat
#产生播放时间/显示歌词(若存在)
fpid=$$
tss=0
tmm=0
thh=0
if [ -e /dev/shm/mlrc ];then
rm /dev/shm/mlrc /dev/shm/mlrc_now
fi
{
while [ -e /proc/$fpid ];do
{
if ! [ -e /dev/shm/mlrc ];then
if [ -e ~/.mplayer/lrc/"${sone##*\/}".lrc ];then
cp ~/.mplayer/lrc/"${sone##*\/}".lrc /dev/shm/mlrc
fi
fi
if [ $tss -lt 10 ];then
echo $tmm:0$tss > /dev/shm/mtime
if [ -e /dev/shm/mlrc ];then
lrc="`grep $tmm:0$tss /dev/shm/mlrc | awk -F ] '{print $2}'`"
if [ "$lrc" ];then
#echo $lrc > /dev/shm/mlrc_now
gnome-osd-client -f "<message id='mlrc' osd_vposition='bottom' hide_timeout='10000'>`echo "<span foreground='grey'>$lrc</span>"`</message>"
fi
fi
else
echo $tmm:$tss > /dev/shm/mtime
if [ -e /dev/shm/mlrc ];then
lrc="`grep $tmm:$tss /dev/shm/mlrc | awk -F ] '{print $2}'`"
if [ "$lrc" ];then
#echo $lrc > /dev/shm/mlrc_now
gnome-osd-client -f "<message id='mlrc' osd_vposition='bottom' hide_timeout='10000'>`echo "<span foreground='grey'>$lrc</span>"`</message>"
fi
fi
fi
}&
if [ $tmm:0$tss != 00:00 ];then
sleep 1
fi
tss=$(($tss + 1))
if [ $tss -gt 59 ];then
tmm=$(($tmm + 1))
tss=0
fi
done
}&
cpid=$!
#判断播放方式
if [ "`echo $sone|grep -E '(.asx)|(.m3u)'`" ];then
mplayer -playlist "`echo $sone|awk '{print $1}'`" -input file=/dev/shm/mfifo;
stat=$?
elif [ "`echo $sone|grep -E '(mms://)|(rtsp://)|(http://)'`" ];then
mplayer "`echo $sone|awk '{print $1}'`" -input file=/dev/shm/mfifo;
stat=$?
else
if [ -f "$sone" ];then
mplayer "$sone" -input file=/dev/shm/mfifo;
stat=$?
else
mplayer -input file=/dev/shm/mfifo "$sone"/*;
stat=$?
fi
fi
kill $cpid
echo 3 > /dev/shm/mstat
#间隔时间
if [ $stat = 0 ];then
sleep 5.5
#check3
if [ -s /dev/shm/mloop ];then
read s < '/dev/shm/mloop'
fi
if [ $s = 0 ];then i=$(($i + 1));fi
else
read i < /dev/shm/mnum;
if [ -e ~/.mplayer/list_name ];then
read list_name < ~/.mplayer/list_name
fi
fi
#清理
if [ -e /dev/shm/mlrc ];then
rm /dev/shm/mlrc /dev/shm/mlrc_now
fi
done
exit
上次由
qqttdh 在 2009-01-13 8:41,总共编辑 9 次。
-
den
- 帖子: 196
- 注册时间: 2007-06-15 21:19
- 来自: 上海
#4
帖子
由 den » 2008-10-23 15:27
感觉不错,有空试试看
/****************************************************
/* Work hard, play harder.
/****************************************************
-
qqttdh
- 帖子: 896
- 注册时间: 2007-07-20 22:15
#5
帖子
由 qqttdh » 2008-10-25 16:30
备用。。。。
chose_list
代码: 全选
#!/bin/sh
if [ -s ~/.mplayer/list_name ];then
read list_name < ~/.mplayer/list_name
fi
echo "`ls ~/.mplayer/plist -1`" > /dev/shm/mlists
exec < /dev/shm/mlists
while read line
do
a="`echo "${line##*\/}"|sed 's/\ /\_/g'`"
if [ "x$line" = "x$list_name" ];then
lab=TRUE
else
lab=FALSE
fi
list="$list $lab $a"
done
c=`zenity --list --radiolist --height=350 --width=300 --column "选项" --column "列表名" $list`
if ! [ $c ];then exit;fi
exec < /dev/shm/mlists
while read line
do
a="`echo "${line##*\/}"|sed 's/\ /\_/g'`"
if [ $c = $a ];then
new_list_name="$line"
break
fi
done
if [ "x$new_list_name" != "x$list_name" ];then
echo "$new_list_name" > ~/.mplayer/list_name
echo 1 > /dev/shm/mnum
if [ -e /dev/shm/mfifo ];then
pid=`ps aux |grep ' mplayer '|grep -v grep|grep "/dev/shm/mfifo"|awk {'print $2'}`
if [ "$pid" ];then
kill -9 $pid
fi
fi
fi
上次由
qqttdh 在 2008-11-30 11:16,总共编辑 2 次。
-
qqttdh
- 帖子: 896
- 注册时间: 2007-07-20 22:15
#6
帖子
由 qqttdh » 2008-11-07 19:38
貌似除了添加新功能已经很难有再优化了。。估计还能做个gui前端。。
版本号:0.5
代码: 全选
#!/bin/sh
list_out ()
{
while [ $# -gt 0 ]; do
for i in $@; do
if [ `echo "$1"|grep -vicE '(.jpg)|(.srt)'` = 0 ];then break;fi
d="`pwd`"
if [ `grep -c "${d##*\/}/$1" /dev/shm/mqueue` != 0 ];then break;fi
echo "$d/$1" >> /dev/shm/mqueue
break
done
shift
done
}
bakup_list ()
{
#bakup play list
if [ -s /dev/shm/mqueue ];then
cp /dev/shm/mqueue ~/.mqueue
cp /dev/shm/mnum ~/.mnum
elif [ -s ~/.mqueue ];then
cp ~/.mqueue /dev/shm/mqueue
cp ~/.mnum /dev/shm/mnum
fi
}
#################################################
# PROGRAMME
if [ $# != 0 ];then
#生成和添加播放队列
if [ "`ps aux |grep ' mplayer '|grep -v grep|grep -c "/dev/shm/mfifo"`" = 0 ];then
if [ -e /dev/shm/mqueue ];then rm /dev/shm/mqueue;fi
list_out "$@"
else
list_out "$@"
bakup_list
exit
fi
elif [ "`ps aux |grep ' mplayer '|grep -v grep|grep -c "/dev/shm/mfifo"`" != 0 ];then
zenity --info --text="队列已存在" &
exit
fi
bakup_list
#排除异己:)
if [ "`ps aux |grep '/player'|grep -vcE '(grep)|(player_now)|(file:)'`" != 2 ];then
kill -9 `ps aux |grep '/player'|grep -vE '(grep)|(player_now)|(file:)'|awk {'print $2'}|grep -v $$`
fi
#建立/清理 管道
if [ -e /dev/shm/mfifo ];then
if [ "`ps aux |grep ' mplayer '|grep -v grep|grep -c "/dev/shm/mfifo"`" != 0 ];then
echo quit > /dev/shm/mfifo
sleep 0.1
if [ "`ps aux |grep ' mplayer '|grep -v grep|grep -c "/dev/shm/mfifo"`" != 0 ];then
kill -9 `ps aux |grep ' mplayer '|grep -v grep|grep "/dev/shm/mfifo"|awk {'print $2'}`
fi
fi
else
mkfifo /dev/shm/mfifo
fi
sleep 0.5
i=1
if [ -e "$1" ];then
echo $i > /dev/shm/mnum
echo 0 > /dev/shm/mstat
mplayer "$1" -input file=/dev/shm/mfifo
echo 3 > /dev/shm/mstat
i=2
elif [ -s /dev/shm/mnum ];then
read i < '/dev/shm/mnum'
fi
#################################################
# MAIN PROGRAMME
MAX=0
s=0
while [ ture ]; do
#error manage
if ! [ -e /dev/shm/mqueue ];then exit;fi;
if ! [ -s /dev/shm/mqueue ];then rm /dev/shm/mqueue;exit;fi;
##**##check1
if [ -s /dev/shm/mnum ];then
read t < '/dev/shm/mnum'
ts=$(($t + 1))
if [ $ts != $i ];then i=$t;fi;
fi
#check2
MAX=`grep -c "" /dev/shm/mqueue`
if [ $i -gt $MAX ];then i=1;fi;
#
sone="`awk 'NR=='$i'' /dev/shm/mqueue`"
echo $i > /dev/shm/mnum
#echo "$sone"
echo 0 > /dev/shm/mstat
mplayer "$sone" -input file=/dev/shm/mfifo;
echo 3 > /dev/shm/mstat
#间隔时间
sleep 5.5
#check3
if [ -s /dev/shm/mloop ];then
read s < '/dev/shm/mloop'
fi
if [ $s = 0 ];then i=$(($i + 1));fi
done
exit
上次由
qqttdh 在 2008-11-08 22:51,总共编辑 2 次。
-
xiooli
- 帖子: 6956
- 注册时间: 2007-11-19 21:51
- 来自: 成都
-
联系:
#7
帖子
由 xiooli » 2008-11-07 19:41
你这个是干啥玩意儿的?
-
内存不足
- 论坛版主
- 帖子: 3277
- 注册时间: 2005-08-18 18:43
-
联系:
#8
帖子
由 内存不足 » 2008-11-07 19:45
看到了mplayer 难道是在conky里显示mplayer正在播放文件的名称?
-
qqttdh
- 帖子: 896
- 注册时间: 2007-07-20 22:15
#9
帖子
由 qqttdh » 2008-11-07 21:28
第一个gui方案
代码: 全选
#!/bin/sh
exec < /dev/shm/mqueue
i=1
while read line
do
a=`echo ${line##*\/}|sed 's/\ /\_/g'`
echo FALSE $a
list="$list FALSE $a"
i=$(($i + 1))
done
c=`zenity --list --radiolist --height=350 --width=300 --column "曲目" --column "曲名" $list`
exec < /dev/shm/mqueue
i=1
while read line
do
a=`echo ${line##*\/}|sed 's/\ /\_/g'`
if [ $c = $a ];then
n=$i
break
fi
i=$(($i + 1))
done
if [ $n ];then
echo $n > /dev/shm/mnum
echo quit > /dev/shm/mfifo
fi
-
qqttdh
- 帖子: 896
- 注册时间: 2007-07-20 22:15
#10
帖子
由 qqttdh » 2008-11-07 21:37
xiooli 写了:你这个是干啥玩意儿的?
建立/维护一个mplayer播放队列,并播放
还没做删除曲目的脚本。。。
内存不足 写了:看到了mplayer 难道是在conky里显示mplayer正在播放文件的名称?
仅限于此播放队列
有人想尝试的话,下面的脚本名称应该有帮助
主队列脚本 player
立即切换 player_now
-
linlee
- 帖子: 1132
- 注册时间: 2007-10-20 11:30
#11
帖子
由 linlee » 2008-11-07 21:48
很好啊,楼主继续加油吧。
-
qqttdh
- 帖子: 896
- 注册时间: 2007-07-20 22:15
#12
帖子
由 qqttdh » 2008-11-08 11:12
新增队列删除脚本 list_edit
代码: 全选
#!/bin/sh
if [ -s /dev/shm/mnum ];then
read t < '/dev/shm/mnum'
else
exit
fi
exec < /dev/shm/mqueue
i=1
while read line
do
a=`echo ${line##*\/}|sed 's/\ /\_/g'`
lab=TRUE
list="$list $lab $a"
i=$(($i + 1))
done
c="`zenity --list --checklist --height=350 --width=300 --column "曲目" --column "曲名" $list`"
if [ -e /dev/shm/mqueue_bak ];then
rm /dev/shm/mqueue_bak
fi
exec < /dev/shm/mqueue
i=1
while read line
do
st=`echo ${line##*\/}|sed 's/\ /\_/g;s/\[/\\\[/g;s/\]/\\\]/g'`
sc="`echo "$c"|grep -n "$st"|sed -n 1p|awk -F : '{print $1}'`"
if [ $sc ];then
song="`awk 'NR=='$i'' /dev/shm/mqueue`"
echo "$song" >> /dev/shm/mqueue_bak
fi
i=$(($i + 1))
done
if [ -s /dev/shm/mqueue_bak ];then
mv /dev/shm/mqueue_bak /dev/shm/mqueue
#bakup play list
cp /dev/shm/mqueue ~/.mqueue
cp /dev/shm/mnum ~/.mnum
#echo quit > /dev/shm/mfifo
fi
-
xiooli
- 帖子: 6956
- 注册时间: 2007-11-19 21:51
- 来自: 成都
-
联系:
#13
帖子
由 xiooli » 2008-11-08 11:37
lz很勤奋哈
-
qqttdh
- 帖子: 896
- 注册时间: 2007-07-20 22:15
#14
帖子
由 qqttdh » 2008-11-08 16:22
xiooli 写了:lz很勤奋哈
闲的时候训练下思维而已。。。
-
xiooli
- 帖子: 6956
- 注册时间: 2007-11-19 21:51
- 来自: 成都
-
联系:
#15
帖子
由 xiooli » 2008-11-08 17:38
试了下,不错的说哦,不过建议把几个脚本集成到一块,至少那几个控制的脚本集成到一起。
btw:你说的添加gnome-panel是什么意思?