;;; mobiquid.el --- Emacs interface to the http://www.mobiquid.com/ ;;; service ;; Copyright (C) 2001 Florent Rougon ;; Author: Florent Rougon ;; Maintainer: Florent Rougon ;; Keywords: radio, mobiquid, mobiquid.com ;; Version: 0.5 ;; This program is free software; you can redistribute it and/or ;; modify it under the terms of the GNU General Public License as ;; published by the Free Software Foundation; either version 2 of ;; the License, or (at your option) any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public ;; License along with this program; if not, write to the Free ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, ;; MA 02111-1307, USA. ;;; Commentary: ;; This program enables you to access to the http://www.mobiquid.com ;; database. Juste type `M-x mobiquid' and you will be prompted for ;; the name of a (french) radio and an time of the day (hour and ;; minute). Then the function will fetch the name of the artist and ;; the title of what was being played on that radio at this time and ;; display it in a *Mobiquid* buffer or with the browser of your ;; choice. ;;; Installation: ;; Place mobiquid.el and mobiquid-init.el somewhere in emacs' load-path, and ;; byte-compile them (by pressing `B' in dired mode, for example). Then add ;; the following line to your ~/.emacs.el initialization file: ;; ;; (require 'mobiquid-init) ;; ;; You will also have to add some lines depending on the way you want to ;; display the HTML table returned by the server and whether or not elib is ;; installed on your system. The following paragraphs will tell you how to do ;; this. ;; ;; 1) Choosing the browser ;; -------------------- ;; ;; a) If you want to use W3, I recommend the following: ;; ;; (setq mobiquid-browse-function 'mobiquid-browse-with-w3-region) ;; (add-hook 'mobiquid-after-browsing-hooks 'switch-to-buffer-other-window) ;; ;; which obviously requires W3 installed on your system. ;; ;; b) If you want to use `browse-url', you should put: ;; ;; (setq mobiquid-browse-function 'mobiquid-browse-with-browse-url) ;; ;; This will enable you to use particular (local) values of ;; `browse-url-browser-function' and `browse-url-of-file-hook' that you can ;; set with `mobiquid-browse-url-browser-function' and ;; `mobiquid-browse-url-of-file-hook' (have a look at browse-url.el to see ;; possible values for `browse-url-browser-function'). ;; ;; c) You can use any user-defined function for browsing by setting ;; `mobiquid-browse-function' to its name (as a symbol). ;; ;; What happens is that the function whose name is `mobiquid-browse-function' ;; is called with the buffer containg the HTML code as the current buffer, ;; named *Mobiquid* and not yet displayed when it is called. ;; ;; If `mobiquid-browse-function' modifies the contents of this buffer to ;; display the rendered HTML code (which is the case when using ;; `mobiquid-browse-with-w3-region'), you will probably find useful to display ;; the *Mobiquid* buffer so that the user can see the result. You will have to ;; use `mobiquid-after-browsing-hooks' to do this. ;; ;; If it doesn't, for example if you browse with Netscape, you will probably ;; do nothing particular in `mobiquid-after-browsing-hooks'. You could think ;; of killing the *Mobiquid* buffer in that case, because the user doesn't ;; need to see the HTML code, but it is not always possible: if you use ;; browse-url and Netscape, killing the buffer will delete the temporary file ;; containg the HTML code and Netscape will be quite angry... But it should'nt ;; be a big problem since that buffer is not displayed by default and is the ;; last one in the Emacs' queue. ;; ;; 2) Telling `mobiquid' whether or not you have elib installed ;; --------------------------------------------------------- ;; ;; If you don't have elib installed, you should set `mobiquid-use-elib' to nil ;; with `(setq mobiquid-use-elib nil)' in you init file. Then there will be no ;; error checking on the hour and minute arguments given to `mobiquid' (which ;; is probably not a big problem). ;;; Bugs ;; `mobiquid-radios-alist' is not fetched from ;; http://www.mobiquid.com/home2_ns.asp each time `mobiquid' is ;; executed. This behaviour would be slower but in the current ;; implementation, you have to update it manually when you think it ;; needs to be updated. ;; Thanks ;; This file is inspired from dict-web.el by Eric Marsden, which should be ;; available from: ;; ;; ;; ;; ;;; About mobiquid.com ;; mobiquid.com is a service from MOBIQUID. For more information, have a look ;; at http://www.mobiquid.com or send an e-mail to info@mobiquid.com. ;;; Code: (defvar mobiquid-radios-alist '(("Ado" . "23") ("Cherie" . "17") ("Europe1" . "21") ("Europe2" . "12") ("Fun" . "1") ("MFM" . "19") ("MTV" . "28") ("Nostalgie" . "9") ("Nrj" . "3") ("Oui FM" . "10") ("FG" . "22") ("Nova" . "11") ("RFM" . "15") ("Rire&Cha" . "18") ("RMC" . "24") ("RTL" . "16") ("RTL2" . "8") ("Voltage" . "20")) "*Mapping between radio names and their assigned numbers by www.mobiquid.com" ) (defvar mobiquid-default-radio-name "Oui FM" "*Mobiquid default radio name for completion in `mobiquid'") (defvar mobiquid-use-elib t "*Variable to tell if `mobiquid' should use elib or not. If set to t, `mobiquid' will use elib to do some checking on the hour and minute given as input, otherwise elib is not needed, but no error checking will be done") (defvar mobiquid-browse-function 'mobiquid-browse-with-w3-region "*Name of the function used by `mobiquid' to render the HTML code fetched (and cleaned) from http://www.mobiquid.com. It is called in the buffer where the code resides with no argument. Possible values are `mobiquid-browse-with-browse-url' or `mobiquid-browse-with-w3-region' or user-defined function names.") (defun mobiquid-browse-with-w3-region () "Browses the contents of the current buffer with `w3-region'. The HTML code is replaced by the result, the first two (blank) lines are deleted and font-lock-mode is turned of because it is of no use with mobiquid and makes the table harder to read." (require 'w3) (require 'w3-display) (w3-region (point-min) (point-max)) (delete-blank-lines) (delete-blank-lines) (font-lock-mode -1)) (defun mobiquid-browse-with-browse-url () (require 'browse-url) (let ((browse-url-browser-function mobiquid-browse-url-browser-function) (browse-url-of-file-hook mobiquid-browse-url-of-file-hook)) (browse-url-of-buffer))) (defvar mobiquid-browse-url-browser-function 'browse-url-netscape "*Function used by `mobiquid' as `browse-url-browser-function'. When `mobiquid' is called, `browse-url-browser-function' is locally set to the value of `mobiquid-browse-url-browser-function' so that you can use a particular browser with browse-url for `mobiquid' calls.") (defvar mobiquid-html-header " Emacs -> Mobiquid \n" "HTML code inserted before the HTML table returned by http://www.mobiquid.com.") (defvar mobiquid-html-footer "" "HTML code inserted after the HTML table returned by http://www.mobiquid.com") ;;;###autoload (defun mobiquid (radio hour minute datepass) "Lookup an artist and title from http://www.mobiquid.com. Prompt (if called interactively) for a radio name, an hour and a minute and fetch from http://www.mobiquid.com the artist and the title of what was being played on that radio at this time." (interactive (let ((hour-prompt "Hour: ") (minute-prompt "Minute (multiple of 5): ")) (if mobiquid-use-elib (require 'read)) (list ;; Radio (assoc (completing-read (concat "Radio: (default " mobiquid-default-radio-name ") ") mobiquid-radios-alist nil t nil nil mobiquid-default-radio-name) mobiquid-radios-alist) ;; Hour (number-to-string (if mobiquid-use-elib (read-num-range 0 23 hour-prompt) (string-to-number (read-string hour-prompt)))) ;; Minute (number-to-string (if mobiquid-use-elib (let (minute) (while (/= 0 (mod (setq minute (read-num-range 0 55 minute-prompt)) 5))) minute) (string-to-number (read-string minute-prompt)))) ;; Date (asked to the system) (concat (number-to-string (string-to-number (format-time-string "%m"))) "/" (number-to-string (string-to-number (format-time-string "%d"))) "/" (format-time-string "%y"))))) (let ((buffer (get-buffer-create "*Mobiquid*"))) (save-current-buffer (set-buffer buffer) (mobiquid-fetch radio hour minute datepass) (mobiquid-wash) ;; Insert "..." (goto-char (point-min)) (insert mobiquid-html-header) ;; Insert "..." (goto-char (point-max)) (insert mobiquid-html-footer) ;; Display the table (funcall mobiquid-browse-function) (set-buffer-modified-p nil)) (run-hook-with-args 'mobiquid-after-browsing-hooks buffer) )) (defun mobiquid-fetch (radio hour minute datepass) (require 'url) (require 'url-cookie) (let* ((pairs `(("radio" . ,radio) ("heure" . ,hour) ("minute" . ,minute) ("datepass" . ,datepass))) (url-request-data (mobiquid-form-encode pairs)) (url-request-method "POST") (url-request-extra-headers '(("Content-type" . "application/x-www-form-urlencoded")))) (url-insert-file-contents "http://www.mobiquid.com/20rad.asp"))) (defun mobiquid-wash () (let ((case-fold-search nil)) ; case will be significant ;; Replace all ^M by newlines (translate-region (point-min) (point-max) "\x0\^A\^B\^C\^D\^E\^F\^G\^H\^I\^J\^K\^L\n") (goto-char (point-min)) (unless (re-search-forward "" nil t) (error "mobiquid-wash-and-render didn't find magic string `'")) (delete-region (match-beginning 0) (point-max)) (unless (re-search-backward "