aboutsummaryrefslogtreecommitdiff
path: root/lisp/emms-stream-info.el
diff options
context:
space:
mode:
authorYoni Rabkin <yoni@rabkins.net>2008-12-24 19:40:07 +0200
committerYoni Rabkin <yoni@rabkins.net>2008-12-24 19:40:07 +0200
commit1cb621334a33563996784b14eadc96f2126767f2 (patch)
tree622c7f9a9aeed406a8c346493e881e8402b65f22 /lisp/emms-stream-info.el
parentb1e16d0f1d8f8ac13efc3706b016d4abbb06949d (diff)
* lisp/emms-stream-info.el: Reimplement using player backends.
Diffstat (limited to 'lisp/emms-stream-info.el')
-rw-r--r--lisp/emms-stream-info.el85
1 files changed, 76 insertions, 9 deletions
diff --git a/lisp/emms-stream-info.el b/lisp/emms-stream-info.el
index 62c8d4c..1683357 100644
--- a/lisp/emms-stream-info.el
+++ b/lisp/emms-stream-info.el
@@ -22,27 +22,94 @@
;;; Commentary:
;;
+;; Set `*emms-stream-info-backend*' to either 'vlc or 'mplayer, which
+;; are the two currently supported backends for retrieving stream
+;; information. You can then either call `emms-stream-info-message'
+;; directly or hit "i" in the `emms-streams' buffer over stream you
+;; want to investigate.
+;;
+;; Note that you do not have to be playing the stream in question in
+;; order to find out what is playing on it since this library will
+;; open its own connection to the streaming server.
+;;
+;; Please send bug reports and stations which do not work to the
+;; maintainer (email at the top of this file).
+
+;;; History:
+;;
;; This library was re-implemented from scratch around January of
;; 2009. If you are looking for the old code then grab source code
;; older than that.
;;; Code:
-(defvar *emms-stream-info-debug-buffer* "*stream-info-debug*")
+(defvar *emms-stream-info-backend* 'mplayer
+ "Symbol designating the backend program to use.")
-;; "http://di-fm-01.quintex.com:8888"
+;; using unhygienic macros for good... or is it evil?
+(defmacro emms-stream-info-defreg (symname regexp)
+ "Set SYMNAME to be the match for REGEXP."
+ `(save-excursion
+ (goto-char (point-min))
+ (re-search-forward ,regexp (point-max) t)
+ (when (and (match-string-no-properties 1)
+ (> (length (match-string-no-properties 1)) 0))
+ (setq ,symname (match-string-no-properties 1)))))
-(defun emms-stream-info-call-backend (url)
- (with-temp-buffer
- (call-process "mplayer" nil *emms-stream-info-debug-buffer* nil
- "-endpos" "0" "-vo" "null" "-ao" "null" url)
- (buffer-substring (point-min) (point-max))))
+(defun emms-stream-info-mplayer-backend (url)
+ "Backend command for running mplayer on URL."
+ (condition-case excep
+ (call-process "mplayer" nil t nil
+ "-nocache" "-endpos" "0" "-vo" "null" "-ao" "null"
+ url)
+ (file-error
+ (error "Could not find the mplayer backend binary"))))
+
+(defun emms-stream-info-vlc-backend (url)
+ "Backend command for running VLC on URL."
+ (condition-case excep
+ (call-process "vlc" nil t nil
+ "-vvv" "--intf" "dummy" "--stop-time" "1" "--noaudio"
+ url "vlc:quit")
+ (file-error
+ (error "Could not find the VLC backend binary"))))
-(setq foo (emms-stream-info-call-backend "http://di-fm-01.quintex.com:8888"))
+(defun emms-stream-info-call-backend (url)
+ "Call backend and return a list of stream information for URL."
+ (let ((name "N/A")
+ (genre "N/A")
+ (bitrate "N/A")
+ (nowplaying "N/A"))
+ (with-temp-buffer
+ (message "querying stream...")
+ (cond
+ ((eq *emms-stream-info-backend* 'mplayer)
+ (emms-stream-info-mplayer-backend url)
+ (emms-stream-info-defreg name "^Name[ ]+:[ ]+\\(.*\\)$")
+ (emms-stream-info-defreg genre "^Genre[ ]+:[ ]+\\(.*\\)$")
+ (emms-stream-info-defreg bitrate "^Bitrate[ ]+:[ ]+\\(.*\\)$")
+ (emms-stream-info-defreg nowplaying "ICY Info: StreamTitle='\\(.+?\\)'"))
+ ((eq *emms-stream-info-backend* 'vlc)
+ (emms-stream-info-vlc-backend url)
+ (emms-stream-info-defreg name "'Title' = '\\(.*\\)'")
+ (emms-stream-info-defreg genre "Genre: \\(.*\\)")
+ (emms-stream-info-defreg bitrate "bitrate:\\([0-9].+\\)")
+ (emms-stream-info-defreg nowplaying "'Now Playing' = '\\(.+?\\)'"))
+ (t (error "Unknown backend"))))
+ (message "querying stream...done")
+ (list name genre bitrate nowplaying)))
;; point of entry
(defun emms-stream-info-message (url)
- 'stub)
+ "Display a message with information about the stream at URL."
+ (interactive "Murl: ")
+ (let* ((stream-info (emms-stream-info-call-backend url))
+ (name (nth 0 stream-info))
+ (genre (nth 1 stream-info))
+ (bitrate (nth 2 stream-info))
+ (nowplaying (nth 3 stream-info)))
+ (message "now playing: %s on %s, genre: %s, bitrate: %s"
+ nowplaying name genre bitrate)))
(provide 'emms-stream-info)