X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=blobdiff_plain;f=media-mplayer.el;h=c7c581ef27f592dc963e933f2a210b01e4040367;hb=26df02aba68fc5f1053ab7016b4e54717c2b5991;hp=da6d8df1eb2e80f3367767adc9c3312c444694d3;hpb=3771096a125c7cff7216ca61ce51b2cda5a7aca1;p=elisp.git diff --git a/media-mplayer.el b/media-mplayer.el index da6d8df..c7c581e 100644 --- a/media-mplayer.el +++ b/media-mplayer.el @@ -18,8 +18,8 @@ ;; Contact 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,99 +68,122 @@ 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 + (cons 'progn + (cdr + (assoc cmd - '( + '( - ;; ---------------------------------------- + ;; ---------------------------------------- - ("ANS_LENGTH" . + ("ICY Info:" + ;; (message "ICY Info \"%s\"" param) - (setq media/song-duration - (string-to-number (substring param 1)))) + (if (string-match "StreamTitle='\\([^;]*\\)';" param) - ;; ---------------------------------------- + (setq media/current-song-in-stream + (let ((s (match-string 1 param))) + (concat (if (string= s "") "" s) + " | " + (format-time-string "%a %b %d %H:%M:%S") + ) + ) + ) - ("ANS_TIME_POSITION" . + (setq media/current-song-in-stream nil) - (progn - (setq media/song-current-time - (string-to-number (substring param 1))) + ;; If we did not parse it properly, show it + (message "ICY Info \"%s\"" param)) - (when (and media/duration-to-history - (< media/mplayer/cumulated-duration media/duration-to-history)) + (if (and media/current-song-in-stream media/current-information) + (media/show-current-information)) + ) - (when media/mplayer/last-current-time - (setq media/mplayer/cumulated-duration - (+ media/mplayer/cumulated-duration - (- media/song-current-time media/mplayer/last-current-time)))) + ;; ---------------------------------------- - (when (>= media/mplayer/cumulated-duration media/duration-to-history) - (media/put-in-history) - ) + ("ANS_LENGTH" - (setq media/mplayer/last-current-time media/song-current-time) - ) + (setq media/song-duration + (string-to-number (substring param 1)))) + ;; ---------------------------------------- - ) - ) + ("ANS_TIME_POSITION" - ;; ---------------------------------------- + (setq media/song-current-time + (string-to-number (substring param 1))) - ("AUDIO:" . + (when (and media/duration-to-history + (< media/mplayer/cumulated-duration media/duration-to-history)) - (progn - ;; param = "44100 Hz, 2 ch, s16le, 128.0 kbit/9.07% (ratio: 16000->176400)" - (when (string-match "^\\([0-9]+\\) Hz, \\([0-9]+\\) ch.* \\([0-9.]+\\) kbit" - param) - (setq media/current-information - (list media/mplayer/url - (string-to-number (match-string 1 param)) - (string-to-number (match-string 2 param)) - (string-to-number (match-string 3 param)))) - ) - (run-hooks 'media/play-hook) - )) + (when media/mplayer/last-current-time + (setq media/mplayer/cumulated-duration + (+ media/mplayer/cumulated-duration + (- media/song-current-time media/mplayer/last-current-time)))) - ;; ---------------------------------------- + (when (>= media/mplayer/cumulated-duration media/duration-to-history) + (media/put-in-history) + ) - ("Starting" . - (media/mplayer/write "get_time_length\n")) + (setq media/mplayer/last-current-time media/song-current-time) + ) + ) - ;; ---------------------------------------- + ;; ---------------------------------------- - ("Cache fill:" . + ("AUDIO:" + + ;; param = "44100 Hz, 2 ch, s16le, 128.0 kbit/9.07% (ratio: 16000->176400)" + (when (string-match "^\\([0-9]+\\) Hz, \\([0-9]+\\) ch.* \\([0-9.]+\\) kbit" + param) + (setq media/current-information + (list media/mplayer/url + (string-to-number (match-string 1 param)) + (string-to-number (match-string 2 param)) + (string-to-number (match-string 3 param)))) + ) + (run-hooks 'media/play-hook) + ) - (when (string-match "(\\([0-9]+\\) bytes" param) - (message "Caching stream (%dkb)" - (/ (string-to-number (match-string 1 param)) 1024)))) + ;; ---------------------------------------- - ;; ---------------------------------------- + ("Starting" + (media/mplayer/write "get_time_length\n")) - ("Exiting..." . + ;; ---------------------------------------- - (progn - (setq media/mplayer/exit-type - (cdr (assoc param '(("(End of file)" . file-finished) - ("(Quit)" . quit)))) - media/current-information nil - media/song-duration nil - media/song-current-time nil) + ("Cache fill:" + (when (string-match "(\\([0-9]+\\) bytes" param) + (message "Caching stream (%dkb)" + (/ (string-to-number (match-string 1 param)) 1024)))) - (when media/mplayer/process (kill-process media/mplayer/process)) + ;; ---------------------------------------- - (force-mode-line-update))) + ("Exiting..." + (setq media/mplayer/exit-type + (cdr (assoc param '(("(End of file)" . file-finished) + ("(Quit)" . quit)))) + media/current-information nil + media/song-duration nil + media/song-current-time nil) - ;; ---------------------------------------- + (when media/mplayer/process (kill-process media/mplayer/process)) - ) - )))) + (force-mode-line-update) + ) + + ;; ---------------------------------------- + + ) + ) + ) + ) + ) + ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -171,8 +194,9 @@ load Emacs less. Nil means no timing." (string-match "\\(.*\\)[\n ]+" 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)))) + ) (setq media/mplayer/buffer (substring media/mplayer/buffer start))) )