From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Alexandre Oliva Newsgroups: gmane.emacs.devel Subject: subtitler Date: Thu, 04 Mar 2021 16:33:33 -0300 Organization: Free thinker, not speaking for the GNU Project Message-ID: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="695"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Mar 04 22:27:30 2021 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lHvVJ-000AaO-OM for ged-emacs-devel@m.gmane-mx.org; Thu, 04 Mar 2021 22:27:29 +0100 Original-Received: from localhost ([::1]:44302 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lHvVI-0003AB-QF for ged-emacs-devel@m.gmane-mx.org; Thu, 04 Mar 2021 16:27:28 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:46986) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lHtjB-0005oO-W8 for emacs-devel@gnu.org; Thu, 04 Mar 2021 14:33:42 -0500 Original-Received: from linux-libre.fsfla.org ([209.51.188.54]:53194 helo=free.home) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lHtjB-0003z0-8S for emacs-devel@gnu.org; Thu, 04 Mar 2021 14:33:41 -0500 Original-Received: from livre (livre.home [172.31.160.2]) by free.home (8.15.2/8.15.2) with ESMTPS id 124JXYed177253 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 4 Mar 2021 16:33:34 -0300 X-Scanned-By: MIMEDefang 2.84 X-Mailman-Approved-At: Thu, 04 Mar 2021 16:26:23 -0500 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:265987 Archived-At: --=-=-= Content-Type: text/plain Hello, (please keep me copied explicitly in responses) I was looking for something to turn a transcript into time-synced subtitles in Emacs the other day, couldn't find anything, and came up with this. It's works well enough for me, but I'm sure it would need some more polish to work for a wider user base, and I'm hardly fluent as an elisp coder, so... would anyone like to turn this into a proper module or package? (or point me at something else I missed that does the job in a much better way ;-) I have a copyright assignment on file, so in case you integrate it with GNU Emacs, please change my copyright notice to "Contributed by", and make it copyright FSF. Thanks, --=-=-= Content-Type: application/emacs-lisp Content-Disposition: attachment; filename=subtitler.el Content-Transfer-Encoding: quoted-printable ;; Subtitler - sync transcripts into mpsub files ;; https://www.fsfla.org/blogs/lxo/2021-02-28-syncing-subtitles-in-freedom ;; Bind some key, say RET, to subtitler-insert-time, then type it at ;; the time and point you wish to end a subtitle and start another. ;; Copyright 2021 Alexandre Oliva ;; This file is an extension for GNU Emacs. ;; This file is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; This file is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this file. If not, see . (provide 'subtitler) (defvar subtitler-base-time nil "This is the start time for the currently-open subtitle entry. Set it to (current-time) to resync.") (defvar subtitler-auto-end-of-line nil "Set this to t to move to the end of the line after starting a new subtit= le entry. This is useful if the transcript already has line breaks at suit= able places.") (defun subtitler-insert-time () "Insert an mpsub subtitle break at the current point. Bind this interactive function to RET to conveniently add timing info to a transcript. If it's the first subtitle entry, the file header is inserted, and time-keeping is started. Otherwise, the currently open subtitle entry is closed with the duration since it was started, and a new one is opened with a zero-length gap. Use blank lines for no-text intervals; they can be cleaned up mechanically later. " (interactive) (let ((next-time (current-time))) (insert "\n\n0 ") (if (not (looking-at "\n")) (insert "\n") (goto-char (+ (point) 1))) (if (not (search-backward "\n\n0 " nil t 2)) (progn (goto-char (point-min)) (insert "FORMAT=3DTIME")) (goto-char (match-end 0)) (insert (format "%.1f" (float-time (time-subtract next-time subtitler-base-time))))) (search-forward "\n\n0 \n") (goto-char (match-end 0)) (if (subtitler-auto-end-of-line) (end-of-line)) (setq subtitler-base-time next-time))) --=-=-= Content-Type: text/plain -- Alexandre Oliva, happy hacker https://FSFLA.org/blogs/lxo/ Free Software Activist GNU Toolchain Engineer Vim, Vi, Voltei pro Emacs -- GNUlius Caesar --=-=-=--