diff options
| author | Lars Ingebrigtsen | 2021-11-09 06:19:09 +0100 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2021-11-09 06:19:09 +0100 |
| commit | 9a67efa11b0fb9add6325cf68f8c0f8c7fcff861 (patch) | |
| tree | 9580b0f0e5f6808baf1c1e1c270d6cfc0be7594e | |
| parent | 5ba738eb0a24e54852e3a5fb11894a3f39355b7e (diff) | |
| download | emacs-9a67efa11b0fb9add6325cf68f8c0f8c7fcff861.tar.gz emacs-9a67efa11b0fb9add6325cf68f8c0f8c7fcff861.zip | |
Optionally use use xwidgets to display <video> elements in shr
* doc/misc/eww.texi (Advanced): Document it.
* lisp/net/shr.el (shr-use-xwidgets-for-media): New user option.
(shr-tag-video): Use xwidgets to display <video> elements.
| -rw-r--r-- | doc/misc/eww.texi | 9 | ||||
| -rw-r--r-- | etc/NEWS | 9 | ||||
| -rw-r--r-- | lisp/net/shr.el | 42 |
3 files changed, 55 insertions, 5 deletions
diff --git a/doc/misc/eww.texi b/doc/misc/eww.texi index 5d308efba4d..95e59d98f8a 100644 --- a/doc/misc/eww.texi +++ b/doc/misc/eww.texi | |||
| @@ -397,6 +397,15 @@ transformed URL. By default, this variable contains | |||
| 397 | @code{eww-remove-tracking}, which removes the common @samp{utm_} | 397 | @code{eww-remove-tracking}, which removes the common @samp{utm_} |
| 398 | trackers from links. | 398 | trackers from links. |
| 399 | 399 | ||
| 400 | @cindex video | ||
| 401 | @vindex shr-use-xwidgets-for-media | ||
| 402 | If Emacs has been built with xwidget support, EWW can use that to | ||
| 403 | display @samp{<video>} elements. However, this support is still | ||
| 404 | experimental, and on some systems doesn't work (and even worse) may | ||
| 405 | crash your Emacs, so this feature is off by default. If you wish to | ||
| 406 | switch it on, set @code{shr-use-xwidgets-for-media} to a | ||
| 407 | non-@code{nil} value. | ||
| 408 | |||
| 400 | @node Command Line | 409 | @node Command Line |
| 401 | @chapter Command Line Usage | 410 | @chapter Command Line Usage |
| 402 | 411 | ||
| @@ -228,7 +228,14 @@ If non-nil, 'C-c C-a' will put attached files at the end of the message. | |||
| 228 | *** 'texinfo-mode' now has a specialised 'narrow-to-defun' definition. | 228 | *** 'texinfo-mode' now has a specialised 'narrow-to-defun' definition. |
| 229 | It narrows to the current node. | 229 | It narrows to the current node. |
| 230 | 230 | ||
| 231 | ** eww | 231 | ** eww/shr |
| 232 | |||
| 233 | +++ | ||
| 234 | *** New user option 'shr-use-xwidgets-for-media'. | ||
| 235 | If non-nil (and Emacs has been built with support for xwidgets), | ||
| 236 | display <video> elements with an xwidget. Note that this is | ||
| 237 | experimental, and is known to crash Emacs on some systems, and just | ||
| 238 | doesn't work on other systems. Also see etc/PROBLEMS. | ||
| 232 | 239 | ||
| 233 | +++ | 240 | +++ |
| 234 | *** New user option 'eww-url-transformers'. | 241 | *** New user option 'eww-url-transformers'. |
diff --git a/lisp/net/shr.el b/lisp/net/shr.el index cb8ee73c14c..295ffddf059 100644 --- a/lisp/net/shr.el +++ b/lisp/net/shr.el | |||
| @@ -1626,6 +1626,14 @@ url if no type is specified. The value should be a float in the range 0.0 to | |||
| 1626 | :version "24.4" | 1626 | :version "24.4" |
| 1627 | :type '(alist :key-type regexp :value-type float)) | 1627 | :type '(alist :key-type regexp :value-type float)) |
| 1628 | 1628 | ||
| 1629 | (defcustom shr-use-xwidgets-for-media nil | ||
| 1630 | "If non-nil, use xwidgets to display video and audio elements. | ||
| 1631 | This also depends on Emacs being built with xwidgets capability. | ||
| 1632 | Note that this is experimental, and may lead to instability on | ||
| 1633 | some platforms." | ||
| 1634 | :type 'boolean | ||
| 1635 | :version "29.1") | ||
| 1636 | |||
| 1629 | (defun shr--get-media-pref (elem) | 1637 | (defun shr--get-media-pref (elem) |
| 1630 | "Determine the preference for ELEM. | 1638 | "Determine the preference for ELEM. |
| 1631 | The preference is a float determined from `shr-prefer-media-type'." | 1639 | The preference is a float determined from `shr-prefer-media-type'." |
| @@ -1668,10 +1676,36 @@ The preference is a float determined from `shr-prefer-media-type'." | |||
| 1668 | (start (point))) | 1676 | (start (point))) |
| 1669 | (unless url | 1677 | (unless url |
| 1670 | (setq url (car (shr--extract-best-source dom)))) | 1678 | (setq url (car (shr--extract-best-source dom)))) |
| 1671 | (if (> (length image) 0) | 1679 | (if (and shr-use-xwidgets-for-media |
| 1672 | (shr-indirect-call 'img nil image) | 1680 | (fboundp 'make-xwidget)) |
| 1673 | (shr-insert " [video] ")) | 1681 | ;; Play the video. |
| 1674 | (shr-urlify start (shr-expand-url url)))) | 1682 | (progn |
| 1683 | (let ((widget (make-xwidget | ||
| 1684 | 'webkit | ||
| 1685 | "Video" | ||
| 1686 | (truncate (* (window-pixel-width) 0.8)) | ||
| 1687 | (truncate (* (window-pixel-width) 0.8 0.75)))) | ||
| 1688 | (file (make-temp-file "shr" nil ".html"))) | ||
| 1689 | (run-at-time 1 nil (lambda () | ||
| 1690 | (ignore-errors | ||
| 1691 | (delete-file file)))) | ||
| 1692 | (insert | ||
| 1693 | (propertize | ||
| 1694 | " [video] " | ||
| 1695 | 'display (list 'xwidget :xwidget widget))) | ||
| 1696 | (with-temp-buffer | ||
| 1697 | (insert | ||
| 1698 | (format | ||
| 1699 | "<video autoplay loop muted><source src=%S type=\"video/mp4\"></source></video>" | ||
| 1700 | url)) | ||
| 1701 | (write-region (point-min) (point-max) file nil 'silent)) | ||
| 1702 | (xwidget-webkit-goto-uri widget | ||
| 1703 | (concat "file://" file)))) | ||
| 1704 | ;; No xwidgets. | ||
| 1705 | (if (> (length image) 0) | ||
| 1706 | (shr-indirect-call 'img nil image) | ||
| 1707 | (shr-insert " [video] ")) | ||
| 1708 | (shr-urlify start (shr-expand-url url))))) | ||
| 1675 | 1709 | ||
| 1676 | (defun shr-tag-audio (dom) | 1710 | (defun shr-tag-audio (dom) |
| 1677 | (let ((url (dom-attr dom 'src)) | 1711 | (let ((url (dom-attr dom 'src)) |