分页: 2 / 2

Re: 居然又折腾了下conky。moc显示歌词的脚本

发表于 : 2010-01-21 20:42
xiooli
python 版本

代码: 全选

#!/usr/bin/python
# -*- coding: utf-8 -*-

import os, sys
info = os.popen("mocp -i").readlines()
info_dic = dict(map(lambda x: x.replace("\n", "").split(": "), info))

print info_dic["Title"]
if info_dic["State"] != "PLAY": sys.exit(1)
else:
    lrc_file = os.path.splitext(info_dic["File"])[0] + '.lrc'
    if os.path.exists(lrc_file):
        lrc_line = os.popen("grep " + info_dic["CurrentTime"] + " " + lrc_file).readlines()
        if lrc_line:
            lrc_line = lrc_line[0].split("]")[-1]
            os.system("echo '" + lrc_line + "' >/tmp/mocp-last-lrc")
            print lrc_line
        else:
            lrc_line = os.popen("cat /tmp/mocp-last-lrc").readlines()
            if lrc_line: print lrc_line[0]
    else:
        print "==无歌词文件=="
        sys.exit(0)
ps: 其实我们那个 lrcdis 只要用 fifo 模式,然后在 conkyrc 里面添加一个 cat /shm/lrcfifo 就可以了阿,实际种播放器支持呢,

Re: 居然又折腾了下conky。moc显示歌词的脚本

发表于 : 2010-01-21 20:46
adagio
我支持 xiooli, 干掉EE :em76

Re: 居然又折腾了下conky。moc显示歌词的脚本

发表于 : 2010-01-21 20:47
adagio
不过貌似python的玩意跑起来费劲一点 :em04

Re: 居然又折腾了下conky。moc显示歌词的脚本

发表于 : 2010-01-21 20:53
xiooli
adagio 写了:不过貌似python的玩意跑起来费劲一点 :em04
咋会费劲些呢? 不过写这个 bash 就足够了,ee 大婶那里还不是调用了系统命令。

Re: 居然又折腾了下conky。moc显示歌词的脚本

发表于 : 2010-01-24 12:47
eexpress
额。你错了。说grep? 那是懒得开文件,偷懒而已,从老脚本继承过来的。可你的还加了,echo 管道出去的哦。你看,我那保存,占用了一半长度。
py 语法罗嗦。那map都这么罗嗦?

Re: 居然又折腾了下conky。moc显示歌词的脚本

发表于 : 2010-04-09 12:53
eexpress
加了一个共用~/.lyrics目录的功能。

代码: 全选

● cat mocp-lrc.pl 
#!/usr/bin/perl

use utf8;
@info=`mocp -i`;
%hinfo=map{split /: /} @info;

print $hinfo{Title};
$_=$hinfo{State}; print,exit if ! /PLAY/;       #不是播放状态
chomp %hinfo;

$_=$hinfo{File}; s/(ogg|mp3)$/lrc/;     # 同目录的lrc
if(-s){$find=$_;}else{
$_="$ENV{HOME}/.lyrics/$hinfo{Artist}/$hinfo{SongTitle}.lrc";
#print;
if(-s){$find=$_;}
}
if(! $find){print "==无歌词文件==";exit 0;}

$_=`grep -m 1 \'$hinfo{CurrentTime}\' $find`;
if (! $_)               #无新歌词,不更新输出,打印记录的行
{
open (OUT, "/tmp/mocp-last-lrc");print <OUT>;close OUT;exit 0;
}
s/\xd//; s/\[.*\]//g;
print;
open (OUT, ">/tmp/mocp-last-lrc"); print OUT; close OUT;

Re: 居然又折腾了下conky。moc显示歌词的脚本

发表于 : 2010-04-13 13:19
eagle5678
神,conky刷新不爽

Re: 居然又折腾了下conky。moc显示歌词的脚本

发表于 : 2010-10-21 15:09
fyq
上面的脚本似乎不能处理带有空格的歌曲名称?
我不会python和perl,求修正?

Re: 居然又折腾了下conky。moc显示歌词的脚本

发表于 : 2010-10-21 15:36
eexpress
/home/exp/媒体/音乐●/Disney Pop Station
/home/exp/媒体/音乐●/The Platinum Album
我不记得有问题。

Re: 居然又折腾了下conky

发表于 : 2010-10-21 16:28
adsl
tenzu 写了:神,加个草榴新贴的脚本吧 :em04
同感!!