-
This commit is contained in:
47
music-library.rkt
Normal file
47
music-library.rkt
Normal file
@@ -0,0 +1,47 @@
|
||||
#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 (cadr row))
|
||||
)
|
||||
(list (list 'td (list (list 'class "library-entry") (list 'id file-id) (list 'file (format "~a" file-entry)))
|
||||
(if (equal? file-id "lib-up")
|
||||
file-entry
|
||||
(basename file-entry))
|
||||
))
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user