-
Notifications
You must be signed in to change notification settings - Fork 0
/
cdrom.rkt
86 lines (70 loc) · 2.63 KB
/
cdrom.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#lang racket
(require racket/file)
(require "core.rkt"
"par2.rkt"
"split.rkt"
"rebuild.rkt"
"b2.rkt"
)
(provide archive-cdrom)
;; ISOs should be run through PAR2 directly.
(define (archive-cdrom)
;; Create the temp directory
(mkdir (get 'temp))
;; Create our working directory there
(define working-dir (build-path
(get 'temp)
"disc"))
;; Create the working directory
(printf "Working directory is: ~a~n" working-dir)
(mkdir working-dir)
;; Clean out the working directory
(parameterize ([current-directory working-dir])
(for ([file (directory-list (current-directory))])
(cond
[(or (regexp-match #px"\\.flac$" file)
(regexp-match #px"\\.cue$" file)
)
(printf "Cleaning up ~a~n" file)
(delete-file file)]
)))
;; (define disc-dir (build-path working-dir (get 'disc-name)))
(parameterize ([current-directory working-dir])
(putenv "OUTPUTDIR" (format "~a" working-dir))
;; (define command (format "abcde -1 -N -B -o flac -Q musicbrainz,cddb -j 6 -p -a default,cue 1"))
(define command (format "abcde -N -B -o mp3,flac -Q musicbrainz,cddb -j 6 -p -x"))
;; mp3,flac
(printf "command: ~a~n" command)
(when (not (zero? (system/exit-code command)))
(printf "abcde exited abnormally. Exiting.~n")
(exit -1)))
;; When it is done, there will be one directory in the "disc" folder.
;; Grab the first one that does not start with "abcde", just in case.
(parameterize ([current-directory working-dir])
(define dirs (directory-list (current-directory)))
(for ([d dirs])
(when (and (directory-exists? d)
(not (regexp-match #px"abcde" (format "~a" d))))
(put 'rip-dir (build-path (current-directory)
d))
(put 'disc-name
(string-downcase
(regexp-replace* #px"[^a-zA-Z0-9_-]" (format "~a" d) ""))))))
;;;;;;;;;;;;;;;;;
;; Copy to destination
(when (get 'destination)
(make-directory* (get 'destination))
(define target-dir (build-path (get 'destination)
(get 'disc-name)))
(mkdir target-dir)
(printf "Destination target directory: ~a~n" target-dir)
(when (directory-exists? target-dir)
(delete-directory/files target-dir))
(archive-copy (get 'rip-dir) target-dir))
;;;;;;;;;;;;;;;;;
;; Upload
(when (get 'bucket)
(parameterize ([current-directory (get 'rip-dir)])
(copy-music-to-b2 #:bucket (get 'bucket)
#:disc (get 'disc-name))))
)