aboutsummaryrefslogtreecommitdiff
path: root/emms-url.el
diff options
context:
space:
mode:
authorMichael Olson <mwolson@gnu.org>2007-01-05 03:40:00 +0000
committerMichael Olson <mwolson@gnu.org>2007-01-05 03:40:00 +0000
commit1e446de1aec47d258e509183d126d0341001900f (patch)
tree7b46c20bc7a3dbb7f0e8783c83bedfa57a141a5a /emms-url.el
parentc744071cb69bff0a4fa7dfaf469aa1d6bb845b1d (diff)
emms-url: New file containing the url.el interaction routines from emms-lastfm.el. I plan to use these in other parts of EMMS as well.
darcs-hash:20070105034035-1bfb2-d213da8dab318baf3fc5d6a1f7a3ac75d0e7640c.gz
Diffstat (limited to 'emms-url.el')
-rw-r--r--emms-url.el72
1 files changed, 72 insertions, 0 deletions
diff --git a/emms-url.el b/emms-url.el
new file mode 100644
index 0000000..2af1027
--- /dev/null
+++ b/emms-url.el
@@ -0,0 +1,72 @@
+;;; emms-url.el --- Make URL and EMMS work together well
+
+;; Copyright (C) 2006, 2007 Free Software Foundation, Inc.
+
+;; This file is part of EMMS.
+
+;; EMMS 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, or (at your option)
+;; any later version.
+;;
+;; EMMS 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 EMMS; see the file COPYING. If not, write to the
+;; Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
+
+;;; Commentary:
+
+;; These routines sanify input to URL and parse data returned by URL.
+
+;;; Code:
+
+(require 'url)
+
+(defvar emms-url-specials
+ '((?\" . "&quot;")
+ (?\< . "&lt;")
+ (?\> . "&gt;")
+ (?\& . "&amp;")
+ (?\ . "%20")
+ (?\n . "%0D%0A"))
+ "*An alist of characters which must be represented specially in URLs.
+The transformation is the key of the pair.")
+
+(defun emms-escape-url (url)
+ "Escape specials in URL.
+
+The specials to escape are specified by the `emms-url-specials'
+variable."
+ (apply (function concat)
+ (mapcar
+ (lambda (ch)
+ (let ((repl (assoc ch emms-url-specials)))
+ (if (null repl)
+ (char-to-string ch)
+ (cdr repl))))
+ (append url nil))))
+
+(defun emms-http-content-coding ()
+ (and (boundp 'url-http-content-type)
+ (string-match ";\\s-*charset=\\([^;[:space:]]+\\)"
+ url-http-content-type)
+ (intern-soft (downcase (match-string 1 url-http-content-type)))))
+
+(defun emms-http-decode-buffer ()
+ "Recode the buffer with `url-retrieve's contents. Else the
+buffer would contain multibyte chars like \\123\\456."
+ (let* ((default (or (car default-process-coding-system) 'utf-8))
+ (coding (or (emms-http-content-coding) default)))
+ ;; (pop-to-buffer (current-buffer))
+ ;; (message "content-type: %s" url-http-content-type)
+ ;; (message "coding: %S [default: %S]" coding default)
+ (set-buffer-multibyte t)
+ (decode-coding-region (point-min) (point-max) coding)))
+
+(provide 'emms-url)
+;;; emms-url.el ends here