;;; ani-playlist-converter.el --- Converts Winamp playlists for use in XMMS.
;; Author: Anirudh Sasikumar <an1sk@hotmail.com>
;; Original: Anirudh Sasikumar
;; Version: 0.1
;; URL: http://www.aloofhosting.com/anisk/code/ani-playlist-converter.el.html

;; This file 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.

;; This file is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING.  If not, write to
;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.

;;; Commentary:

;; This file is for use within emacs-wiki only.
;; Converts Winamp playlists to its linux equivalent for use in GNU/Linux players
;; like XMMS. For more details visit 
;; http://www.aloofhosting.com/anisk/blog/2004.07.31.html
;; Examples: 
;; (convert-win-play-to-lin "/mnt/E/playlists/myplaylist.m3u" "~/playlists/myplaylist.m3u" "E")
;; or do M-x convert-win-play-to-lin
;; Please forward any errors/bugs/improvements (there are bound to be many) 
;; you have to my email address.

;;; Code:

(defun ani-convert-win-playlist-to-lin (&optional source dest sourcedrive)
  "Converts Windows winamp playlist to its Linux equivalent.
   Assumes that you have your windows partitions mounted as /mnt/C/, /mnt/D/ etc.
   source is the path to the playlist to be converted.
   dest is the path to which the new playlist should be written.
   sourcedrive is the Windows drive letter in which the playlist was saved in."
  ;ask for values if not present
  (if (or
       (not source)
       (not dest)
       (not sourcedrive))
	(setq source (read-from-minibuffer "Source Playlist: "))
	(setq dest (read-from-minibuffer "Save To: "))
	(setq sourcedrive 
	      (read-from-minibuffer "Drive in which playlist was saved: "))))
  (with-temp-file dest
    (insert-file-contents source)
    (goto-char 0)
    (while (re-search-forward "\\(^\\\\\\)" nil t)
       (concat "/mnt/" sourcedrive  "/") t t))
    (goto-char 0)
    (while (re-search-forward "\\(^\\([A-Z]\\):\\\\\\)" nil t)
       (concat "/mnt/" (match-string 2) "/") t t))
    (goto-char 0)
    (while (re-search-forward "\\(\\\\\\)" nil t)
      (replace-match "/" t t))))

;; For convenience, you can hard code the arguments into a function as so
(defun update-playlists ()
  "Calls ani-convert-win-playlist-to-lin."
   "~/playlists/myplaylist.m3u" "E"))

Copyright © 2004-2011 Anirudh Sasikumar. All rights reserved.
Last Updated: November 29, 2011 4:41 PM