├── README.md ├── images └── image.png ├── lyrics.lrc └── song.sh /README.md: -------------------------------------------------------------------------------- 1 | # waybar-netease-music-lyrics 2 | ![本地路径](./images/image.png "状态栏") 3 | 在waybar上显示网易云音乐歌曲信息和当前歌词 4 | 目前支持feeluown、ElectronNCM、netease-cloud-music 5 | 6 | 7 | -------------------------------------------------------------------------------- /images/image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kangxiaoju/waybar-netease-music-lyrics/f84810fe1628ca38fa36d88506152d88cf0e77e4/images/image.png -------------------------------------------------------------------------------- /lyrics.lrc: -------------------------------------------------------------------------------- 1 | 夜半歌声 2 | 3 | [00:31.23]途经这夜灰的街角 琴声像怨曲伴弦乐 4 | [00:42.65]无数晚上是母子的歌声 5 | [00:48.06]令这街夜冷添上淒清 6 | [00:56.54]无心再路经这街角 如今独幼子在弹乐 7 | [01:08.42]寒冷晚上 夜雨彷彿低泣 8 | [01:13.49]像痛哀挚爱今已痛失 9 | [01:22.19]这小手在颤抖 任泪光眼内透 10 | [01:27.80]没法可预计将来的以后 11 | [01:33.36]这小手在颤抖 独在暗街似木偶 12 | [01:39.14]之中苦痛彷彿躲藏背后 13 | [02:07.59]长街怨乐声风飘送 无声倦眼光极沉重 14 | [02:18.77]谁会领会夜冷瑟缩街中 15 | [02:24.34]没法懂运数可有变通 16 | [02:32.99]这小手在颤抖 任泪光眼内透 17 | [02:38.63]没怨天是否公平的宇宙 18 | [02:44.30]坐街中每分钟路上眼光已受够 19 | [02:50.02]不懂打算怎过将来以后 20 | [02:58.67]这小手在颤抖 任泪光眼内透 21 | [03:04.31]没怨天是否公平的宇宙 22 | [03:09.93]坐街中每分钟路上眼光已受够 23 | [03:15.51]不懂打算怎过将来以后 24 | [03:21.38]真想知道可有公平宇宙 25 | 26 | -------------------------------------------------------------------------------- /song.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | playerName=$(playerctl --list-all | head -n 1) 4 | #playerName="feeluown" 5 | playerShell="playerctl --player=$playerName" 6 | lyricsPath="$HOME/.config/waybar/lyrics.lrc" 7 | songIcons="$HOME/.config/waybar/scripts/songIcon" 8 | songSt=$($playerShell status) 9 | 10 | song(){ 11 | # 歌曲标题 12 | title=$($playerShell metadata title) 13 | if [[ $title != "" ]]; then 14 | songId=$(getSongId) 15 | # 播放当前时间 16 | position=$($playerShell metadata --format '{{ duration(position) }}') 17 | # 音乐播放器当前状态 18 | status=$($playerShell status) 19 | # 歌曲总长度 20 | length=$($playerShell metadata --format '{{ duration(mpris:length) }}') 21 | # 歌曲名称 22 | oldTitle=$(head -n +1 $lyricsPath) 23 | if [ "$title" != "$oldTitle" ]; then 24 | # 删除上首歌的图片 25 | rm -rf $songIcons/* 26 | echo "" > $lyricsPath 27 | echo "" >> $lyricsPath 28 | sed -i "1 c $title" $lyricsPath 29 | getSongMedia $songId 30 | notifySongInfo $songId 31 | fi 32 | # 写入歌词 33 | lyrics=$(cat $lyricsPath | grep "$position" | awk -F ']' '{print $NF}' | head -n 1) 34 | if [ -n "$lyrics" ]; then 35 | sed -i "2 c $lyrics" $lyricsPath 36 | fi 37 | echo "$(sed -n 2p $lyricsPath)" 38 | fi 39 | } 40 | 41 | getSongId() { 42 | if [[ $playerName == "ElectronNCM" ]];then 43 | echo $($playerShell metadata mpris:trackid | cut -d "/" -f5 | cut -d "'" -f1) 44 | elif [[ $playerName == "feeluown" ]]; then 45 | echo $($playerShell metadata mpris:trackid | cut -d "/" -f7) 46 | elif [[ $playerName == "netease-cloud-music" ]]; then 47 | jsonPath="$HOME/.cache/netease-cloud-music/StorageCache/webdata/file/queue" 48 | echo $(jq -r '.[]|.track.name,.track.id' $jsonPath | grep -A 1 "$title" | sed -n '2p') 49 | elif [[ $playerName == "yesplaymusic" ]]; then 50 | echo $(curl -s http://127.0.0.1:27232/player | jq -r .currentTrack.id) 51 | elif [[ $playerName == "musicfox" ]]; then 52 | echo $($playerShell metadata mpris:trackid | cut -d "/" -f5 | cut -d "'" -f1) 53 | elif [[ $playerName == "Qcm" ]]; then 54 | echo $($playerShell metadata mpris:trackid | cut -d "/" -f3 | cut -d "'" -f1) 55 | elif [[ $playerName == "NeteaseCloudMusicGtk4" ]]; then 56 | echo $($playerShell metadata mpris:trackid | cut -d "/" -f6 | cut -d "'" -f1) 57 | fi 58 | 59 | } 60 | 61 | getSongMedia(){ 62 | songId=$1 63 | # 请求歌词 64 | curl -s http://music.163.com/api/song/media?id=$songId | jq -r '.lyric' >> $lyricsPath 65 | } 66 | 67 | # 下载歌曲图片 68 | notifySongInfo(){ 69 | # 演唱者 70 | artist=$($playerShell metadata artist) 71 | # 专辑名称 72 | album=$($playerShell metadata album) 73 | songId=$1 74 | # 歌曲本地图片 75 | icon=$($playerShell metadata mpris:artUrl) 76 | # 获取图片后缀名 77 | iconSu=$(echo "${icon##*.}") 78 | # 下载图片 79 | curl -s -L $icon -o "$songIcons/$songId.$iconSu" 80 | # 弹出提示框 81 | notify-send -h string:x-dunst-stack-tag:music "$title-$artist" $album -t 800 --icon "$songIcons/$songId.$iconSu" 82 | } 83 | 84 | title(){ 85 | if [[ $songSt == "Playing" ]];then 86 | echo "$($playerShell metadata title) "; 87 | fi 88 | } 89 | 90 | post() { 91 | if [[ $songSt == "Playing" ]];then 92 | dp=$($playerShell metadata --format '{{ duration(position) }}') 93 | if [[ $dp != "" ]]; then 94 | duration=$(feeluown status | grep 'duration' | sed 's/duration: //' | bc) 95 | le="$(date -u -d @${duration} +"%M:%S")" 96 | if [[ $le != "" ]]; then 97 | echo " [$dp|$le] " 98 | else 99 | echo " [$dp] " 100 | fi 101 | fi 102 | fi 103 | 104 | } 105 | 106 | songStatus(){ 107 | # 音乐播放器当前状态 108 | if [[ $songSt == "Playing" ]];then 109 | echo "♫ ♪ ♫ ♪ ♥ " 110 | else 111 | echo "_ z Z Z ♥ " 112 | fi 113 | } 114 | 115 | 116 | case "$1" in 117 | "songStatus") 118 | songStatus 119 | ;; 120 | "post") 121 | post 122 | ;; 123 | "title") 124 | title 125 | ;; 126 | "songId") 127 | getSongId 128 | ;; 129 | *) 130 | song 131 | ;; 132 | esac 133 | --------------------------------------------------------------------------------