[
  {
    "path": ".gitignore",
    "content": "/flycheck-helm-spotify.el\n/helm-spotify-autoloads.el\n"
  },
  {
    "path": "LICENSE.txt",
    "content": "The MIT License (MIT)\n\nCopyright (c) 2013 Kris Jenkins\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the \"Software\"), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\nthe Software, and to permit persons to whom the Software is furnished to do so,\nsubject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\nFOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\nCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\nIN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\nCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n"
  },
  {
    "path": "README.org",
    "content": "* Helm Spotify\n\nA simple Emacs interface for Spotify that makes good use of helm.\n\n[[helm-spotify.png]]\n\n* Video\n\nSee how [[http://www.youtube.com/watch?v=XjKtkEMUYGc&feature=youtu.be][the first version was coded in 16 minutes]].\n\n** Installation\n\nIf you're hooked up to [[http://melpa.milkbox.net/][MELPA]]:\n\n#+BEGIN_EXAMPLE\nM-x package-refresh-contents\nM-x package-install RET helm-spotify\n#+END_EXAMPLE\n\nAlternatively just grab the single =helm-spotify.el= file and\ninstall that in your preferred way.\n\n* Usage\n\n=M-x helm-spotify= and type a search string.\n\n(The search begins after you've typed at least 2 characters. You can\nuse space-separated terms for psuedo-fuzzy matching.)\n\n*** Keys\n\n| =C-n=   | Next item.                       |\n| =C-p=   | Previous item.                   |\n| =RET=   | Play this track.                 |\n| =C-z=   | Play this album.                 |\n| =TAB=   | More options.                    |\n| =C-h m= | Full list of keyboard shortcuts. |\n\n* Status\n\nReady to use.\n\nCurrently OSX & Linux only. Windows support is available, but\npartial. Please contribute the code for your platform, if you can!\n\n* Supporting Other Platforms\n\nFind out what emacs says your =system-type= is. (=C-h v system-type=).\nLet's say it shows the symbol =ms-dos=. Then you need to write this function:\n\n#+BEGIN_SRC emacs-lisp\n  (defmulti-method spotify-play-href 'ms-dos\n    (href)\n    ...\n    ... href is a string that's something like \"spotify:track:5Yt80fWRB8JG73XlPjrrKP\"\n    ...\n    ... here, you write any code that will cause Spotify to play that href.\n    ...\n    )\n#+END_SRC\n\nThen submit a pull request!\n\n** Credits\n\nThanks to [[https://github.com/aes][Anders Eurenius]] for supplying the Linux portion of the code.\nThanks to [[https://github.com/Kungsgeten][Kungsgeten]] for supplying the Windows portion of the code.\n\nI tip my hat to the team behind [[https://github.com/emacs-helm/helm][Helm]], to [[https://github.com/purcell][Steve Purcell]] (for [[https://github.com/milkypostman/melpa][Melpa]]),\nand to [[https://github.com/kurisuwhyte][Christina Whyte]] (for [[https://github.com/kurisuwhyte/emacs-multi][Emacs Multimethods]]).\n\n"
  },
  {
    "path": "helm-spotify.el",
    "content": ";;; helm-spotify.el --- Control Spotify with Helm.\n;; Copyright 2013 Kris Jenkins\n;;\n;; Author: Kris Jenkins <krisajenkins@gmail.com>\n;; Maintainer: Kris Jenkins <krisajenkins@gmail.com>\n;; Keywords: helm spotify\n;; URL: https://github.com/krisajenkins/helm-spotify\n;; Created: 14th October 2013\n;; Version: 0.1.1\n;; Package-Requires: ((helm \"0.0.0\") (multi \"2.0.0\"))\n\n;;; Commentary:\n;;\n;; A search & play interface for Spotify.\n;;\n;; Currently supports OSX, Linux & Windows.\n;;\n;; (Want support for another platform? There's a guide in the github README.)\n\n;;; Code:\n\n;;; API Reference: https://developer.spotify.com/technologies/web-api/\n(require 'url)\n(require 'json)\n(require 'helm)\n(require 'multi)\n\n(defun alist-get (symbols alist)\n  \"Look up the value for the chain of SYMBOLS in ALIST.\"\n  (if symbols\n      (alist-get (cdr symbols)\n\t\t (assoc (car symbols) alist))\n    (cdr alist)))\n\n(defmulti spotify-play-href (href)\n  \"Get the Spotify app to play the object with the given HREF.\"\n  system-type)\n\n(defmulti-method spotify-play-href 'darwin\n  (href)\n  (shell-command (format \"osascript -e 'tell application %S to play track %S'\"\n\t\t\t \"Spotify\"\n\t\t\t href)))\n\n(defmulti-method spotify-play-href 'gnu/linux\n  (href)\n  (shell-command \"dbus-send  --print-reply --session --type=method_call --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Pause\")\n  (shell-command (format \"dbus-send --session --type=method_call --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.OpenUri \\\"string:%s\\\"\"\n\t\t\t href)))\n\n(defmulti-method spotify-play-href 'windows-nt\n  (href)\n  (shell-command (format \"explorer %S\" href)))\n\n(defmulti-method-fallback spotify-play-href\n  (href)\n  (message \"Sorry, helm-spotify does not support playing tracks on %S.\" system-type))\n\n(defun spotify-play-track (track)\n  \"Get the Spotify app to play the TRACK.\"\n  (spotify-play-href (alist-get '(uri) track)))\n\n(defun spotify-get-track (album-href)\n  (let ((response (with-current-buffer\n                   (url-retrieve-synchronously album-href)\n                   (goto-char url-http-end-of-headers)\n                   (json-read))))\n    (aref (alist-get '(tracks items) response) 0)))\n\n(defun spotify-play-album (track)\n  \"Get the Spotify app to play the album for this TRACK.\"\n  (let ((first-track (spotify-get-track (alist-get '(album href) track))))\n    (spotify-play-href (alist-get '(uri) first-track))))\n\n\n(defun spotify-search (search-term)\n  \"Search spotify for SEARCH-TERM, returning the results as a Lisp structure.\"\n  (let ((a-url (format \"https://api.spotify.com/v1/search?q=%s&type=track\" search-term)))\n    (with-current-buffer\n\t(url-retrieve-synchronously a-url)\n      (goto-char url-http-end-of-headers)\n      (json-read))))\n\n(defun spotify-format-track (track)\n  \"Given a TRACK, return a a formatted string suitable for display.\"\n  (let ((track-name   (alist-get '(name) track))\n\t(track-length (/ (alist-get '(duration_ms) track) 1000))\n\t(album-name   (alist-get '(album name) track))\n\t(artist-names (mapcar (lambda (artist)\n\t\t\t\t(alist-get '(name) artist))\n\t\t\t      (alist-get '(artists) track))))\n    (format \"%s (%dm%0.2ds)\\n%s - %s\"\n\t    track-name\n\t    (/ track-length 60) (mod track-length 60)\n\t    (mapconcat 'identity artist-names \"/\")\n\t    album-name)))\n\n(defun spotify-search-formatted (search-term)\n  (mapcar (lambda (track)\n\t    (cons (spotify-format-track track) track))\n\t  (alist-get '(tracks items) (spotify-search search-term))))\n\n\n(defun helm-spotify-search ()\n  (spotify-search-formatted helm-pattern))\n\n(defun helm-spotify-actions-for-track (actions track)\n  \"Return a list of helm ACTIONS available for this TRACK.\"\n  `((,(format \"Play Track - %s\" (alist-get '(name) track))       . spotify-play-track)\n    (,(format \"Play Album - %s\" (alist-get '(album name) track)) . spotify-play-album)\n    (\"Show Track Metadata\" . pp)))\n\n;;;###autoload\n(defvar helm-source-spotify-track-search\n  '((name . \"Spotify\")\n    (volatile)\n    (delayed)\n    (multiline)\n    (requires-pattern . 2)\n    (candidates-process . helm-spotify-search)\n    (action-transformer . helm-spotify-actions-for-track)))\n\n;;;###autoload\n(defun helm-spotify ()\n  \"Bring up a Spotify search interface in helm.\"\n  (interactive)\n  (helm :sources '(helm-source-spotify-track-search)\n\t:buffer \"*helm-spotify*\"))\n\n(provide 'helm-spotify)\n;;; helm-spotify.el ends here\n"
  }
]