[部分翻译]MOCP高级使用技巧

sh/bash/dash/ksh/zsh等Shell脚本
回复
头像
roylez
帖子: 1928
注册时间: 2005-10-04 10:59
来自: 上海

[部分翻译]MOCP高级使用技巧

#1

帖子 roylez » 2007-08-13 10:21

部分翻译自:http://polishlinux.org/apps/cli/moc-aud ... ed-tricks/

多媒体键

现在很多键盘带有多媒体键,他们一般都有windows下的驱动,在Linux下是不是也可以一样使用这些多媒体键呢?幸运的是有些牛人写了个xbindkeys的程序,让用于可以随意定义键盘快捷键,包括多媒体键。xbindkey被包含在大多数GNU/Linux发行版中。如果没有,你可以从作者的主页上面下载并编译。

安装好了xbindkeys之后,你可以在命令行下输入

代码: 全选

xindkeys -k
然后你按下一个你想定义的键,你将会看到

代码: 全选

Press combination of keys or/and click under the window.
You can use one of the two lines after "NoCommand"
in $HOME/.xbindkeysrc to bind a key.
"NoCommand"
  m:0x0 + c:160
  NoSymbol
将最后三行复制到 ~/.xbindkeysrc ,NoCommand字样需要替换为下面的几条中的一条。

代码: 全选

mocp --play     运行MOC server并开始播放
mocp --stop     停止播放
mocp --toggle-pause         暂停/继续播放
mocp --next     播放下一首
mocp --previous     播放前一首
你可以参考MOC manual使用其他的命令,但是上述命令应该是最常用的。更多有关 xbindkeys的信息可以通过 man xbindkeys 或者阅读官方网站的文档获得。

MOC & 系统监视器


理所当然,很多人想要知道是不是可以做点什么让正在播放的歌曲的歌曲名显示在桌面上,或者将MOC和监视器(比如conky)整合起来?这是当然可行的!:)怎么做?MOC有一个很有用的 --info 命令行参数用来显示当前的播放状态。Conky正好可以用来显示其他程序的输出,所以,只需要写一个小脚本可以了。以下是一个叫做 folken 的用户写的一个bash脚本。

代码: 全选

#!/bin/sh

TITLE="`mocp -i | grep 'Title:' | sed -e 's/^.*: //'`";
if [ "$TITLE" != "" ]; then
    ARTIST="`mocp -i | grep 'Artist:' | sed -e 's/^.*: //'`";
    SONGTITLE="`mocp -i | grep 'SongTitle:' | sed -e 's/^.*: //'`";
    ALBUM="`mocp -i | grep 'Album:' | sed -e 's/^.*: //'`";
    if [ "$ARTIST" != "" ]; then ARTIST="$ARTIST - "; fi
    if [ "$ALBUM" != "" ]; then ALBUM="($ALBUM)"; fi
    echo $ARTIST $SONGTITLE $ALBUM
else echo "MOC is idling"
fi
说简单点,这个脚本显示正在播放的文件的tags。如果当前没有播放任何东西,这个脚本返回一条简单的信息说明MOC未被运行。要记住MOC由两部分组成,一个server和一个 client。为了让Conky显示这个脚本的运行结果,有必要在conkyrc的合适的地方加上
${exec 30 /.sh | fold -w55 -s}
如果使用conky没有问题,你也应该可以把它应用到gkrellm插件或者gnome-panel applet。

MOC & OSD


MOC没有内置的功能显示OSD播放信息——毕竟这只是个基于命令行的程序。直到有个叫做 robo 的用户,写出了两个bash脚本用 osd_cat 命令实现了OSD功能。他的脚本可以OSD的方式显示歌曲名、歌手、专辑信息、进度条和音量条。

代码: 全选

#!/bin/bash

FONT=-adobe-helvetica-bold-*-*-*-24-*-*-*-*-*-*-*
COLOR=red
SHADOW=0

TOTALSEC=`mocp --info | egrep "TotalSec:" | sed 's/TotalSec: //'`
CURRENTSEC=`mocp --info | egrep "CurrentSec:" |
sed 's/CurrentSec: //'`

PERCENT=`echo $(($CURRENTSEC*100/$TOTALSEC))`

mocp --info | egrep "^Artist:|^SongTitle:|^Album:" |
osd_cat --offset=10 --indent=10 --color=$COLOR --font=$FONT --shadow=$SHADOW &

osd_cat --offset=120 --indent=10 --color=$COLOR --font=$FONT \
--shadow=$SHADOW --barmode=percentage --percentage=$PERCENT

代码: 全选

#!/bin/bash

COLOR=red
SHADOW=0
# pasek lub procenty
BARMODE=slider

VOLUME=`amixer get Master | grep Front.Left: |
sed -e s/"  Front Left: Playback [0-9]* ["// | sed -e s/"%.*"//`

osd_cat --offset=10 --indent=10 --color=$COLOR --shadow=$SHADOW \
--barmode=$BARMODE --percentage=$VOLUME --delay=1
第一个脚本显示歌曲信息。第二个脚本显示当前音量,可以和下面的命令一同使用。

代码: 全选

amixer sset Master 1+   — 增加音量
amixer sset Master 1-   — 减少音量
这是个调节音量的好办法,你可以将其用xbindkeys定义。
"amixer sset Master 1+;~/.skrypty/volume.sh"
alt + b:4

"amixer sset Master 1-;~/.skrypty/volume.sh"
alt + b:5
上面的两条可以让你用鼠标滚轮和alt键控制音量。当你按下alt键并滚动鼠标滚轮的时候,你不光可以调节音量,同时屏幕也会显示一个音量OSD进度条。

自动运行MOC


MOC可以在不打开伪图形界面的状况下播放音乐。所以为什么不把MOC加入到启动脚本中呢?只需要用

代码: 全选

mocp -p
来启动MOC就可以了,前提是你有一个playlist。

听电台

我一般playlist里面就一个电台……顺便提一下MOC里面按o可以输入电台url,不过不支持 AAC。电台可以用ctrl+u添加到playlist里面去,我听的电台都是在 http://shoutcast.com 找的。我用这个脚本来更新OSD电台播放状态

代码: 全选

#/bin/bash

FONT=-*-lucidabright-*-r-*-*-34-*-*-*-*-*-*-*
COLOR=green
SHADOW=2
OFFSET=100

if [ "`pgrep mocp`" == '' ]; then
    exit
fi
if [ "$TITLEBK" == '' ]; then
    TITLEBK=nil
    export TITLEBK
fi

TITLE=`mocp --info | egrep "^SongTitle:"|sed 's/SongTitle: //' `
if [[ $TITLE != $TITLEBK ]]; then
    export TITLEBK=$TITLE
    echo $TITLE|
    osd_cat --offset=$OFFSET -A center --color=$COLOR --font=$FONT \
    --shadow=$SHADOWa --age=10
fi

sleep 2
exec $0 &
把MOC的快捷键之一定义成这个脚本就好了,我用的是F1。执行之后好像会假死,但其实你按Tab或者l就可以返回MOC的。

MOC快捷键列表
enter -- starts playing
s -- stops playing
n -- plays next item from the playlist
b -- plays previous item from the playlist
space -- pause
p -- pause

S -- plays at random
R -- repeats the same song in a loop,
Next (X button below) must be OFF
X -- switches to play sequentially
o -- plays a file from the Internet
u -- moves playlist item up
j -- moves playlist item down
Ctrl+u -- adds the URL to the playlist
g -- searches marked string in file names
/ -- searches marked string in file names

r -- rereads the directory
T -- switches to the theme selection menu
f -- toggles display mode of song titles
TAB -- switches marker bar between the playlist
and the file manager panels
l -- switches between displaying the playlist
or the file manager panel
P -- switches full path in the playlist
H -- toggles hidden files view
Ctrl-t -- toggles song duration time
Ctrl-f -- toggles format file view
m -- moves to directory entered in config file
G -- moves to directory with currently played file
i -- moves to marked directory
U -- moves to upper directory
a -- adds a file to the playlist
A -- adds a directory recursively to the playlist
C -- clears the playlist
V -- saves the playlist
d -- removes marked item from the playlist
Y -- removes all empty items from the playlist

< -- decreases volume by 1%
, -- decreases volume by 5%
> — increases volume by 1%
. — increases volume by 5%

x — toggles the mixer channel
? — shows help

! — goes to a fast dir 1 (set in config file)
@ — goes to a fast dir 2
# — goes to a fast dir 3
$ — goes to a fast dir 4
% — goes to a fast dir 5
^ — goes to a fast dir 6
& — goes to a fast dir 7
* — goes to a fast dir 8
( — goes to a fast dir 9
) — goes to a fast dir 10

F1 — executes ExecCommand1 (set in config file)
F2 — executes ExecCommand2
F3 — executes ExecCommand3
F4 — executes ExecCommand4
F5 — executes ExecCommand5
F6 — executes ExecCommand6
F7 — executes ExecCommand7
F8 — executes ExecCommand8
F9 — executes ExecCommand9
F10 — executes ExecCommand10
附件
mocposd.png
上次由 roylez 在 2007-08-31 9:18,总共编辑 2 次。
弄个dropbox空间来备份文件或者做私人代码服务器
配置:[url]git://github.com/roylez/dotfiles.git[/url]
主页:http://roylez.heroku.com
各种稀奇玩意儿:http://dooloo.info
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

#2

帖子 eexpress » 2007-08-13 10:27

Conky???为什么不XOsview或者gnome-swallow-applet。没测试。

写得蛮认真的吗,自己写的??

想得诺贝尔文学奖??

nnnnd
● 鸣学
头像
roylez
帖子: 1928
注册时间: 2005-10-04 10:59
来自: 上海

#3

帖子 roylez » 2007-08-13 10:33

大部分是翻译的……

干嘛专门针对我?难道我太帅了?
弄个dropbox空间来备份文件或者做私人代码服务器
配置:[url]git://github.com/roylez/dotfiles.git[/url]
主页:http://roylez.heroku.com
各种稀奇玩意儿:http://dooloo.info
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

#4

帖子 eexpress » 2007-08-13 10:35

好帅啊。就是比我崽崽差了一些而已。
● 鸣学
头像
roylez
帖子: 1928
注册时间: 2005-10-04 10:59
来自: 上海

#5

帖子 roylez » 2007-08-13 10:36

eexpress 写了:好帅啊。就是比我崽崽差了一些而已。
你说得太绝了吧……下次投胎好好努力了。
弄个dropbox空间来备份文件或者做私人代码服务器
配置:[url]git://github.com/roylez/dotfiles.git[/url]
主页:http://roylez.heroku.com
各种稀奇玩意儿:http://dooloo.info
头像
rhfcaesar
帖子: 2996
注册时间: 2005-11-17 15:45
来自: 湖北

#6

帖子 rhfcaesar » 2007-08-30 22:19

很有启发,支持一下! :D
头像
BigSnake.NET
帖子: 12522
注册时间: 2006-07-02 11:16
来自: 廣州
联系:

#7

帖子 BigSnake.NET » 2007-08-30 22:26

moc 播mp3能不能用mpg123的库, 不用mad
^_^ ~~~
要理解递归,首先要理解递归。

地球人都知道,理论上,理论跟实际是没有差别的,但实际上,理论跟实际的差别是相当大滴。
头像
nuanhuai
帖子: 7813
注册时间: 2009-03-10 13:04

Re: [部分翻译]MOCP高级使用技巧

#8

帖子 nuanhuai » 2009-08-22 10:16

好帅的帖子
头像
sirniu
帖子: 235
注册时间: 2009-05-31 22:52
联系:

Re: [部分翻译]MOCP高级使用技巧

#9

帖子 sirniu » 2009-08-22 10:58

楼主is a god! :em11
自從簽名被別人“借用”了之後我就不用了
头像
solcomo
帖子: 2838
注册时间: 2007-04-25 13:12

Re: [部分翻译]MOCP高级使用技巧

#11

帖子 solcomo » 2009-10-09 12:33

:em11 支持
♜♞♝♛♚♝♞♜
♟♟♟♟♟♟♟♟
♙♙♙♙♙♙♙♙
♖♘♗♕♔♗♘♖

☠☯⚔⚓☣☦☃☕
☹☻☪☭☬⚖⚛⚜
ℜℳℬ™ ℋℯℓ℘ ℳℭ
sƂɐʍ рǀɹoʍ əɥʇ oS
头像
kakashan
帖子: 417
注册时间: 2009-04-09 19:43
来自: Tianjin Polytechnic

Re: [部分翻译]MOCP高级使用技巧

#12

帖子 kakashan » 2009-10-18 21:52

厉害,学习。
庄子曰:相濡以沫,不如相忘于江湖
子曰:不能相濡以沫,不如相忘于江湖
回复