emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master 74358c2 070/348: Purge all dependency on helm-rhythmbox


From: Oleh Krehel
Subject: [elpa] master 74358c2 070/348: Purge all dependency on helm-rhythmbox
Date: Sat, 8 Apr 2017 11:03:29 -0400 (EDT)

branch: master
commit 74358c2781353c80113fae0f5e27f3a857f8739e
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>

    Purge all dependency on helm-rhythmbox
    
    Got tired of a breaking interface change every two months.
    
    * counsel.el (counsel-rhythmbox-play-song): New defun.
    (counsel-rhythmbox-history): New defvar.
    (counsel-rhythmbox): Update.
---
 counsel.el | 50 +++++++++++++++++++++++++++++++++++---------------
 1 file changed, 35 insertions(+), 15 deletions(-)

diff --git a/counsel.el b/counsel.el
index 30c8f96..4fce04d 100644
--- a/counsel.el
+++ b/counsel.el
@@ -2099,24 +2099,30 @@ And insert it into the minibuffer. Useful during
 
 ;;* Misc OS
 ;;** `counsel-rhythmbox'
-(defvar helm-rhythmbox-library)
-(declare-function helm-rhythmbox-load-library "ext:helm-rhythmbox")
 (declare-function dbus-call-method "dbus")
 (declare-function dbus-get-property "dbus")
-(declare-function helm-rhythmbox-song-uri "ext:helm-rhythmbox")
-(declare-function helm-rhythmbox-candidates "ext:helm-rhythmbox")
 
-(defun counsel-rhythmbox-enqueue-song (song)
+(defun counsel-rhythmbox-play-song (uri)
+  "Let Rhythmbox enqueue SONG."
+  (let ((service "org.gnome.Rhythmbox3")
+        (path "/org/mpris/MediaPlayer2")
+        (interface "org.mpris.MediaPlayer2.Player"))
+    (dbus-call-method :session service path interface
+                      "OpenUri" uri)))
+
+(defun counsel-rhythmbox-enqueue-song (uri)
   "Let Rhythmbox enqueue SONG."
   (let ((service "org.gnome.Rhythmbox3")
         (path "/org/gnome/Rhythmbox3/PlayQueue")
         (interface "org.gnome.Rhythmbox3.PlayQueue"))
     (dbus-call-method :session service path interface
-                      "AddToQueue" (helm-rhythmbox-song-uri song))))
+                      "AddToQueue" uri)))
 
 (defvar counsel-rhythmbox-history nil
   "History for `counsel-rhythmbox'.")
 
+(defvar counsel-rhythmbox-songs nil)
+
 (defun counsel-rhythmbox-current-song ()
   "Return the currently playing song title."
   (ignore-errors
@@ -2135,21 +2141,35 @@ And insert it into the minibuffer. Useful during
 (defun counsel-rhythmbox ()
   "Choose a song from the Rhythmbox library to play or enqueue."
   (interactive)
-  (unless (require 'helm-rhythmbox nil t)
-    (error "Please install `helm-rhythmbox'"))
-  (unless helm-rhythmbox-library
-    (helm-rhythmbox-load-library)
-    (while (null helm-rhythmbox-library)
-      (sit-for 0.1)))
-  (ivy-read "Rhythmbox: "
-            (helm-rhythmbox-candidates)
+  (unless counsel-rhythmbox-songs
+    (let* ((service "org.gnome.Rhythmbox3")
+           (path "/org/gnome/UPnP/MediaServer2/Library/all")
+           (interface "org.gnome.UPnP.MediaContainer2")
+           (nb-songs (dbus-get-property
+                      :session service path interface "ChildCount")))
+      (if (not nb-songs)
+          (error "Couldn't connect to Rhythmbox")
+        (setq counsel-rhythmbox-songs
+              (mapcar (lambda (x)
+                        (cons
+                         (format
+                          "%s - %s - %s"
+                          (cl-caadr (assoc "Artist" x))
+                          (cl-caadr (assoc "Album" x))
+                          (cl-caadr (assoc "DisplayName" x)))
+                         (cl-caaadr (assoc "URLs" x))))
+                      (dbus-call-method
+                       :session service path interface "ListChildren"
+                       0 nb-songs '("*")))))))
+  (ivy-read "Rhythmbox: " counsel-rhythmbox-songs
             :history 'counsel-rhythmbox-history
             :preselect (counsel-rhythmbox-current-song)
             :action
             '(1
-              ("p" helm-rhythmbox-play-song "Play song")
+              ("p" counsel-rhythmbox-play-song "Play song")
               ("e" counsel-rhythmbox-enqueue-song "Enqueue song"))
             :caller 'counsel-rhythmbox))
+
 ;;** `counsel-linux-app'
 (defvar counsel-linux-apps-alist nil
   "List of data located in /usr/share/applications.")



reply via email to

[Prev in Thread] Current Thread [Next in Thread]