thomas-louvigne / playerctl.el

Play music from emacs with playerctl
Other
15 stars 7 forks source link

Adding a new command #6

Closed robertodr closed 2 years ago

robertodr commented 2 years ago

Hello and thanks for this package! I am trying to add a new command to show metadata from a player:

  (defun playerctl-metadata ()
    "Get metadata from playerctl player."
    (interactive)
    (let ((proc (start-process "playerctl.el" "*playerctl*" "playerctl" "metadata" "--format {{ playerName }}")))
      (set-process-filter proc (lambda
                                 (proc line)
                                 (message line))))
    )

The command playerctl metadata --format {{ playerName }} works fine in the terminal, but run within Emacs it gives: Unknown option --format {{ playerName }}. This is the first time I write an Emacs function, should command-line arguments be treated in a special way?

thomas-louvigne commented 2 years ago

ok, i found the problem, you can't put a space in an arg, so you must write "--format" and "{{playerName}}" in 2 separate args :

  (defun playerctl-metadata ()
    "Get metadata from playerctl player."
    (interactive)
    (let ((proc (start-process "playerctl.el" "*playerctl*" "playerctl" "metadata" "--format" "{{playerName}}")))
      (set-process-filter proc (lambda
                                 (proc line)
                                 (message line))))
    )

I am also a true newbee in elisp. But i learned something today with you 😃

robertodr commented 2 years ago

Excellent. That was the only combination I had not tried, as I could not see any such suggestion in the documentation for start-process!

thomas-louvigne commented 2 years ago

Yea, the documentation is not good. So, you want push a new feature ?

robertodr commented 2 years ago

I'd like to. I've expanded the metadata to query:

(defun playerctl-metadata ()
  "Get metadata from playerctl player."
  (interactive)
  (let ((proc (start-process "playerctl.el" "*playerctl*" "playerctl" "metadata" "--format" "{{ playerName }}" "{{ lc(status) }}:" "{{ artist }}" "-" "{{ album }}" "-" "{{ title }}")))
    (set-process-filter proc (lambda
                               (proc line)
                               (message line))))
  )

and I only get the playerName. Need to debug a bit more before submitting a PR.

thomas-louvigne commented 2 years ago

cool !