[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[emms-help] emms-info-youtube

From: Konstantin Reich
Subject: [emms-help] emms-info-youtube
Date: Thu, 05 Sep 2019 17:19:21 +0300


I am trying to write an emms info function, which fetches the title from 
youtube url.
The synchronous version of such function works good, but freezes Emacs. So i am 
trying to figure out how to do it asynchronously.
Somehow, (emms-track-set track 'info-title title) does not work, even although 
I provided "track" and "title".

Could you help me to figure out what is wrong. The code is below:

(defun emms-info-youtube (track)
  (when (eq 'url (emms-track-type track))
    (let ((url (emms-track-name track)))
      (when (string-match "youtube" url)
        (let* ((id (make-temp-name ""))
               (process-name (format "youtube-%s" id))
               (buffer-name (format "*youtube-%s*" id))
               (buffer (get-buffer-create buffer-name)))
          (with-current-buffer buffer
            (make-local-variable 'url)
            (make-local-variable 'track)
             (start-process process-name buffer "youtube-dl" "-e" url)

(defun youtube-sentinel (process event)
  (let ((buffer (process-buffer process)))
    (with-current-buffer buffer
      (when (string-match-p "finished" event)
        (goto-char (point-min))
        (let ((title (buffer-substring (point-min) (line-end-position))))

          ;;;; To this point everything works well. The title and track are 
determined, but the following line does nothing.

          (emms-track-set track 'info-title title))
        (kill-buffer buffer))
      (when (string-match-p "abnormal" event)
        (message "youtube failed: %s" url)))))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]