summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThanos Apollo <[email protected]>2023-09-25 02:35:02 +0300
committerThanos Apollo <[email protected]>2023-09-25 02:35:02 +0300
commit1acb7b40df89093ad25c12a6dfee8fc568adee23 (patch)
tree41e482b1637d1ef3ec39ed80b6648b0c9c3d189e
parentf0bf3c4e5caff82c166046516e3dd856c99cf6f7 (diff)
[Rewrite] seperate yeetube-mpv functionality
- Seperate yeetube-mpv - Make it easier to use other programs as yeetube-player, such as emms
-rw-r--r--yeetube-mpv.el92
-rw-r--r--yeetube.el89
2 files changed, 98 insertions, 83 deletions
diff --git a/yeetube-mpv.el b/yeetube-mpv.el
new file mode 100644
index 0000000..dcbbdd7
--- /dev/null
+++ b/yeetube-mpv.el
@@ -0,0 +1,92 @@
+;;; yeetube-mpv.el --- Provide yeetube mpv functionality -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2023 Thanos Apollo
+
+;; Author: Thanos Apollo <[email protected]>
+;; Keywords: extensions youtube videos invidious
+;; URL: https://git.thanosapollo.com/yeetube
+
+;; Version: 0.1
+;; Package-Requires: ((emacs "27.2"))
+
+;; This program 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 program 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 program. If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; This package is a yeetube extension, to start an mpv process and
+;; control it
+
+;;; Code:
+
+(require 'yeetube)
+
+(defcustom yeetube-mpv-disable-video nil
+ "Add no-video flag when using mpv."
+ :type 'boolean
+ :safe #'booleanp
+ :group 'yeetube)
+
+(defun yeetube-process (command)
+ "Start yeetube process for shell COMMAND."
+ (let ((yeetube-process "yeetube"))
+ (dolist (process (process-list))
+ (when (string-match yeetube-process (process-name process))
+ (kill-process process)))
+ (sit-for 0.1)
+ (unless (get-process yeetube-process)
+ (start-process-shell-command
+ "yeetube" nil command))))
+
+(defun yeetube-mpv (url)
+ "Start yeetube process to play URL using mpv."
+ (yeetube-process
+ (if yeetube-mpv-disable-video
+ (format "%s --no-video '%s'" (executable-find "mpv") url)
+ (format "%s '%s'" (executable-find "mpv") url)))
+ (message "yeetube: starting mpv process"))
+
+(defun yeetube-mpv-toggle-no-video-flag ()
+ "Toggle no video flag for mpv player."
+ (interactive)
+ (if yeetube-mpv-disable-video
+ (progn (setf yeetube-mpv-disable-video nil)
+ (message "yeetube: mpv removed no-video flag"))
+ (setf yeetube-mpv-disable-video t)
+ (message "yeetube: mpv added no-video flag")))
+
+(defun yeetube-mpv-send-keypress (key)
+ "Send KEY to yeetube-process."
+ (interactive "sKey: ")
+ (process-send-string "yeetube" key))
+
+(defun yeetube-mpv-toggle-pause ()
+ "Toggle pause mpv."
+ (interactive)
+ (yeetube-mpv-send-keypress "p")
+ (message "yeetube: toggle pause"))
+
+(defun yeetube-mpv-toggle-fullscreen ()
+ "Toggle fullscreen."
+ (interactive)
+ (yeetube-mpv-send-keypress "f")
+ (message "toggle fullscreen"))
+
+(defun yeetube-mpv-toggle-video ()
+ "Toggle video mpv."
+ (interactive)
+ (yeetube-mpv-send-keypress "_")
+ (message "yeetube: toggle video"))
+
+(provide 'yeetube-mpv)
+;;; yeetube-mpv.el ends here
diff --git a/yeetube.el b/yeetube.el
index 226f958..932bc26 100644
--- a/yeetube.el
+++ b/yeetube.el
@@ -4,9 +4,9 @@
;; Author: Thanos Apollo <[email protected]>
;; Keywords: extensions youtube videos invidious
-;; URL: https://git.sr.ht/~thanosapollo/yeetube.el
-;; Version: 1.5.0
-(defvar yeetube--version '2.0.0)
+;; URL: https://git.thanosapollo.com/yeetube
+;; Version: 2.0.1
+(defvar yeetube--version '2.0.1)
;; Package-Requires: ((emacs "27.2"))
@@ -28,19 +28,12 @@
;; This package provides the ability to scrape YouTube or any Invidious
;; instance, with the results displayed in a read-only org-mode buffer.
-;; Key features:
-;; - Search video query
-;; - Play video URL, by default with mpv
-;; - Save video URL with a custom name/label
-;; - Download video, this package serves also as a front-end for
-;; yt-dlp, thus supporting platforms beyond Youtube & Invidious.
-
;;; Code:
(require 'url)
(require 'org-element)
(require 'cl-lib)
-
+(require 'yeetube-mpv)
(defgroup yeetube nil
"Youtube & Invidious Front-end."
@@ -81,18 +74,12 @@ Example Usage:
:safe #'booleanp
:group 'yeetube)
-(defcustom yeetube-player 'mpv
+(defcustom yeetube-player 'yeetube-mpv
"Select video player."
:type 'symbol
:safe #'symbolp
:group 'yeetube)
-(defcustom yeetube-mpv-disable-video nil
- "Add no-video flag when using mpv."
- :type 'boolean
- :safe #'booleanp
- :group 'yeetube)
-
(defcustom yeetube-download-directory "~/Downloads"
"Default directory to downlaod videos."
:type 'string
@@ -149,24 +136,12 @@ Example Usage:
t
nil))
-(defun yeetube-play-url (url)
- "Open URL using yeetube-player."
- (let ((media-player (executable-find (symbol-name yeetube-player))))
- (unless media-player
- (error (format "%s not found." media-player)))
- (when (string-prefix-p "http" url)
- (setf yeetube-last-played url)
- (if (eq yeetube-player 'mpv)
- (yeetube-start-mpv-process url)
- (yeetube-start-process
- (format "%s '%s'" media-player url))))))
-
(defun yeetube-play ()
"Open the url at point in an `'org-mode buffer using ='yeetube-player'."
(interactive)
(let ((url (org-element-property
:raw-link (org-element-context))))
- (yeetube-play-url url)))
+ (funcall yeetube-player url)))
(defun yeetube-load-saved-videos ()
"Load saved videos."
@@ -210,58 +185,6 @@ Example Usage:
(when clear-saved
(setf yeetube-saved-videos nil))))
-(defun yeetube-start-process (command)
- "Start yeetube process for shell COMMAND."
- (let ((yeetube-process "yeetube"))
- (dolist (process (process-list))
- (when (string-match yeetube-process (process-name process))
- (kill-process process)))
- (sit-for 0.1)
- (unless (get-process yeetube-process)
- (start-process-shell-command
- "yeetube" nil command))))
-
-(defun yeetube-start-mpv-process (url)
- "Start yeetube process to play URL using mpv."
- (yeetube-start-process
- (if yeetube-mpv-disable-video
- (format "%s --no-video '%s'" (executable-find "mpv") url)
- (format "%s '%s'" (executable-find "mpv") url)))
- (message "yeetube: starting mpv process"))
-
-(defun yeetube-mpv-toggle-no-video-flag ()
- "Toggle no video flag for mpv player."
- (interactive)
- (if yeetube-mpv-disable-video
- (progn (setf yeetube-mpv-disable-video nil)
- (message "yeetube: mpv removed no-video flag"))
- (setf yeetube-mpv-disable-video t)
- (message "yeetube: mpv added no-video flag")))
-
-(defun yeetube-mpv-send-keypress (key)
- "Send KEY to yeetube-process."
- (interactive "sKey: ")
- (process-send-string "yeetube" key))
-
-(defun yeetube-mpv-toggle-pause ()
- "Toggle pause mpv."
- (interactive)
- (yeetube-mpv-send-keypress "p")
- (message "yeetube: toggle pause"))
-
-(defun yeetube-mpv-toggle-fullscreen ()
- "Toggle fullscreen."
- (interactive)
- (yeetube-mpv-send-keypress "f")
- (message "toggle fullscreen"))
-
-(defun yeetube-mpv-toggle-video ()
- "Toggle video mpv."
- (interactive)
- (yeetube-mpv-send-keypress "_")
- (message "yeetube: toggle video"))
-
-
;; Usually titles from youtube get messed up,
;; This should fix some of the common issues.
(defun yeetube-fix-title (title)