emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: stardiviner <numbchild@gmail.com>
To: Org Mode <emacs-orgmode@gnu.org>
Subject: Add a new link type for video files
Date: Fri, 03 Jan 2020 17:07:16 +0800	[thread overview]
Message-ID: <87y2uohprv.fsf@gmail.com> (raw)


I write a patch to add new link type:

#+begin_example
[[video:/path/to/file.mp4::00:13:20]]
#+end_example

This will open video file in specific timestamp. And it is possible to add more
options in link. Like video player arguments.

I want to ask should I add this patch to Org Mode built-in?

Here is my patch source code:

#+begin_src emacs-lisp :file "ol-video.el"
;;; [[video:/path/to/file.mp4::00:13:20]]
(defcustom org-video-link-open-command "mplayer"
  "Specify the program for openning video: link."
  :type 'string)

(defvar org-video-link-extension-list '("avi" "rmvb" "ogg" "mp4" "mkv"))

(defun org-video-link-open (uri)
  "Open video file `URI' with video player."
  (let* ((list (split-string uri "::"))
         (path (car list))
         (start-timstamp (cadr list)))
    (make-process
     :command (list org-video-link-open-command
                    "-ss" start-timstamp
                    (expand-file-name (org-link-unescape path)))
     :name "org-video-link")))

(defun org-video-complete-link (&optional arg)
  "Create a video link using completion."
  (let ((file (read-file-name "Video: " nil nil nil nil
                              #'(lambda (file)
                                  (seq-contains-p
                                   org-video-link-extension-list
                                   (file-name-extension file)))))
        (pwd (file-name-as-directory (expand-file-name ".")))
        (pwd1 (file-name-as-directory (abbreviate-file-name
                                       (expand-file-name ".")))))
    (cond ((equal arg '(16))
           (concat "video:"
                   (abbreviate-file-name (expand-file-name file))))
          ((string-match
            (concat "^" (regexp-quote pwd1) "\\(.+\\)") file)
           (concat "video:" (match-string 1 file)))
          ((string-match
            (concat "^" (regexp-quote pwd) "\\(.+\\)")
            (expand-file-name file))
           (concat "video:"
                   (match-string 1 (expand-file-name file))))
          (t (concat "video:" file)))))

(org-link-set-parameters "video"
                         :follow #'org-video-link-open
                         :complete #'org-video-complete-link)
#+end_src

-- 
[ stardiviner ]
       I try to make every word tell the meaning what I want to express.

       Blog: https://stardiviner.github.io/
       IRC(freenode): stardiviner, Matrix: stardiviner
       GPG: F09F650D7D674819892591401B5DF1C95AE89AC3
      

             reply	other threads:[~2020-01-03  9:12 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-03  9:07 stardiviner [this message]
2020-01-03 20:02 ` Add a new link type for video files Eduardo Ochs
2020-01-07  8:27 ` Nicolas Goaziou
2020-01-31 11:17   ` Bastien
2020-01-31 12:37     ` stardiviner
2020-01-31 16:23       ` Bastien

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87y2uohprv.fsf@gmail.com \
    --to=numbchild@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).