From e41edcad7947fab43b17cae064ae617d0162f783 Mon Sep 17 00:00:00 2001 From: forcer Date: Sat, 1 Apr 2006 18:59:00 +0000 Subject: Move emms-parse-playlist to emms-source-file.el, rename to emms-source-file-parse-playlist darcs-hash:20060401185913-2189f-75ccf31626867407f72de64642d6fc020cfc240e.gz --- emms-source-file.el | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'emms-source-file.el') diff --git a/emms-source-file.el b/emms-source-file.el index d3215a2..e2e1cec 100644 --- a/emms-source-file.el +++ b/emms-source-file.el @@ -149,11 +149,33 @@ or lines starting with '#'." emms-source-file-default-directory emms-source-file-default-directory t))) - (dolist (file (emms-parse-playlist playlist)) + (dolist (file (emms-source-file-parse-playlist playlist)) (if (string-match "\\`http://" file) (emms-source-url file) (emms-source-file file)))) +(defun emms-source-file-parse-playlist (playlist) + "Extract a list of filenames from the given .m3u or .pls playlist. +Empty lines and lines starting with '#' are ignored." + (let ((files '()) + (pls-p (if (string-match "\\.pls\\'" playlist) t nil)) + (dir (file-name-directory playlist))) + (with-temp-buffer + (insert-file-contents playlist) + (goto-char (point-min)) + (while (re-search-forward "^[^# ].*$" nil t) + (let ((line (match-string 0))) + (when pls-p + (if (string-match "\\`File[0-9]*=\\(.+\\)\\'" line) + (setq line (match-string 1 line)) + (setq line ""))) + (unless (string= line "") + (setq files (cons (if (or (string-match "\\`http://" line) + (file-name-absolute-p line)) + line + (concat dir line)) + files)))))) + (reverse files))) ;;; Helper functions -- cgit v1.2.3