diff --git a/elisp/yt-stopwatch/probe.scpt b/elisp/yt-stopwatch/probe.scpt new file mode 100644 index 000000000..f9270315b Binary files /dev/null and b/elisp/yt-stopwatch/probe.scpt differ diff --git a/elisp/yt-stopwatch/yt-stopwatch.el b/elisp/yt-stopwatch/yt-stopwatch.el new file mode 100644 index 000000000..4e23a55fb --- /dev/null +++ b/elisp/yt-stopwatch/yt-stopwatch.el @@ -0,0 +1,39 @@ + +(defconst yt-stopwatch-script-path (file-name-directory load-file-name)) + +(defun yt-stopwatch-record-time () + (interactive) + (beginning-of-line) + (insert (format "* %ss - " (yt-stopwatch--reformat-time (cdr (yt-stopwatch--probe)))))) + +(defun yt-stopwatch--reformat-time (seconds) + (format-time-string "%H:%M:%S" (encode-time (string-to-number (car seconds)) 0 0 0 0 0))) + +(defun yt-stopwatch-video-name () + (interactive) + (beginning-of-line) + (insert (format "%s\n" (car (yt-stopwatch--probe))))) + +(defun yt-stopwatch--probe () + (let ((out (shell-command-to-string (format "osascript %s/probe.scpt" yt-stopwatch-script-path)))) + (if (string-equal out "---\n") + (user-error "VLC isn't running or no video playing") + (split-string out " || " t "[\n \t]+")))) + +(defun yt-stopwatch-test () + (interactive) + (let ((data (yt-stopwatch--probe))) + (message "Video: %s \n Time: %ss" (car data) (cdr data)))) + +(defvar yt-stopwatch-mode-map + (let ((map (make-sparse-keymap))) + (define-key map (kbd "C-c y") 'yt-stopwatch-record-time) + (define-key map (kbd "C-c C-y") 'yt-stopwatch-video-name) + map)) + +(define-minor-mode yt-stopwatch-mode + :keymap yt-stopwatch-mode-map + :group yt-stopwatch-mode) + +(provide 'yt-stopwatch) +;;; yt-stopwatch.el ends here diff --git a/init.el b/init.el index 0e9c9a466..e51f76eda 100644 --- a/init.el +++ b/init.el @@ -42,6 +42,7 @@ (let ((default-directory my-elisp-dir)) (normal-top-level-add-subdirs-to-load-path)) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Just the... bear necessities... (mapc 'require @@ -85,6 +86,7 @@ ;; init-vala init-web init-yasnippet ; type for me + init-youtube ; tools for youtube vids my-bindings my-settings diff --git a/init/init-youtube.el b/init/init-youtube.el new file mode 100644 index 000000000..9b7b47bd0 --- /dev/null +++ b/init/init-youtube.el @@ -0,0 +1,6 @@ + +(require 'yt-stopwatch) + +(provide 'init-youtube) +;;; init-youtube.el ends here +