summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOleg Pykhalov <go.wigust@gmail.com>2018-03-21 16:24:37 +0300
committerOleg Pykhalov <go.wigust@gmail.com>2018-03-22 07:45:20 +0300
commit28c97969a59906a184a74cafe5dec075ce4f8169 (patch)
treeea109bf98bf715eb2d3d7ee383687ffe66983909
downloademacs-youtube-stream-28c97969a59906a184a74cafe5dec075ce4f8169.tar.gz
Initial commit.HEADmaster
-rw-r--r--guix.scm76
-rw-r--r--youtube-stream.el115
2 files changed, 191 insertions, 0 deletions
diff --git a/guix.scm b/guix.scm
new file mode 100644
index 0000000..4cb2806
--- /dev/null
+++ b/guix.scm
@@ -0,0 +1,76 @@
+;;; guix.scm --- Guix package for Emacs-YouTube-stream
+
+;; Copyright © 2018 Oleg Pykhalov <go.wigust@gmail.com>
+
+;; 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 <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; This file contains Guix package for development version of
+;; Emacs-YouTube-stream. To build or install, run:
+;;
+;; guix build --file=guix.scm
+;; guix package --install-from-file=guix.scm
+
+;; The main purpose of this file though is to make a development
+;; environment for building Emacs-YouTube-stream:
+;;
+;; guix environment --pure --load=guix.scm
+
+;;; Code:
+
+(use-modules ((guix licenses) #:prefix license:)
+ (guix build utils)
+ (guix build-system emacs)
+ (guix gexp)
+ (guix git-download)
+ (guix packages)
+ (ice-9 popen)
+ (ice-9 rdelim))
+
+(define %source-dir (dirname (current-filename)))
+
+(define (git-output . args)
+ "Execute 'git ARGS ...' command and return its output without trailing
+newspace."
+ (with-directory-excursion %source-dir
+ (let* ((port (apply open-pipe* OPEN_READ "git" args))
+ (output (read-string port)))
+ (close-port port)
+ (string-trim-right output #\newline))))
+
+(define (current-commit)
+ (git-output "log" "-n" "1" "--pretty=format:%H"))
+
+(define emacs-youtube-stream
+ (let ((commit (current-commit)))
+ (package
+ (name "emacs-youtube-stream")
+ (version (string-append "0.0.1" "-" (string-take commit 7)))
+ (source (local-file %source-dir
+ #:recursive? #t
+ #:select? (git-predicate %source-dir)))
+ (build-system emacs-build-system)
+ (home-page "https://github.com/wigust/emacs-youtube-stream")
+ (synopsis "Open YouTube stream video and live chat")
+ (description "This package provides an Emacs function to open
+YouTube video and live chat in preferred programs.")
+ (license license:gpl3+))))
+
+emacs-youtube-stream
+
+;;; guix.scm ends here
diff --git a/youtube-stream.el b/youtube-stream.el
new file mode 100644
index 0000000..2c5cc64
--- /dev/null
+++ b/youtube-stream.el
@@ -0,0 +1,115 @@
+;;; youtube-stream.el --- Open YouTube stream video and chat
+
+;; Copyright © 2018 Oleg Pykhalov <go.wigust@gmail.com>
+
+;; 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 <http://www.gnu.org/licenses/>.
+
+;;; 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