'How to get current playing song on mac by command line tools?

I can only find some applescripts on Google with specific music app(like itunes, spotify, etc) to get current playing song.

But now I'm using Netease Music which not supporting to be controled by applescript, I wonder if there is any universal way to get current playing song info via mac media center?

Applescript and other command line tools both ok.

enter image description here



Solution 1:[1]

enter image description here1

This following AppleScript code uses UI scripting to retrieve the currently playing media.

tell application "System Events" to tell process "Control Center"
    click menu bar item "Control Center" of menu bar 1
    set currentlyPlaying to value of static text 3 of window "Control Center"
    key code 53 -- press 'esc' key
end tell

activate
display dialog currentlyPlaying with title "Currently Playing" buttons ¬
    {"OK"} default button 1 giving up after 3

enter image description here2

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 wch1zpink