aboutsummaryrefslogtreecommitdiff
path: root/emacs/.emacs.d/lisp/my/my-media-segment.el
diff options
context:
space:
mode:
Diffstat (limited to 'emacs/.emacs.d/lisp/my/my-media-segment.el')
-rw-r--r--emacs/.emacs.d/lisp/my/my-media-segment.el46
1 files changed, 31 insertions, 15 deletions
diff --git a/emacs/.emacs.d/lisp/my/my-media-segment.el b/emacs/.emacs.d/lisp/my/my-media-segment.el
index f222316..003953a 100644
--- a/emacs/.emacs.d/lisp/my/my-media-segment.el
+++ b/emacs/.emacs.d/lisp/my/my-media-segment.el
@@ -50,18 +50,20 @@ The process can be started by applying 'start-process' on START-PROCESS-ARGS."
(when my-media-segment-queued-jobs
(funcall (pop my-media-segment-queued-jobs))))
-(defun my-segment-media-file-1 (media-file-name desc-file-name)
+(defun my-segment-media-file-1 (media-file-name info-file-name)
"Run ffmpeg asynchronously to segment file-name according to description.
Uses `my-media-segment-max-inflight' to limit number of inflight tasks."
(interactive (list
(read-file-name "Choose media file: ")
- (read-file-name "Choose description file: ")))
+ (read-file-name
+ "Choose description file (.info.json or .description): "
+ ;; nil
+ ;; (file-name-with-extension media-file-name ".info.json")
+ ;; t
+ )))
(let* ((dir (file-name-sans-extension (expand-file-name media-file-name)))
- (info (my-get-media-segments
- (with-temp-buffer
- (insert-file-contents desc-file-name)
- (buffer-string))))
+ (info (my-get-media-segments info-file-name))
(total (length info))
(pad (1+ (floor (log10 total))))
(idx 0)
@@ -94,12 +96,29 @@ Uses `my-media-segment-max-inflight' to limit number of inflight tasks."
(funcall thunk)
(my-media-segment-enqueue-process thunk))))))
-(defun my-get-media-segments (description)
+(defun my-get-media-segments (info-file-name)
+ (if (equal (file-name-extension info-file-name) "json")
+ (my-get-media-segments-from-json info-file-name)
+ (my-get-media-segments-from-descr info-file-name)))
+
+(defun my-get-media-segments-from-json (json-file-name)
+ (let ((info
+ (with-temp-buffer
+ (insert-file-contents json-file-name)
+ (goto-char (point-min))
+ (json-read))))
+ (seq-map
+ (lambda (ch)
+ (let-alist ch
+ (list :title (my-make-filename .title) :start (format "%s" .start_time)
+ :end (format "%s" .end_time))))
+ (alist-get 'chapters info))))
+
+(defun my-get-media-segments-from-descr (descr-file-name)
"Output title start end triplets."
(let ((results) (title) (start) (end))
(with-temp-buffer
- (erase-buffer)
- (insert description)
+ (insert-file-contents descr-file-name)
(goto-char (point-min))
(save-excursion
(while (re-search-forward
@@ -127,19 +146,16 @@ Uses `my-media-segment-max-inflight' to limit number of inflight tasks."
)))
(defvar my-segment-media-max-async 10)
-(defun my-segment-media-file (media-file-name desc-file-name synchronously)
+(defun my-segment-media-file (media-file-name info-file-name synchronously)
"Run ffmpeg asynchronously to segment file-name according to description.
With a prefix-arg, run synchronously."
(interactive (list
(read-file-name "Choose media file: ")
- (read-file-name "Choose description file: ")
+ (read-file-name "Choose info file: ")
current-prefix-arg))
(let* ((dir (file-name-sans-extension (expand-file-name media-file-name)))
- (info (my-get-media-segments
- (with-temp-buffer
- (insert-file-contents desc-file-name)
- (buffer-string))))
+ (info (my-get-media-segments info-file-name))
(total (length info))
(idx 0))
(when (or synchronously (<= total my-segment-media-max-async)