|
用terminal显示歌词.
所以先定义先启动一个term. 我用的是mlterm.
- #!/bin/bash
- if [ "$TERM" == "dumb" ]
- then
- mlterm -l 128 -O none -g 50x5+450+0 -T "audacious:Lyrics" -e $0 "$@" &
- exit
- fi
- /usr/bin/audacious "$@" 2>/dev/null
复制代码
在audacious 加上songchange插件.每次歌开始是运行显示歌词的脚本:
lyrics是显示歌词的脚本, 如下.
- #!/bin/bash
- kill -9 `ps -C ${0##*/} |awk '!/'"$$"'/{print $1}'`
- lyricdir=$HOME/music/lyrics
- time0=`date +%s`
- getname()
- {
- longname="`printf "${2//\%/\\x}"`"
- longname="${longname#file:\/\/}"
- if [ -f "${longname%.*}".lrc ]
- then
- name="${longname%.*}".lrc
- return 0
- fi
- name2="${longname##*/}"
- name2="${name2%.*}"
- if [ -f "$lyricdir/$name2".lrc ]
- then
- name="$lyricdir/$name2".lrc
- return 0
- fi
- singer="`echo ${1%% - *}|iconv -f utf8`"
- if [ -f "${longname}" ]
- then
- name="${longname%.*}".lrc
- return 1
- fi
- name2="`echo ${1##* - }|iconv -f utf8`"
- name="$lyricdir/$name2".lrc
- if [ -f "$lyricdir/$name2".lrc ]
- then
- return 0
- fi
- longname="$name2"
- return 1
- }
- showlyrics()
- {
- clear
- awk 'BEGIN{FS="]"}
- /^\[[0-9]+:[0-9]+/ && $NF !~/^[\ \r]*$/{
- for(i=1;i<NF;i++){
- sub("\[","",$(NF-i))
- num=split($(NF-i),time,":")
- axis=0
- for(j=0;j<num;j++){
- axis+=time[num-j]*60^j
- }
- printf("%d\t%s\n", axis, $NF)
- }
- }
- /^\[(ti|ar|al):/{sub("\[","",$1);
- print "0\t"$1;
- }' "$name" |sort -n|(tFS="$IFS"; read a b; while [ "$a" ]
- do
- while [ "$(($a-(`date +%s`-$time0)))" -ge 1 ]
- do
- echo -ne "$(($a-(`date +%s`-$time0))) \r"
- #sleep "1"
- comm=""
- IFS=""
- read -t 1 -n 1 comm <&2
- case "$comm" in
- " " | "p")audacious -t
- ptime=`date +%s`
- comm=""
- echo -ne "\rpause..."
- read -n 1 comm <&2
- audacious -t
- time0=$((`date +%s`-$ptime+$time0))
- echo -ne "\r \r";;
- "f" | "." | ">")audacious -f
- exit;;
- esac
- done
- echo -e "$b"
- IFS="$tFS"
- read a b
- done)
- }
- getname "$@" || getlrc-jpwy "$longname" "$singer"
- showlyrics
复制代码
getlrc-jpwj是下载歌词的脚本:
- #!/bin/bash
- #Usage: getlrc 歌名 [歌手 [专辑]]
- # or: getlrc mp3文件名 [歌手 [专辑]]
- #可以设置mp3文件关联, 就可以直接用它"打开"mp3文件, 下载歌词
- #要求gnome-terminal, wget
- #lrcdir可能要适当修改.
- export LC_CTYPE=zh_CN.GBK
- if [ "$TERM" == dumb ]
- then
- mlterm -e "$0" "$@"
- exit 0
- fi
- logfile=/dev/null
- result=/tmp/a.htm
- cookies=/tmp/lrc_cookies
- list="/tmp/lrclist"
- lrcdir="$HOME/music/lyrics"
- lrcfile="${1%.mp3}"
- if [ "$lrcfile" == "$1" ]
- then
- lrcfile="$lrcdir/$lrcfile"
- fi
- gm="`basename "$lrcfile"`"
- gm="${gm// /+}"
- gm="${gm//_/+}"
- zj="${3// /+}"
- gs="${2// /+}"
- searchanddown()
- {
- clear
- echo "歌名:$gm 歌手:$gs"
- wget -o $logfile -O $result --post-data='song='"$gm"'&singer='"$gs"'&album='"$zj"'&submit=%B8%E8%B4%CA%CB%D1%CB%F7' --referer="http://www.jpwy.net/gc/" http://www.jpwy.net/gc/search.php
- printf "%-4s%-18s%-14s%-12s\n" No. 歌名 歌手 专辑
- awk 'BEGIN{FS="(<[^>]+>| )+"; RS="</TR>"}
- /mp3/ && /sms/ && /list/ && /lrc/ { for (i=1;i<=NF;i++){printf( "%s\t", $i)};
- print "";
- num=split($0,link,""[^"]+ href="");
- sub("">.*","",link[num]);
- print link[num]>"/tmp/lrclist"
- }' "$result"|awk '{printf("%-4s%-18s%-14s%-12s\n", $1, $2, $3, $4)}'
- echo -n "下载序号(r重搜):"
- if [ "$xh"xx == "rxx" ]
- then
- read xh
- else
- read -t 10 xh
- fi
- if [ -z "$xh" ]
- then
- xh=1
- elif [ "$xh" == "r" ]
- then
- echo "输入歌名:"
- read gm
- echo "输入歌手:"
- read gs
- echo "输入专辑:"
- read zj
- searchanddown
- exit 1
- fi
- url=`awk 'FNR=='"$xh"' {print}' /tmp/lrclist`
- if [ -z "$url" ]
- then
- exit 1
- fi
- if wget -o $logfile -O "$lrcfile".lrc --referer="http://www.jpwy.net/gc/search.php" "$url"
- then
- echo download lyric successful
- sleep 2
- exit 0
- fi
- }
- searchanddown
复制代码 |
|