Move a watched, transcoded file from recordings directory to watched-recordings.
This commit is contained in:
Leo Butler 2022-05-12 11:46:04 -05:00
parent 1e8a1d861f
commit 599e269e67
1 changed files with 54 additions and 1 deletions

View File

@ -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)
(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)
((string? (caar files))
(maybe-mv-files (cdr files) (cons (maybe-mv-file (caar files)) rest)))
(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))
(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)))