krisajenkins / helm-spotify

A simple Spotify-for-Emacs interface.
MIT License
180 stars 21 forks source link

Spotify Endpoint Deprecated #19

Open mitchellgordon95 opened 8 years ago

mitchellgordon95 commented 8 years ago

Hey there! On OSX, emacs 24.5.1, using the spacemacs configuration, Spotify version 1.0.27.75.gdc223232. I don't see any results from the helm search. Not sure if I'm missing some kind of setup or whatever.

mitchellgordon95 commented 8 years ago

Bump Get this error when trying to run it: Error running timer: (error "In Spotify' source:helm-spotify-search' (json-readtable-error)")

mitchellgordon95 commented 8 years ago

Double bump The endpoint we're using is deprecated http://ws.spotify.com/search/1/track.json?q=test

asummers commented 8 years ago

Change the functions spotify-search, spotify-format-track and spotify-search-formatted.

(defun spotify-search (search-term)
  "Search spotify for SEARCH-TERM, returning the results as a Lisp structure."
  (let ((a-url (format "http://api.spotify.com/v1/search?type=track&q=%s" search-term)))
    (with-current-buffer
    (url-retrieve-synchronously a-url)
      (goto-char url-http-end-of-headers)
      (json-read))))

(defun spotify-format-track (track)
  "Given a TRACK, return a a formatted string suitable for display."
  (let ((track-name   (alist-get '(name) track))
    (track-length (/ (alist-get '(duration_ms) track)) 1000)
    (album-name   (alist-get '(album name) track))
    (artist-names (mapcar (lambda (artist)
                (alist-get '(name) artist))
                  (alist-get '(artists) track))))
    (format "%s (%dm%0.2ds)\n%s - %s"
        track-name
        (/ track-length 60) (mod track-length 60)
        (mapconcat 'identity artist-names "/")
        album-name)))

(defun spotify-search-formatted (search-term)
  (mapcar (lambda (track)
        (cons (spotify-format-track track) track))
      (alist-get '(tracks items) (spotify-search search-term))))

Notably: URL change, and length is no longer a field, it is now duration_ms and items are the grouping in the response.

Also note, on OSX for me, using the href to play the track no longer works and must be changed to uri:

(defun spotify-play-track (track)
  "Get the Spotify app to play the TRACK."
  (spotify-play-href (alist-get '(uri) track)))