summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThanos Apollo <[email protected]>2023-07-06 18:51:01 +0300
committerThanos Apollo <[email protected]>2023-07-06 18:51:01 +0300
commit61a1b9449cd5c9832f2eb939c131e4bc21c33562 (patch)
tree2611767ab22800a4e69f0007b1d4baa744349778
parent37c61f5b6b6c7ed459e649bb53ffcad94b10e298 (diff)
Add error handlers
yeetube-toggle functions: - Throw error to have mpv installed and set it to the default value if not already done so - toggle-video just checks if it's not nil(meaning it's installed assuming user has not changed default value), making it easier to reset it yeetube-search - Throw condition errors if user has set yeetube-search-limits too high.
-rw-r--r--yeetube.el30
1 files changed, 21 insertions, 9 deletions
diff --git a/yeetube.el b/yeetube.el
index 4a5c413..92c7e7c 100644
--- a/yeetube.el
+++ b/yeetube.el
@@ -131,17 +131,23 @@ It's recommended you keep it as the default value."
(defun yeetube-toggle-video-mpv ()
"Toggle video on/off for mpv player."
(interactive)
- (when yeetube-player
- (setq yeetube-player
- (if (equal yeetube-player "mpv --input-ipc-server=/tmp/mpvsocket")
- "mpv --no-video --input-ipc-server=/tmp/mpvsocket"
- "mpv --input-ipc-server=/tmp/mpvsocket"))))
+ (if yeetube-player
+ (setq yeetube-player
+ (if (equal yeetube-player "mpv --input-ipc-server=/tmp/mpvsocket")
+ "mpv --no-video --input-ipc-server=/tmp/mpvsocket"
+ "mpv --input-ipc-server=/tmp/mpvsocket"))
+ (error "To use this function you need to have mpv installed and & set yeetube-player to the default value")))
(defun yeetube-toggle-pause-mpv ()
"Play/Pause mpv."
(interactive)
- (when yeetube-player
- (shell-command "echo '{ \"command\": [\"cycle\", \"pause\"] }' | socat - /tmp/mpvsocket")))
+ (if
+ (or (equal yeetube-player "mpv --input-ipc-server=/tmp/mpvsocket")
+ (equal yeetube-player "mpv --no-video --input-ipc-server=/tmp/mpvsocket"))
+ (progn
+ (shell-command "echo '{ \"command\": [\"cycle\", \"pause\"] }' | socat - /tmp/mpvsocket")
+ (message "mpv play/pause"))
+ (error "To use this function you need to have mpv installed & set yeetube-player to the default value")))
;; we should use something like
;; (decode-coding-region (point-min) (point-max) 'utf-8
@@ -186,9 +192,15 @@ PREFIX [[URL/watch?v=VIDEOID][VIDEOTITLE ]]"
(goto-char (point-min))
(toggle-enable-multibyte-characters)
(while (< (length video-ids) yeetube-results-limit)
- (if is-youtube?
+ (condition-case err
+ (if is-youtube?
(search-forward "videoId")
- (search-forward "watch?v"))
+ (search-forward "watch?v"))
+ (error
+ (display-warning 'yeetube
+ (format
+ "Unable to find enough results, reduce yeetube-results-limit (%s)"
+ (error-message-string err)))))
(let* ((start (point))
(end (if is-youtube?
(search-forward ",")