aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--emms-player-mpd.el27
-rw-r--r--emms-source-file.el36
-rw-r--r--emms-source-playlist.el78
3 files changed, 86 insertions, 55 deletions
diff --git a/emms-player-mpd.el b/emms-player-mpd.el
index 8808c7a..8034b9c 100644
--- a/emms-player-mpd.el
+++ b/emms-player-mpd.el
@@ -90,7 +90,7 @@
;; emms-playing-time, the displayed time will be accurate.
(require 'emms-player-simple)
-(require 'emms-source-file) ; for emms-source-file-parse-playlist
+(require 'emms-source-playlist) ; for emms-source-file-parse-playlist
(defun emms-player-mpd-get-supported-regexp ()
"Returns a regexp of file extensions that MusicPD supports,
@@ -520,15 +520,20 @@ If we succeed in adding the file, return non-nil, nil otherwise."
(defun emms-player-mpd-add-playlist (playlist)
"Load contents of PLAYLIST into MusicPD by adding each line.
This handles both m3u and pls type playlists."
- ;; This allows us to keep playlists anywhere and not worry about
- ;; having to mangle their names. Also, mpd can't handle pls
- ;; playlists by itself.
- (let ((playlist (emms-source-file-parse-playlist playlist))
- (any-success nil))
- (dolist (file playlist)
- (when (emms-player-mpd-add-file file)
- (setq any-success t)))
- any-success))
+ ;; This is useful for playlists of playlists
+ (with-temp-buffer
+ (insert-file-contents playlist)
+ (goto-char (point-min))
+ (let ((list (cond ((emms-source-playlist-m3u-p)
+ (emms-source-playlist-parse-m3u-1))
+ ((emms-source-playlist-pls-p)
+ (emms-source-playlist-parse-pls-1))
+ (t nil)))
+ (any-success nil))
+ (dolist (file list)
+ (when (emms-player-mpd-add-file file)
+ (setq any-success t)))
+ any-success)))
(defun emms-player-mpd-add (track)
"Add TRACK to the MusicPD playlist."
@@ -544,7 +549,7 @@ This handles both m3u and pls type playlists."
;;; EMMS API
-(defun emms-player-mpd-playablep (track)
+(defun emms-player-mpd-playable-p (track)
"Return non-nil when we can play this track."
(and (memq (emms-track-type track) '(file url playlist))
(string-match (emms-player-get emms-player-mpd 'regex)
diff --git a/emms-source-file.el b/emms-source-file.el
index e2e1cec..6634130 100644
--- a/emms-source-file.el
+++ b/emms-source-file.el
@@ -140,42 +140,6 @@ value of `emms-source-file-default-directory'."
(emms-track 'file file)))
(emms-source-file-directory-tree dir regex)))
-;;;###autoload (autoload 'emms-play-playlist "emms-source-file" nil t)
-;;;###autoload (autoload 'emms-add-playlist "emms-source-file" nil t)
-(define-emms-source playlist (playlist)
- "A source for .m3u and .pls playlists. It ignores empty lines,
-or lines starting with '#'."
- (interactive (list (read-file-name "Play file: "
- emms-source-file-default-directory
- emms-source-file-default-directory
- t)))
- (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
diff --git a/emms-source-playlist.el b/emms-source-playlist.el
index e2527ac..1e4a6fb 100644
--- a/emms-source-playlist.el
+++ b/emms-source-playlist.el
@@ -37,7 +37,9 @@
(require 'emms-source-file)
(defcustom emms-source-playlist-formats
- '((emms-source-playlist-native-p emms-source-playlist-parse-native))
+ '((emms-source-playlist-native-p emms-source-playlist-parse-native)
+ (emms-source-playlist-pls-p emms-source-playlist-parse-pls)
+ (emms-source-playlist-m3u-p emms-source-playlist-parse-m3u))
"*A list of playlist format functions.
Each entry is a list with two elements:
A function which returns non-nil if the current buffer is of this
@@ -49,6 +51,8 @@ called with two buffers: The playlist buffer and the file buffer."
;;; General playlist
+;;;###autoload (autoload 'emms-play-playlist "emms-source-playlist" nil t)
+;;;###autoload (autoload 'emms-add-playlist "emms-source-playlist" nil t)
(define-emms-source playlist (file)
"An EMMS source for playlists.
See `emms-source-playlist-formats' for supported formats."
@@ -58,7 +62,7 @@ See `emms-source-playlist-formats' for supported formats."
t)))
(mapc #'emms-playlist-insert-track
(with-temp-buffer
- (insert-file file)
+ (insert-file-contents file)
(goto-char (point-min))
(catch 'return
(let ((formats emms-source-playlist-formats))
@@ -114,7 +118,7 @@ OUT should be a buffer to get the native EMMS format."
t)))
(mapc #'emms-playlist-insert-track
(with-temp-buffer
- (insert-file file)
+ (insert-file-contents file)
(goto-char (point-min))
(when (not (emms-source-playlist-native-p))
(error "Not a native EMMS playlist file."))
@@ -126,15 +130,14 @@ OUT should be a buffer to get the native EMMS format."
emms-source-file-default-directory
emms-source-file-default-directory
nil)))
- (with-current-buffer (find-file-noselect file)
- (delete-region (point-min)
- (point-max))
+ (with-temp-buffer
(emms-source-playlist-unparse-native (with-current-emms-playlist
(current-buffer))
(current-buffer))
- (save-buffer)))
+ (let ((backup-inhibited t))
+ (write-file file))))
-;;; m3u/pls files
+;;; m3u files
;; Format:
;; Either a list of filename-per-line, ignore lines beginning with #
@@ -147,6 +150,63 @@ OUT should be a buffer to get the native EMMS format."
; emms-source-playlist-parse-m3u
; emms-source-playlist-unparse-m3u
+(defun emms-source-playlist-m3u-p ()
+ "Return non-nil if the current buffer contains a native EMMS playlist."
+ t)
+
+(defun emms-source-playlist-parse-m3u ()
+ "Parse the native EMMS playlist in the current buffer."
+ (mapcar (lambda (file)
+ (if (string-match "\\`http://" file)
+ (emms-track 'url file)
+ (emms-track 'file (expand-file-name file))))
+ (emms-source-playlist-parse-m3u-1)))
+
+(defun emms-source-playlist-parse-m3u-1 ()
+ "Extract a list of filenames from the given .m3u playlist.
+Empty lines and lines starting with '#' are ignored."
+ (let ((files nil))
+ (save-excursion
+ (goto-char (point-min))
+ (while (re-search-forward "^[^# ].*$" nil t)
+ (setq files (cons (match-string 0) files))))
+ (nreverse files)))
+
+;;; pls files
+
+;; Format:
+;; A list of one filename per line.
+;; File<position>=<filename>
+
+; emms-source-playlist-pls-p
+; emms-source-playlist-parse-pls
+; emms-source-playlist-unparse-pls
+
+(defun emms-source-playlist-pls-p ()
+ "Return non-nil if the current buffer contains a native EMMS playlist."
+ (save-excursion
+ (goto-char (point-min))
+ (if (re-search-forward "^File[0-9]*=.+$" nil t)
+ t
+ nil)))
+
+(defun emms-source-playlist-parse-pls ()
+ "Parse the native EMMS playlist in the current buffer."
+ (mapcar (lambda (file)
+ (if (string-match "\\`http://" file)
+ (emms-track 'url file)
+ (emms-track 'file (expand-file-name file))))
+ (emms-source-playlist-parse-pls-1)))
+
+(defun emms-source-playlist-parse-pls-1 ()
+ "Extract a list of filenames from the given .pls playlist.
+Empty lines and lines starting with '#' are ignored."
+ (let ((files nil))
+ (save-excursion
+ (goto-char (point-min))
+ (while (re-search-forward "^File[0-9]*=\\(.+\\)$" nil t)
+ (setq files (cons (match-string 1) files))))
+ (nreverse files)))
;;; Helper functions
@@ -236,3 +296,5 @@ This moves point."
;; (emms-playlist-save-as-m3u emms-playlist-buffer filename))
+(provide 'emms-source-playlist)
+;;; emms-source-playlist.el ends here