-
This commit is contained in:
64
playlist.rkt
64
playlist.rkt
@@ -38,19 +38,41 @@
|
||||
(define/public (get-number) number)
|
||||
(define/public (get-length) length)
|
||||
|
||||
(super-new)
|
||||
(begin
|
||||
(unless (eq? file #f)
|
||||
(let ((f (if (path? file) (path->string file) file)))
|
||||
(let ((tags (id3-tags f))
|
||||
(tmpfile #f))
|
||||
(unless (tags-valid? tags)
|
||||
(the-displayln "Invalid, try to open a copy of this file")
|
||||
(let ((nfile (make-temporary-file "rktplayer-~a" #:copy-from f)))
|
||||
(define (read-tags)
|
||||
(let* ((f (if (path? file) (path->string file) file))
|
||||
(tags (id3-tags f))
|
||||
(tmpfile #f))
|
||||
(unless (tags-valid? tags)
|
||||
(let ((nfile (make-temporary-file "rktplayer-~a" #:copy-from f)))
|
||||
(set! tags (id3-tags nfile))
|
||||
(set! tmpfile nfile)
|
||||
)
|
||||
))
|
||||
(unless (eq? tmpfile #f)
|
||||
(delete-file tmpfile))
|
||||
tags
|
||||
)
|
||||
)
|
||||
|
||||
(define/public (image->file to-file)
|
||||
(let ((tags (read-tags)))
|
||||
(if (tags-valid? tags)
|
||||
(let ((ext (tags-picture->ext tags)))
|
||||
(if (eq? ext #f)
|
||||
#f
|
||||
(let ((path (string-append to-file "." (symbol->string ext))))
|
||||
(if (tags-picture->file tags path)
|
||||
path
|
||||
#f)
|
||||
)
|
||||
)
|
||||
)
|
||||
#f)))
|
||||
|
||||
(super-new)
|
||||
|
||||
(begin
|
||||
(unless (eq? file #f)
|
||||
(let ((tags (read-tags)))
|
||||
(if (tags-valid? tags)
|
||||
(begin
|
||||
(set! title (tags-title tags))
|
||||
@@ -67,9 +89,6 @@
|
||||
(set! length -1)
|
||||
)
|
||||
)
|
||||
(unless (eq? tmpfile #f)
|
||||
(delete-file tmpfile))
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
@@ -77,6 +96,7 @@
|
||||
)
|
||||
|
||||
(define list-len length)
|
||||
(define orig-for-each for-each)
|
||||
|
||||
(define playlist%
|
||||
(class object%
|
||||
@@ -104,7 +124,7 @@
|
||||
(add-track dir))
|
||||
(if (directory-exists? dir)
|
||||
(let ((content (directory-list dir)))
|
||||
(for-each (λ (entry)
|
||||
(orig-for-each (λ (entry)
|
||||
(let ((p (build-path dir entry)))
|
||||
(if (directory-exists? p)
|
||||
(read-tracks-internal p)
|
||||
@@ -133,10 +153,22 @@
|
||||
(list-ref tracks i))
|
||||
|
||||
(define/public (display-tracks)
|
||||
(for-each (λ (track)
|
||||
(orig-for-each (λ (track)
|
||||
(send track displayln))
|
||||
tracks))
|
||||
|
||||
(define/public (for-each f)
|
||||
(let ((idx 0))
|
||||
(orig-for-each (λ (track)
|
||||
(f idx track)
|
||||
(set! idx (+ idx 1)))
|
||||
tracks)
|
||||
)
|
||||
)
|
||||
|
||||
(define/public (track-id i)
|
||||
(string->symbol (format "track-~a" (+ i 1))))
|
||||
|
||||
(define/public (to-html)
|
||||
(define (formatter row)
|
||||
(let* ((track-idx (car row))
|
||||
@@ -158,7 +190,7 @@
|
||||
|
||||
(letrec ((f (λ (i N)
|
||||
(if (< i N)
|
||||
(cons (list (format "track-~a" (+ i 1)) i) (f (+ i 1) N))
|
||||
(cons (list (send this track-id i) i) (f (+ i 1) N))
|
||||
'()))))
|
||||
(let ((rows (f 0 (send this length))))
|
||||
(mktable rows 'tracks formatter))))
|
||||
|
||||
Reference in New Issue
Block a user