diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..b5150cf --- /dev/null +++ b/Makefile @@ -0,0 +1,8 @@ + + +all: + @echo "make arch" + +arch: + (cd ..; tar czf ../audio-manager.tar.gz --exclude .git --exclude "*.bak" --exclude "*.*~" audio-library-manager) + diff --git a/arch.sh b/arch.sh new file mode 100644 index 0000000..9ca7802 --- /dev/null +++ b/arch.sh @@ -0,0 +1,4 @@ +#!/bin/bash +VERSION=`cat info.rkt | grep version | sed -e 's/^[^0-9]*//' -e s'/[^0-9]*$//'` +echo VERSION=$VERSION +(cd ..; tar czf audio-manager-$VERSION.tar.gz --exclude .git --exclude "*.bak" --exclude "*.*~" audio-library-manager) diff --git a/audio-manager.rkt b/audio-manager.rkt index 36a86f0..7638e10 100644 --- a/audio-manager.rkt +++ b/audio-manager.rkt @@ -18,6 +18,7 @@ (define (audio-manager music-path opus-path #:log-level [log-level 'debug]) (let* ((ini-config-file (build-path music-path ".audio-manager.ini")) (ini (file->ini ini-config-file)) + (mail-oke (check-mail-config)) (report-flacs-with-id3 "FLAC files with id3 tags\n\n") (report-flac "") (report-opus "") @@ -206,54 +207,56 @@ ) (values base-path path info)) + ;; Converteer naar opus indien nodig en flac. (define (to-opus base-path path info) - (when (or (needs-processing? path info) - (needs-copying? info)) - (if (flac? path info) - (let ((path-part (get-path-part info))) - (unless (eq? path-part #f) - (let ((opus-file (path-replace-extension - (build-path opus-path path-part) - #".opus"))) - (set! processed-opus (+ processed-opus 1)) - (unless (file-exists? opus-file) - (info-am "Converting flac to opus: ~a" opus-file) - (rep-opus - (format "Converting flac to opus: ~a" (basename opus-file))) - (with-handlers ([exn? (λ (e) - (set! failed-converts (+ failed-converts 1)) - (err-am "Conversion of ~a: ~a" path e))]) - (unless (directory-exists? (basedir opus-file)) - (make-directory* (basedir opus-file))) - (if (convert-to-opus path opus-file ini) - (begin - (set! converted-files (+ converted-files 1)) - (info-am " Converted") - ) - (begin - (info-am " CONVERSION PROBLEM") - (rep-opus " Conversion failed!") - (set! failed-converts (+ failed-converts 1)) - ) - ) + (when (and (needs-processing? path info) + (flac? path info)) + (let ((path-part (get-path-part info))) + (unless (eq? path-part #f) + (let ((opus-file (path-replace-extension + (build-path opus-path path-part) + #".opus"))) + (set! processed-opus (+ processed-opus 1)) + (info-am "Converting flac to opus: ~a" opus-file) + (rep-opus + (format "Converting flac to opus: ~a" (basename opus-file))) + (with-handlers ([exn? (λ (e) + (set! failed-converts (+ failed-converts 1)) + (err-am "Conversion of ~a: ~a" path e))]) + (unless (directory-exists? (basedir opus-file)) + (make-directory* (basedir opus-file))) + (if (convert-to-opus path opus-file ini) + (begin + (set! converted-files (+ converted-files 1)) + (info-am " Converted") + ) + (begin + (info-am " CONVERSION PROBLEM") + (rep-opus " Conversion failed!") + (set! failed-converts (+ failed-converts 1)) + ) ) - ) ) ) ) - (begin ; copy files rechtstreeks indien nodig - (with-handlers ([exn? (λ (e) - (set! failed-copies (+ failed-copies 1)) - (err-am "Copy file ~a: ~a" path e))]) - (let ((path-part (get-path-part info))) - (unless (eq? path-part #f) - (let ((dest-path (build-path opus-path path-part))) - (unless (directory-exists? (basedir dest-path)) - (make-directory* (basedir dest-path))) - (copy-file path dest-path #:exists-ok? #t) - (set! copied-files (+ copied-files 1))))) - ) - ) + ) + ) + (values base-path path info)) + + ;; Kopieer bestanden rechtstreeks indien nodig en geen flac + (define (copy-other base-path path info) + (when (and (needs-copying? info) + (not (flac? path info))) + (with-handlers ([exn? (λ (e) + (set! failed-copies (+ failed-copies 1)) + (err-am "Copy file ~a: ~a" path e))]) + (let ((path-part (get-path-part info))) + (unless (eq? path-part #f) + (let ((dest-path (build-path opus-path path-part))) + (unless (directory-exists? (basedir dest-path)) + (make-directory* (basedir dest-path))) + (copy-file path dest-path #:exists-ok? #t) + (set! copied-files (+ copied-files 1))))) ) ) (values base-path path info)) @@ -262,11 +265,12 @@ (when (deleted? info) (let ((path-part (get-path-part info))) (unless (eq? path-part #f) - (let ((rm-path (if (flac? info) - (path-replace-extension - (build-path opus-path path-part) - #".opus") - (build-path opus-path path-part)))) + (let ((rm-path (build-path opus-path + (if (flac? path info) + (path-replace-extension + (build-path opus-path path-part) + #".opus") + path-part)))) (delete-directory/files rm-path #:must-exist? #f) (let ((normalized-sub-path (hash-ref info 'path))) (hash-remove! file-db-hash normalized-sub-path)) @@ -360,12 +364,16 @@ (sl-set-log-level log-level) (let ((fw (make-file-admin music-path file-db-hash))) + ;; Enrichement phase (set! fw (fw-add-step fw adjust-ext)) (set! fw (fw-add-step fw flac-with-id3)) (set! fw (fw-add-step fw flac-khz-bits)) + ;; Conversion phase (set! fw (fw-add-step fw flac-convert)) (set! fw (fw-add-step fw flac-picture)) (set! fw (fw-add-step fw to-opus)) + (set! fw (fw-add-step fw copy-other)) + ;; Cleanup/Logging phase (set! fw (fw-add-step fw deleter)) (set! fw (fw-add-step fw log-processed-file)) (let loop () diff --git a/info.rkt b/info.rkt index 537b051..7a0408c 100644 --- a/info.rkt +++ b/info.rkt @@ -2,15 +2,12 @@ (define collection "audio-library-manager") (define deps '("base" - "db-lib" - "keystore" "racket-audio" "simple-ini" "simple-log" - "smtp" - "racket-sprintf")) + )) (define scribblings '(("scribblings/audio-library-manager.scrbl" ()))) (define build-deps '("rackunit-lib" "scribble-lib" "racket-doc")) (define pkg-desc "Audio library maintenance tools for FLAC and Opus trees") -(define version "0.1.5") +(define version "0.2.2") (define pkg-authors '(hans-dijkema)) diff --git a/private/log.rkt b/private/log.rkt index dddb9a9..7d07b18 100644 --- a/private/log.rkt +++ b/private/log.rkt @@ -9,9 +9,4 @@ fatal-am sync-log-am) -(define log-defined #f) -(displayln (format "log-defined: ~a" log-defined)) -(set! log-defined #t) - (sl-def-log audio-manager am) - diff --git a/private/mail.rkt b/private/mail.rkt index 12a4a4d..8cc158a 100644 --- a/private/mail.rkt +++ b/private/mail.rkt @@ -4,25 +4,40 @@ net/head simple-ini) -(provide mail-report) +(provide mail-report + check-mail-config) + + +(define (get ini key msg) + (let ((v (ini-get ini 'mail key 'nil))) + (when (eq? v 'nil) + (error msg)) + v)) + +(define (get-config ini) + (let* ((from (get ini 'from "configure from address as name ")) + (to (get ini 'to "configure to address as name ")) + (server (get ini 'server "configure the smtp server")) + (port (ini-get ini 'mail 'port 25)) + (user (ini-get ini 'mail 'user #f)) + (passwd (ini-get ini 'mail 'passwd #f)) + ) + (values from to server port user passwd))) (define (mail-report ini subject report) - (let* ((get (λ (key msg) - (let ((v (ini-get ini 'mail key 'nil))) - (when (eq? v 'nil) - (error msg)) - v))) - (from (get 'from "configure from address as name ")) - (to (get 'to "configure to address as name ")) - (server (get 'server "configure the smtp server")) - (port (ini-get ini 'mail 'port 25)) - ) + (let-values (((from to server port user auth) (get-config ini))) (let* ((hdr (standard-message-header from (list to) '() '() subject))) (smtp-send-message server from (list to) hdr (if (list? report) report (list report)) - #:port-no port) + #:port-no port + #:auth-user user + #:auth-pwd passwd + ) ) ) ) +(define (check-mail-config ini) + (let-values (((from to server port user passwd) (get-config ini))) + #t)) \ No newline at end of file