X-Git-Url: https://www.fleuret.org/cgi-bin/gitweb/gitweb.cgi?p=elisp.git;a=blobdiff_plain;f=media-mplayer.el;h=46acbb30afc4b95c7684b395d262b757f12ae020;hp=c7c581ef27f592dc963e933f2a210b01e4040367;hb=HEAD;hpb=26df02aba68fc5f1053ab7016b4e54717c2b5991 diff --git a/media-mplayer.el b/media-mplayer.el index c7c581e..46acbb3 100644 --- a/media-mplayer.el +++ b/media-mplayer.el @@ -32,6 +32,11 @@ load Emacs less. Nil means no timing." :type 'float :group 'media) +(defcustom media/mplayer/capture-dir nil + "States where to save the dumped streams." + :type 'string + :group 'media) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; It is impossible to tell mplayer to send information every time dt @@ -67,6 +72,9 @@ load Emacs less. Nil means no timing." ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +(setq media/mplayer/protocol-regexp + "^\\(AUDIO:\\|Exiting...\\|Starting\\|ANS_LENGTH\\|ANS_TIME_POSITION\\|Cache fill:\\|ICY Info:\\) *\\(.*\\)$") + (defun media/mplayer/filter-subfunctions (cmd param) ;; (unless (string= cmd "A:") ;; (message "cmd=%s param=%s" cmd param) @@ -77,9 +85,6 @@ load Emacs less. Nil means no timing." (assoc cmd '( - - ;; ---------------------------------------- - ("ICY Info:" ;; (message "ICY Info \"%s\"" param) @@ -87,17 +92,29 @@ load Emacs less. Nil means no timing." (setq media/current-song-in-stream (let ((s (match-string 1 param))) - (concat (if (string= s "") "" s) + (concat (if (string= s "") + "" + (encode-coding-string s 'latin-1) + ;; s + ) " | " (format-time-string "%a %b %d %H:%M:%S") ) ) ) + ;; If we did not parse it properly, reset the + ;; song name, and display the ICY string raw (setq media/current-song-in-stream nil) + (message "ICY Info \"%s\"" param) + ) - ;; If we did not parse it properly, show it - (message "ICY Info \"%s\"" param)) + (when media/mplayer/capture-dir + (let ((coding-system-for-write 'raw-text-unix)) + (with-temp-buffer + (insert + (concat media/current-song-in-stream "\n")) + (write-region nil nil (concat media/mplayer/capture-dir "/log") t)))) (if (and media/current-song-in-stream media/current-information) (media/show-current-information)) @@ -152,7 +169,12 @@ load Emacs less. Nil means no timing." ;; ---------------------------------------- ("Starting" - (media/mplayer/write "get_time_length\n")) + (media/mplayer/write "get_time_length\n") + (when media/mplayer/capture-dir + (media/mplayer/write "capturing\n") + ;; (message "Capturing stream in %s" media/mplayer/capture-dir) + ) + ) ;; ---------------------------------------- @@ -194,7 +216,7 @@ 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:\\|ICY Info:\\) *\\(.*\\)$" line) + (when (string-match media/mplayer/protocol-regexp line) (media/mplayer/filter-subfunctions (match-string 1 line) (match-string 2 line)))) ) (setq media/mplayer/buffer (substring media/mplayer/buffer start))) @@ -238,7 +260,8 @@ load Emacs less. Nil means no timing." media/song-current-time nil media/mplayer/cumulated-duration 0 media/mplayer/last-current-time nil - )) + ) +) (defun media/api/cleanup () "Called when killing the application's buffer" (when media/mplayer/process @@ -262,9 +285,20 @@ load Emacs less. Nil means no timing." (append '("mplayer" nil "mplayer" "-slave" "-quiet") media/mplayer/args - (if (string-match "\\(asx\\|m3u\\|pls\\|ram\\)$" media/mplayer/url) + (when (string-match "\\(asx\\|m3u\\|pls\\|ram\\)$" media/mplayer/url) + (if media/mplayer/capture-dir + (list "-dumpfile" + (concat media/mplayer/capture-dir + "/" + (replace-regexp-in-string "[^a-zA-Z0-9\.]" "_" media/mplayer/url) + (format-time-string "-%Y-%m-%d-%H:%M:%S")) + "-capture" + "-playlist" + ) (list "-playlist")) - (list (replace-regexp-in-string "^file://" "" media/mplayer/url)))) + ) + (list (replace-regexp-in-string "^file://" "" media/mplayer/url))) + ) media/mplayer/exit-type 'unknown media/mplayer/paused nil media/song-duration nil @@ -278,7 +312,6 @@ load Emacs less. Nil means no timing." (process-kill-without-query media/mplayer/process) (media/mplayer/start-timing-requests) (media/mplayer/write "get_time_pos\n") - ) (defun media/api/stop () (interactive)