1

有没有办法以编程方式获取节奏盒(甚至是 Linux 上的任何音乐播放器)中当前播放曲目的完整路径?它可以是 linux 命令或 python 中的命令。

我需要它来使用快捷方式对我的新音乐专辑进行排序(即,删除或存档当前播放的文件,直到新音乐文件夹为空)。我是用 amarok 做的,但在新版本中,我的插件不再工作,而且还没有文档。

4

2 回答 2

1

安装mp3info和使用这个脚本:

#!/bin/sh

apps="vlc totem rhythmbox banshee mplayer gnome-mplayer"

for app in $apps
do
  pat="([^\w-]$app)"
  if ps ux | grep -P $pat | grep -vq grep; then
    echo
    echo "$app detected"
    echo -------------------------
    file=`lsof -F n -c "$app" | grep -i "^.*\.mp3$" | sed 's/^n//g'`
    if [ ! -z "$file" ]; then
      echo -n "Now playing: "
      if mp3info "$file" 2>&1 | grep -q "does not have an ID3"; then
        echo $file
        echo MP3 info missing \(ID3v2 not supported\)    
      else
        echo
        mp3info "$file"
      fi
    else
      echo Playing no MP3 files
    fi
  fi
done

归功于 Vaphell ( https://ubuntuforums.org/showthread.php?t=1562395&s=4ea6cfb6ce5e37681f20a82af578825f&p=9785684#post9785684 )。

于 2021-06-01T12:31:53.327 回答
0

可以用 mplayer 来完成:

path=`lsof -c mplayer | grep -E '\.m4a|\.mp3|\.flac|\.mp4|\.wav|\.wma|\.aac' | sed "s+.*\(/home/$USER.*\)+\1+g"`

细节:

  • lsof -c mplayer: 列出 mplayer 当前使用的所有文件;
  • grep -E '\.m4a|\.mp3|\.flac|\.mp4|\.wav|\.wma|\.aac':只保留音频文件的行(可能有更优雅的方式来做到这一点......);
  • sed "s+.*\(/home/$USER.*\)+\1+g":删除行前缀(如果您的音乐文件不在 /home/$USER 中,则进行调整)。
于 2021-01-01T17:30:31.273 回答