Full Code of krisajenkins/helm-spotify for AI

master f7a62d1ff88e cached
4 files
7.5 KB
2.1k tokens
1 requests
Download .txt
Repository: krisajenkins/helm-spotify
Branch: master
Commit: f7a62d1ff88e
Files: 4
Total size: 7.5 KB

Directory structure:
gitextract_xx41ul2y/

├── .gitignore
├── LICENSE.txt
├── README.org
└── helm-spotify.el

================================================
FILE CONTENTS
================================================

================================================
FILE: .gitignore
================================================
/flycheck-helm-spotify.el
/helm-spotify-autoloads.el


================================================
FILE: LICENSE.txt
================================================
The MIT License (MIT)

Copyright (c) 2013 Kris Jenkins

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


================================================
FILE: README.org
================================================
* Helm Spotify

A simple Emacs interface for Spotify that makes good use of helm.

[[helm-spotify.png]]

* Video

See how [[http://www.youtube.com/watch?v=XjKtkEMUYGc&feature=youtu.be][the first version was coded in 16 minutes]].

** Installation

If you're hooked up to [[http://melpa.milkbox.net/][MELPA]]:

#+BEGIN_EXAMPLE
M-x package-refresh-contents
M-x package-install RET helm-spotify
#+END_EXAMPLE

Alternatively just grab the single =helm-spotify.el= file and
install that in your preferred way.

* Usage

=M-x helm-spotify= and type a search string.

(The search begins after you've typed at least 2 characters. You can
use space-separated terms for psuedo-fuzzy matching.)

*** Keys

| =C-n=   | Next item.                       |
| =C-p=   | Previous item.                   |
| =RET=   | Play this track.                 |
| =C-z=   | Play this album.                 |
| =TAB=   | More options.                    |
| =C-h m= | Full list of keyboard shortcuts. |

* Status

Ready to use.

Currently OSX & Linux only. Windows support is available, but
partial. Please contribute the code for your platform, if you can!

* Supporting Other Platforms

Find out what emacs says your =system-type= is. (=C-h v system-type=).
Let's say it shows the symbol =ms-dos=. Then you need to write this function:

#+BEGIN_SRC emacs-lisp
  (defmulti-method spotify-play-href 'ms-dos
    (href)
    ...
    ... href is a string that's something like "spotify:track:5Yt80fWRB8JG73XlPjrrKP"
    ...
    ... here, you write any code that will cause Spotify to play that href.
    ...
    )
#+END_SRC

Then submit a pull request!

** Credits

Thanks to [[https://github.com/aes][Anders Eurenius]] for supplying the Linux portion of the code.
Thanks to [[https://github.com/Kungsgeten][Kungsgeten]] for supplying the Windows portion of the code.

I 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]]),
and to [[https://github.com/kurisuwhyte][Christina Whyte]] (for [[https://github.com/kurisuwhyte/emacs-multi][Emacs Multimethods]]).



================================================
FILE: helm-spotify.el
================================================
;;; helm-spotify.el --- Control Spotify with Helm.
;; Copyright 2013 Kris Jenkins
;;
;; Author: Kris Jenkins <krisajenkins@gmail.com>
;; Maintainer: Kris Jenkins <krisajenkins@gmail.com>
;; Keywords: helm spotify
;; URL: https://github.com/krisajenkins/helm-spotify
;; Created: 14th October 2013
;; Version: 0.1.1
;; Package-Requires: ((helm "0.0.0") (multi "2.0.0"))

;;; Commentary:
;;
;; A search & play interface for Spotify.
;;
;; Currently supports OSX, Linux & Windows.
;;
;; (Want support for another platform? There's a guide in the github README.)

;;; Code:

;;; API Reference: https://developer.spotify.com/technologies/web-api/
(require 'url)
(require 'json)
(require 'helm)
(require 'multi)

(defun alist-get (symbols alist)
  "Look up the value for the chain of SYMBOLS in ALIST."
  (if symbols
      (alist-get (cdr symbols)
		 (assoc (car symbols) alist))
    (cdr alist)))

(defmulti spotify-play-href (href)
  "Get the Spotify app to play the object with the given HREF."
  system-type)

(defmulti-method spotify-play-href 'darwin
  (href)
  (shell-command (format "osascript -e 'tell application %S to play track %S'"
			 "Spotify"
			 href)))

(defmulti-method spotify-play-href 'gnu/linux
  (href)
  (shell-command "dbus-send  --print-reply --session --type=method_call --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Pause")
  (shell-command (format "dbus-send --session --type=method_call --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.OpenUri \"string:%s\""
			 href)))

(defmulti-method spotify-play-href 'windows-nt
  (href)
  (shell-command (format "explorer %S" href)))

(defmulti-method-fallback spotify-play-href
  (href)
  (message "Sorry, helm-spotify does not support playing tracks on %S." system-type))

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

(defun spotify-get-track (album-href)
  (let ((response (with-current-buffer
                   (url-retrieve-synchronously album-href)
                   (goto-char url-http-end-of-headers)
                   (json-read))))
    (aref (alist-get '(tracks items) response) 0)))

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


(defun spotify-search (search-term)
  "Search spotify for SEARCH-TERM, returning the results as a Lisp structure."
  (let ((a-url (format "https://api.spotify.com/v1/search?q=%s&type=track" 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))))


(defun helm-spotify-search ()
  (spotify-search-formatted helm-pattern))

(defun helm-spotify-actions-for-track (actions track)
  "Return a list of helm ACTIONS available for this TRACK."
  `((,(format "Play Track - %s" (alist-get '(name) track))       . spotify-play-track)
    (,(format "Play Album - %s" (alist-get '(album name) track)) . spotify-play-album)
    ("Show Track Metadata" . pp)))

;;;###autoload
(defvar helm-source-spotify-track-search
  '((name . "Spotify")
    (volatile)
    (delayed)
    (multiline)
    (requires-pattern . 2)
    (candidates-process . helm-spotify-search)
    (action-transformer . helm-spotify-actions-for-track)))

;;;###autoload
(defun helm-spotify ()
  "Bring up a Spotify search interface in helm."
  (interactive)
  (helm :sources '(helm-source-spotify-track-search)
	:buffer "*helm-spotify*"))

(provide 'helm-spotify)
;;; helm-spotify.el ends here
Download .txt
gitextract_xx41ul2y/

├── .gitignore
├── LICENSE.txt
├── README.org
└── helm-spotify.el
Condensed preview — 4 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (8K chars).
[
  {
    "path": ".gitignore",
    "chars": 53,
    "preview": "/flycheck-helm-spotify.el\n/helm-spotify-autoloads.el\n"
  },
  {
    "path": "LICENSE.txt",
    "chars": 1079,
    "preview": "The MIT License (MIT)\n\nCopyright (c) 2013 Kris Jenkins\n\nPermission is hereby granted, free of charge, to any person obta"
  },
  {
    "path": "README.org",
    "chars": 2156,
    "preview": "* 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 ho"
  },
  {
    "path": "helm-spotify.el",
    "chars": 4407,
    "preview": ";;; helm-spotify.el --- Control Spotify with Helm.\n;; Copyright 2013 Kris Jenkins\n;;\n;; Author: Kris Jenkins <krisajenki"
  }
]

About this extraction

This page contains the full source code of the krisajenkins/helm-spotify GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 4 files (7.5 KB), approximately 2.1k tokens. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!