Reset media/current-information when the song terminates (or if there is a player...
[elisp.git] / media-mplayer.el
index da6d8df..cdff4a0 100644 (file)
@@ -18,8 +18,8 @@
 ;; Contact <francois@fleuret.org> for comments & bug reports             ;;
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
-;; Is it me, or the slave mode of mplayer is ugly to parse ? Did I
-;; miss something ?
+;; Is it me, or the slave mode of mplayer is ugly to parse? Did I miss
+;; something?
 
 (defcustom media/mplayer/args nil
   "List of arguments for mplayer."
@@ -68,9 +68,9 @@ load Emacs less. Nil means no timing."
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
 (defun media/mplayer/filter-subfunctions (cmd param)
-  ;;   (unless (string= cmd "A:")
-  ;;   (message "cmd=%s param=%s" cmd param)
-  ;;   )
+  ;; (unless (string= cmd "A:")
+    ;; (message "cmd=%s param=%s" cmd param)
+    ;; )
   (eval
    (cdr
     (assoc cmd
@@ -79,6 +79,13 @@ load Emacs less. Nil means no timing."
 
              ;; ----------------------------------------
 
+             ("ICY Info:" .
+              (if (string-match "StreamTitle='\\([^;]*\\)';" param)
+                  (setq media/mplayer/current-stream-song (match-string 1 param))
+                (message "ICY Info \"%s\"" param)))
+
+             ;; ----------------------------------------
+
              ("ANS_LENGTH" .
 
               (setq media/song-duration
@@ -171,8 +178,14 @@ load Emacs less. Nil means no timing."
                 (string-match "\\(.*\\)[\n\r]+" media/mplayer/buffer start))
       (setq start (1+ (match-end 1)))
       (let ((line (match-string 1 media/mplayer/buffer)))
-        (when (string-match "^\\(AUDIO:\\|Exiting...\\|Starting\\|ANS_LENGTH\\|ANS_TIME_POSITION\\|Cache fill:\\) *\\(.*\\)$" line)
-          (media/mplayer/filter-subfunctions (match-string 1 line) (match-string 2 line)))))
+        (when (string-match "^\\(AUDIO:\\|Exiting...\\|Starting\\|ANS_LENGTH\\|ANS_TIME_POSITION\\|Cache fill:\\|ICY Info:\\) *\\(.*\\)$" line)
+          (media/mplayer/filter-subfunctions (match-string 1 line) (match-string 2 line))))
+
+      (when (and media/mplayer/current-stream-song media/current-information)
+        (message "Now in stream (%s) \"%s\""
+                 (current-time-string) media/mplayer/current-stream-song)
+        (setq media/mplayer/current-stream-song nil))
+      )
     (setq media/mplayer/buffer (substring media/mplayer/buffer start)))
   )
 
@@ -212,6 +225,7 @@ load Emacs less. Nil means no timing."
         media/mplayer/paused nil
         media/song-duration nil
         media/song-current-time nil
+        media/mplayer/current-stream-song nil
         media/mplayer/cumulated-duration 0
         media/mplayer/last-current-time nil
         ))