;;; youtube-stream.el --- Open YouTube stream video and chat ;; Copyright © 2018 Oleg Pykhalov ;; This file is part of Emacs-youtube-stream. ;; Emacs-YouTube-stream 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. ;; ;; Emacs-YouTube-stream 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 Emacs-YouTube-stream. ;; If not, see . ;;; Commentary: ;; This file provides `youtube-stream-open', the function to open ;; YouTube stream video and live chat. ;;; Code: (defgroup youtube-stream nil "Settings for `youtube-stream'." :prefix "youtube-stream-" :group 'youtube-stream) (defcustom youtube-stream-url-regexp (rx "http" (zero-or-one "s") "://" (zero-or-one "www.") "youtube.com") "Regexp matching YouTube URL." :type 'regexp :group 'youtube-stream) (defcustom youtube-stream-video-id-url-regexp (concat youtube-stream-url-regexp (rx "/watch?v=" (group (one-or-more alphanumeric)))) "Regexp matching Youtube video ID URL." :type 'regexp :group 'youtube-stream) (defcustom youtube-stream-open-chat-function #'browse-url "Function to open YouTube live chat." :type 'function :group 'youtube-stream) (defcustom youtube-stream-open-video-function #'browse-url "Function to open YouTube stream." :type 'string :group 'youtube-stream) (defcustom youtube-stream-open-video t "If `t' open YouTube video in `youtube-stream-stream-player'." :type 'boolean :group 'youtube-stream) (defcustom youtube-stream-open-chat t "If `t' open YouTube live chat in `youtube-stream-stream-browser'." :type 'boolean :group 'youtube-stream) (defcustom youtube-stream-live-chat-url-template "https://www.youtube.com/live_chat?v=%s&is_popout=1" "URL template used in `youtube-stream-live-chat-url'." :type 'string :group 'youtube-stream) (defcustom youtube-stream-video-url-template "https://www.youtube.com/watch?v=%s" "URL template used id `youtube-stream-video-url'") (defun youtube-stream-get-id (url) "Return video id from YouTube URL." (string-match youtube-stream-video-id-url-regexp url) (match-string 1 url)) (defun youtube-stream-live-chat-url (id) "Return a YouTube live chat URL from ID." (format youtube-stream-live-chat-url-template id)) (defun youtube-stream-video-url (id) "Return a YouTube video URL from ID." (format youtube-stream-video-url-template id)) (defun youtube-stream-quote-url (url) "Return a quoted URL." (format "\"%s\"" url)) (defun youtube-stream-open (url) "Open YouTube live chat from URL Use YouTube video URL present from a GUI clipboard if available." (interactive (let ((clipboard (x-get-clipboard))) (list (if (string-match-p youtube-stream-video-id-url-regexp clipboard) clipboard (read-string "YouTube URL: "))))) (let ((id (youtube-stream-get-id url))) (if youtube-stream-open-chat (funcall youtube-stream-open-chat-function (youtube-stream-live-chat-url id))) (if youtube-stream-open-video (funcall youtube-stream-open-video-function (youtube-stream-video-url id))))) (provide 'youtube-stream) ;;; youtube-stream.el ends here