My personal dotfiles
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

spotify.el 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. ;;; spotify.el --- control the Spotify app from Emacs
  2. ;; Copyright (C) 2014-2016 Daniel Fernandes Martins
  3. ;; Keywords: multimedia, music, spotify
  4. ;; Package: spotify
  5. ;; Commentary:
  6. ;; This mode requires at least GNU Emacs 24.4 and Python 2.7
  7. ;; Before using this mode, first go the Spotify Web API console
  8. ;; <https://developer.spotify.com/my-applications> and create a new
  9. ;; application, adding <http://localhost:8591/> as the redirect URI.
  10. ;;
  11. ;; After requiring `spotify', make sure to define the client id and client
  12. ;; secrets, along with some other important settings:
  13. ;;
  14. ;; (custom-set-variables
  15. ;; '(spotify-oauth2-client-id "client-id")
  16. ;; '(spotify-oauth2-client-secret "client-secret")
  17. ;;
  18. ;; ; Only for Mac OS X, for now
  19. ;; '(spotify-transport 'apple)
  20. ;; '(spotify-osascript-bin-path "/usr/bin/osascript"))
  21. ;;
  22. ;; To authenticate, invoke the `spotify-connect' function. This will start the
  23. ;; Oauth2 authentication and authorization workflow. You may be asked to type
  24. ;; a password since the tokens are stored as an encrypted file in the local
  25. ;; filesystem. After you enter your credentials and authorizes the app, you
  26. ;; should see a greeting message in the echo area.
  27. ;;
  28. ;; To search for tracks, invoke the `spotify-track-search' function and
  29. ;; type your query. The results will be shown up in a new buffer. To play the
  30. ;; track under the cursor, just type RET, or type M-RET to play the
  31. ;; track's album from the start.
  32. ;; Code:
  33. (when (version< emacs-version "24.4")
  34. (error "Spotify requires at least GNU Emacs 24.4"))
  35. (require 'json)
  36. (require 'oauth2)
  37. (require 'tabulated-list)
  38. (require 'spotify-api)
  39. (require 'spotify-track-search)
  40. (require 'spotify-playlist-search)
  41. (require 'spotify-controller)
  42. (require 'spotify-remote)
  43. (when-darwin (require 'spotify-apple))
  44. (when-gnu-linux (require 'spotify-dbus))
  45. (defgroup spotify nil
  46. "Spotify client."
  47. :version "0.0.1"
  48. :group 'multimedia)
  49. ;;;###autoload
  50. (defun spotify-track-search (query)
  51. "Searches for tracks that match the given query string."
  52. (interactive "sSpotify Search (Tracks): ")
  53. (let ((buffer (get-buffer-create (format "*Track Search: %s*" query))))
  54. (with-current-buffer buffer
  55. (spotify-track-search-mode)
  56. (spotify-track-search-set-list-format)
  57. (setq-local spotify-query query)
  58. (setq-local spotify-current-page 1)
  59. (setq tabulated-list-entries nil)
  60. (pop-to-buffer buffer)
  61. (spotify-track-search-update 1)
  62. buffer)))
  63. ;;;###autoload
  64. (defun spotify-playlist-search (query)
  65. "Searches for playlists that match the given query string."
  66. (interactive "sSpotify Search (Playlists): ")
  67. (let ((buffer (get-buffer-create (format "*Playlist Search: %s*" query))))
  68. (with-current-buffer buffer
  69. (spotify-playlist-search-mode)
  70. (setq-local spotify-query query)
  71. (setq-local spotify-current-page 1)
  72. (setq tabulated-list-entries nil)
  73. (pop-to-buffer buffer)
  74. (spotify-playlist-search-update 1)
  75. buffer)))
  76. ;;;###autoload
  77. (defun spotify-my-playlists ()
  78. "Displays the current user's playlists."
  79. (interactive)
  80. (spotify-user-playlists (spotify-current-user-id)))
  81. ;;;###autoload
  82. (defun spotify-user-playlists (user-id)
  83. "Displays the public playlists of the given user."
  84. (interactive "sSpotify User ID: ")
  85. (let ((buffer (get-buffer-create (format "*Playlists: %s*" user-id))))
  86. (with-current-buffer buffer
  87. (spotify-playlist-search-mode)
  88. (setq-local spotify-user-id user-id)
  89. (setq-local spotify-current-page 1)
  90. (setq tabulated-list-entries nil)
  91. (pop-to-buffer buffer)
  92. (spotify-user-playlists-update user-id 1)
  93. buffer)))
  94. ;;;###autoload
  95. (defun spotify-featured-playlists ()
  96. "Displays Spotify's featured playlists."
  97. (interactive)
  98. (let ((buffer (get-buffer-create "*Featured Playlists*")))
  99. (with-current-buffer buffer
  100. (spotify-playlist-search-mode)
  101. (setq-local spotify-current-page 1)
  102. (setq tabulated-list-entries nil)
  103. (pop-to-buffer buffer)
  104. (spotify-featured-playlists-update 1)
  105. buffer)))
  106. ;;;###autoload
  107. (defun spotify-create-playlist (name is-public)
  108. "Creates an empty playlist owned by the current user."
  109. (interactive
  110. (list (read-string "Playlist name: ")
  111. (y-or-n-p "Make the playlist public? ")))
  112. (let ((new-playlist (spotify-api-playlist-create (spotify-current-user-id) name is-public)))
  113. (message (format "Playlist '%s' created" (spotify-get-item-name new-playlist)))))
  114. (provide 'spotify)