Stream ListenBrainz.org Music Playlist in GNU Emacs

 

 

Here's an Emacs Multimedia System (EMMS) extension for streaming ListenBrainz.org music playlist using mpv player (with ytdl support).

Irrespective of how satisfied you are with your music streaming service, you should plan for maintaining a playlist of your favorite music in an open format. The popular service might be forced to close down because of non-profitability even when you are willing to pay for ad-free music streaming. e.g. Worldspace radio customers even paid for the device in addition to the subscription fees.

The code uses following function from tumblesocks codebase. In case you don't use tumblesocks, you'll need to define it yourself.
(defun tumblesocks-api-process-response (&optional service)
  "Process Tumblr's response in the current buffer,
returning JSON or signaling an error for other requests."
  (decode-coding-region (point-min) (point-max) 'utf-8-dos)
  ;; the following copied from url.el
  (goto-char (point-min))
  (skip-chars-forward " \t\n")        ; Skip any blank crap
  (skip-chars-forward "HTTP/")        ; Skip HTTP Version
  (skip-chars-forward "[0-9].")
  (let ((pointpos (point))
        (code (read (current-buffer))))
    (cond
     ((= code 100) ;; Gotta clean up the buffer and try again
      (search-forward-regexp "^$" nil t)
      (delete-region (point-min) (point))
      (tumblesocks-api-process-response))
     ((not (and (<= 200 code) (<= code 299)))
      (if (= code 401)
      (setq tumblesocks-token
        (delq (assoc service tumblesocks-token) tumblesocks-token)))
      (error (buffer-substring pointpos
                               (line-end-position))))
     (t
      (search-forward-regexp "^$" nil t)
      ;; body
      (let* ((json-response (buffer-substring (1+ (point)) (point-max)))
             (json-object-type 'plist)
             (json-array-type 'list)
             (json-false nil))
        ;; (plist-get (json-read-from-string json-response)
        ;;            :response)
    (json-parse-string json-response)
    )))))
 
 

Usage

You'll need mpv and ytdl installed. Configure emms as follows:

(require 'emms-player-mpv)
(setq emms-player-list '(emms-player-mpv))
(require 'listenbrainz)
 
;; Optionally, turn off video
(add-to-list 'emms-player-mpv-parameters "--no-video")
 

You'll need an API token from Listenbrainz for using the service. You can get it here.

Use M-x emms-listenbrainz to create a playlist buffer for Listenbrainz. Then you can use emms smart playlist keybindings for interaction with the playlist.

 

Tag Editor

EMMS supports editings tags for MP3, OGG and FLAC. Use E in playlist mode to display/edit the tag. Save the buffer to apply the changes.
 
(require 'emms-tag-editor)
  

Code

 

Comments

Popular posts from this blog

GNU Emacs as a Comic Book Reader

Data Visualization with GNU Emacs

Mozilla Readability in GNU Emacs