From 599e269e67e531dd19ac8d457b1e0f724d19da1e Mon Sep 17 00:00:00 2001 From: Leo Butler Date: Thu, 12 May 2022 11:46:04 -0500 Subject: [PATCH] myth-move-and-symlink-watched-files Move a watched, transcoded file from recordings directory to watched-recordings. --- ffmpeg-myth.scm | 55 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/ffmpeg-myth.scm b/ffmpeg-myth.scm index 483265e..a0b8511 100755 --- a/ffmpeg-myth.scm +++ b/ffmpeg-myth.scm @@ -21,6 +21,7 @@ (define ffmpeg-transcoding-options "-c:v libx264 -preset slow -crf 21 -c:a ac3 -g 60 -keyint_min 30") (define ffmpeg-transcoded-file-muxer 'mpegts) ;; 'matroska (define recordings-directory "/var/lib/mythtv/recordings") +(define watched-recordings-directory "/var/lib/mythtv/watched-recordings") (define working-directory "/mnt/lvraid5/ffmpeg-cut-list.d") (define mythtv-recorded-table->metadata-list '(chanid starttime endtime title subtitle description season episode recordid seriesid programid inetref previouslyshown originalairdate)) (define (mythconverg-input-file-name) @@ -593,9 +594,61 @@ (lambda (key . args) (list 'error (recording-basename rec)))))) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; File-system handling +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +(define (move-file old new) + (shell-command-to-string (simple-format #f "mv ~a ~a" old new))) +(define (symlink-file target linkname) + (shell-command-to-string (simple-format #f "ln -s -r ~a ~a" target linkname))) +(define (symlink? name) + (eq? 'symlink (stat:type (lstat name)))) +(define (file-chain name) + (letrec ((dereference (lambda (s rst) + (if (eq? #f s) + rst + (dereference (if (symlink? s) (readlink s) #f) (cons s rst)))))) + (dereference name '()))) +(define (delete-file-chain name) + (letrec ((delete-file1 (lambda (file) + (catch #t (lambda () + (delete-file file)) + (lambda (key . args) + (simple-format #t "delete-file: Error ~a, ~a\n" key args)))))) + (map delete-file1 (file-chain name)))) + +(define (mythtv-move+symlink-watched-files0 files) + (letrec ((maybe-mv-files (lambda (files . rest) + (cond ((null? files) + rest) + ((string? (caar files)) + (maybe-mv-files (cdr files) (cons (maybe-mv-file (caar files)) rest))) + (#t + (maybe-mv-files (cdr files) (cons (caar files) 'skipped) rest))))) + (maybe-mv-file (lambda (file) + (let ((f (simple-format #f "~a/~a" recordings-directory file)) + (n (simple-format #f "~a/~a" watched-recordings-directory file))) + (cond ((not (access? f F_OK)) + (cons f 'file-does-not-exist)) + ((symlink? f) + (cons f 'symlink)) + (#t + (move-file f n) + (symlink-file n f) + (cons f n))))))) + (maybe-mv-files files))) + +(define* (mythtv-move-and-symlink-watched-files #:optional (files '())) + (let ((watched (if (null? files) (mythconverg-execute+parse "select basename from recorded where watched=1 and (basename like '%.h264.ts' or basename like '%.mkv');") files))) + (mythtv-move+symlink-watched-files0 files))) + + + + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; MAIN ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -(define (ffmpeg-myth0 chanid starttime cut-or-skip) +(define (ffmpeg-myth1 chanid starttime cut-or-skip) (let* ((rec (create-record-data chanid starttime cut-or-skip)) (cmd (ffmpeg-split+transcode-recording rec)) (tr-rec (create-record-data-for-transcode rec)))