50 lines
1.4 KiB
Racket
50 lines
1.4 KiB
Racket
#lang racket
|
|
|
|
(provide music-lib-relevant?
|
|
is-music-dir?
|
|
is-music-file?
|
|
basename
|
|
library-formatter
|
|
)
|
|
|
|
(define (music-lib-relevant? f)
|
|
(let ((type (file-or-directory-type f #t)))
|
|
(if (eq? type 'directory)
|
|
(let ((name (basename f)))
|
|
(not (string-prefix? name ".")))
|
|
(if (eq? type 'file)
|
|
(let* ((fn (string-downcase (format "~a" f)))
|
|
(exts (list "flac" "mp3")))
|
|
(let ((l (filter (λ (e) (string-suffix? fn (string-append "." e))) exts)))
|
|
(not (null? l))))
|
|
#f))))
|
|
|
|
(define (is-music-dir? f)
|
|
(and (music-lib-relevant? f)
|
|
(directory-exists? f)))
|
|
|
|
(define (is-music-file? f)
|
|
(and (music-lib-relevant? f)
|
|
(file-exists? f)))
|
|
|
|
(define (basename file)
|
|
(call-with-values (λ () (split-path file))
|
|
(λ (base name is-dir)
|
|
(path->string name))))
|
|
|
|
(define (library-formatter row)
|
|
(let* ((file-entry (car row))
|
|
(file-id (format "file-~a" (cadr row)))
|
|
(the-file (if (equal? file-id "lib-up") ".." file-entry))
|
|
)
|
|
;(displayln row)
|
|
(list (list 'td (list (list 'class "library-entry") (list 'id file-id) (list 'file (format "~a" the-file)))
|
|
(if (equal? file-id "lib-up")
|
|
file-entry
|
|
(basename file-entry))
|
|
))
|
|
)
|
|
)
|
|
|
|
|