From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id wK0QCRnjrWKFDwEAbAwnHQ (envelope-from ) for ; Sat, 18 Jun 2022 16:37:13 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id AKkcCBnjrWJJnwAAG6o9tA (envelope-from ) for ; Sat, 18 Jun 2022 16:37:13 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id A12B33E884 for ; Sat, 18 Jun 2022 16:37:12 +0200 (CEST) Received: from localhost ([::1]:42620 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o2ZZV-00034m-DS for larch@yhetil.org; Sat, 18 Jun 2022 10:37:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58578) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o2ZYI-00034d-48 for emacs-orgmode@gnu.org; Sat, 18 Jun 2022 10:35:54 -0400 Received: from mout02.posteo.de ([185.67.36.66]:45169) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o2ZYF-0005vF-7I for emacs-orgmode@gnu.org; Sat, 18 Jun 2022 10:35:53 -0400 Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 7C719240107 for ; Sat, 18 Jun 2022 16:35:47 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1655562947; bh=+VEDw7O7AxUaVPIONBSLBpCxoI2safY8Fyw5i9u9A38=; h=From:To:Subject:Date:From; b=KVWHkJ4iua13/Psp29wnEvU12ifvCECMhA1NCy1KU8QmMfj8iSmgxZGtQMp7QLyX5 swm4LikvjwrEkmQ2dsWHt+lIHr32gDYDMQQ/J6+qWuo8f1K2aSkCEO2x7VV2IpRaOw bOZGn8Tx8u09/2IywbO09/DNQySN2ncmfSL74V6Ay2o4ojQJeL2H2InBpnOHf09rqL eEIv+MT+StWCrzZSXGUKQ+xqOTPNU7q6QBG0YftX/r3zI0M+tJ8Up1BvcmuSzuWfRr iATlX11E9PUZ1VkNFuN8Upu9CBmEAd9qRCRa/nlfkYqheOWd3zJCJQgKH4OIkw8xZc w/HQUWQyarlhQ== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4LQJNy5ydfz6tmc for ; Sat, 18 Jun 2022 16:35:46 +0200 (CEST) From: =?utf-8?Q?Juan_Manuel_Mac=C3=ADas?= To: orgmode Subject: [Tip] Screenshots as org links with EMMS and socat Date: Sat, 18 Jun 2022 14:35:44 +0000 Message-ID: <871qvmt4xr.fsf@posteo.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Received-SPF: pass client-ip=185.67.36.66; envelope-from=maciaschain@posteo.net; helo=mout02.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1655563032; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=rB6OQGclRXjC5wzui1mNkWGeVFCuUQPRqbqbDRFwImw=; b=Q1t4H0Rk69and8famlMV3JWu6rf2CV+invcPzeJaJ421iWsobkESDeYGJ+h6SQ9YOlUmUM WtyX0U99sI2x/LAwgzbQTSj2CikgP1FjwobqYP3enxcGSJIO/YUWIExzqFzxKQYqk4EBbX 952e9YnBP8CbnR6T42KaFQt5SfsrhJ15KfAK4k1qxyNdAr3tZCZnyr3WfdaVwn8PyotHE3 DP5HTxELhFPaeAG01cqWBs2qL9nvxSrh37r8Bwj28S58CPCmh7EYlNU3LLQYWsYAvlu02o K8VyvPjurF1cLrfRr253ql0KNLr1zYi0TJirpAhANbpG/UeQlv25qdUhV/4psg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1655563032; a=rsa-sha256; cv=none; b=T8TfEgkqLc/x+Knbec1zvnDI6F+JdZDbivjDrg3Czsg26aIP/FHD5oYoO8cPXePQhswSkr t6EGD235buqVNdvnGnR4cgVF7aBSyNW8/Xbn6zo/3F50svHlN2XVhb8A1StPKwSjTEhLNa qSe5+2fCgyzpvAE4BUVKGuoYfBrAxwZaNQQ8XsXFiDGqbYM7YpT7pTHdu93QQvYcYsokLy n8yy/9estfRpXuH9ObNsSd7rC+hsaGTdIUnxcWDqW3WeATaC3oYAB0xtqs0Jp0pvrqwj0u SK6MV7ObIiamaxHK3ra5JpCf8cHl/LPW39umt3YdpkhTqx1dsZ741wAsEbxzIg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=KVWHkJ4i; dmarc=pass (policy=none) header.from=posteo.net; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -4.19 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=KVWHkJ4i; dmarc=pass (policy=none) header.from=posteo.net; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: A12B33E884 X-Spam-Score: -4.19 X-Migadu-Scanner: scn1.migadu.com X-TUID: M/pdyA2EYzfu Hi all, I=E2=80=99m writing an article about a movie, and I needed to get some screenshots as image links inside Org. I know some package for those things, like org-media-note, a nice library but for me it has two drawbacks: it has, for what I need, too many bells and whistles; and uses the mpv.el package in the background. I use the mpv player, but through EMMS. In fact, I have all my multimedia setup in Emacs around EMMS, and I'm too lazy to use something else. What I am looking for is, therefore, something much simpler, EMMS-centric and "homemade". If someone is in the same situation as me and also uses EMMS with mpv, I=E2=80= =99m sharing my solution here, in case it=E2=80=99s useful (I=E2=80=99ve taken s= ome ideas from org-media-note and mpv.el): Socat needs to be installed first, to communicate with the mpv process via the command line. In Arch it is in the official repositories: =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80 =E2=94=82 sudo pacman -S socat =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80 My EMMS configuration: =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80 =E2=94=82 (require 'emms-setup) =E2=94=82 (emms-all) =E2=94=82 (emms-default-players) =E2=94=82 (setq emms-player-list '(emms-player-mpv)) =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80 And these two variables are for socat communication: =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80 =E2=94=82 (setq emms-player-mpv-ipc-method 'ipc-server) =E2=94=82 (setq emms-player-mpv-ipc-socket "~/.emacs.d/emms/mpv-ipc.sock") =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80 The directory to save the screenshots: =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80 =E2=94=82 (defvar my-screenshot-dir "/path/to/screenshot/dir/") =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80 This function returns the formatted timestamp and path of the current mpv process: =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80 =E2=94=82 (require 'org-timer) =E2=94=82 (defun my-mpv-format-timestamp-and-path () =E2=94=82 (let* ((timestamp-command (shell-command-to-string =E2=94=82 "echo '{ \"command\": [\"get_property\", \"playback-time\"] }'= | socat - ~/.emacs.d/emms/mpv-ipc.sock")) =E2=94=82 (path-command (shell-command-to-string =E2=94=82 "echo '{ \"command\": [\"get_property\", \"path\"] }' | socat - = ~/.emacs.d/emms/mpv-ipc.sock")) =E2=94=82 (timestamp (org-timer-secs-to-hms (round =E2=94=82 (cdr =E2=94=82 (car =E2=94=82 (json-read-from-string timestamp-command)))))) =E2=94=82 (path (cdr =E2=94=82 (car =E2=94=82 (json-read-from-string path-command))))) =E2=94=82 (format "%s --- %s" path timestamp))) =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80 And, finally, the function that inserts the screenshot at point as an org image link: =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80 =E2=94=82 (defun my-mpv-put-screenshot-on-org () =E2=94=82 (let* ((time (format-time-string "%d-%m-%y-%H-%M-%S")) =E2=94=82 (screenshot-file-name (format "fotograma-%s.png" time)) =E2=94=82 (screenshot-final (expand-file-name screenshot-file-name my-scr= eenshot-dir))) =E2=94=82 (start-process-shell-command=20 =E2=94=82 "screenshot" nil =E2=94=82 (format =E2=94=82 "echo \"screenshot-to-file %s\" | socat - \"~/.emacs.d/emms= /mpv-ipc.sock\"" =E2=94=82 screenshot-final)) =E2=94=82 (insert (format "#+media: %s\n" (my-mpv-format-timestamp-and-= path))) =E2=94=82 (insert (format "[[file:%s]]" screenshot-final)))) =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80 A short demo video: https://cloud.disroot.org/s/6zrGYxkKT67kFGx Best regards, Juan Manuel