#!/usr/bin/clisp ; -*- Lisp -*- (asdf:oos 'asdf:load-op :xml-emitter) (in-package #:xml-emitter) ;;; Convenience (defun concat (&rest args) (apply #'concatenate 'string args)) (defmacro while (test &rest body) `(do () ((not ,test)) ,@body)) ;;; Rest (defun rss-item+enclosures (title enclosures &key link description author category comments guid pubDate source) (with-tag ("item") (emit-simple-tags :title title :link link :description description :author author :category category :comments comments :guid guid "pubDate" pubDate :source source) (dolist (enc enclosures) (simple-tag "enclosure" "" (list (list "url" enc)))))) (defun get-episode-name (file) "Extract episode number from FILE and return a useful description." (setf file (pathname-name file)) (let ((len (length file)) (start (position #\- file))) (if (not start) file (progn (incf start) (while (and (< start len) (or (char= (char file start) #\_) (char= (char file start) #\Space))) (incf start)) (if (< start len) (concat "Episode " (subseq file start)) file))))) (defun pathname-name< (path1 path2) (string< (pathname-name path1) (pathname-name path2))) (defun remove-trailing-slash (path) (let ((len (length path))) (if (and (> len 0) (char= (char path (1- len)) #\/)) (subseq path 0 (1- len)) path))) (let (first filter) (defun add-file (file outpath) (when first (setf first nil) (if (position #\- (pathname-name file)) (setf filter #'get-episode-name) (setf filter #'pathname-name))) (let ((desc (funcall filter file)) (link (concat outpath "/" (pathname-name file) "." (pathname-type file)))) (rss-item+enclosures desc (list link) :link link :description desc))) (defun dir2rss (dir outpath desc) (setf dir (remove-trailing-slash dir)) (setf outpath (remove-trailing-slash outpath)) (with-open-file (file (concat dir "/feed.rss") :direction :output) (with-rss2 (file) (rss-channel-header desc (concat outpath "/feed.rss")) (setf first t) (dolist (file (sort (directory (concat dir "/*")) #'pathname-name<)) (add-file file outpath)))))) ;; Pass shell arguments to `dir2rss' (apply #'dir2rss ext:*args*)