summaryrefslogtreecommitdiff
path: root/view-conf.el
diff options
context:
space:
mode:
authorJSDurand <mmemmew@gmail.com>2022-01-10 23:51:08 +0800
committerJSDurand <mmemmew@gmail.com>2022-01-10 23:51:08 +0800
commitad8581ed73d09dac341be5fba7e826bc949f97dc (patch)
tree209d9a7154163cbbd8e03fd53c100f036fe46609 /view-conf.el
parentff35414422cf03e321b3302b414eb3f45ec659d5 (diff)
view-conf: fix the function to convert youtube video to URL.
This change is necessary as yt-dlp uses a different format for the output files than youtube-dl.
Diffstat (limited to 'view-conf.el')
-rw-r--r--view-conf.el37
1 files changed, 22 insertions, 15 deletions
diff --git a/view-conf.el b/view-conf.el
index 69f52a5..5e6b5aa 100644
--- a/view-conf.el
+++ b/view-conf.el
@@ -236,21 +236,28 @@ options to choose from."
(defun durand-convert-youtube-video-to-url (video-name)
"Convert VIDEO-NAME to its original url."
(interactive (list (read-string "Video name: ")))
- (cond
- ((string-match "\\.[^.]+$" video-name)
- ;; with extension
- (kill-new
- (concat
- "https://www.youtube.com/watch?v="
- (substring-no-properties
- video-name
- (- (match-beginning 0) 11)
- (match-beginning 0)))))
- (t
- ;; no extension
- (kill-new
- (concat "https://www.youtube.com/watch?v="
- (substring-no-properties video-name -11))))))
+ (save-match-data
+ (cond
+ ((string-match (rx "[" (group (1+ (not "]"))) "].")
+ video-name)
+ (kill-new
+ (concat
+ "https://www.youtube.com/watch?v="
+ (match-string 1 video-name))))
+ ((string-match "\\.[^.]+$" video-name)
+ ;; with extension
+ (kill-new
+ (concat
+ "https://www.youtube.com/watch?v="
+ (substring-no-properties
+ video-name
+ (- (match-beginning 0) 11)
+ (match-beginning 0)))))
+ (t
+ ;; no extension
+ (kill-new
+ (concat "https://www.youtube.com/watch?v="
+ (substring-no-properties video-name -11)))))))
;;; moving by paragraphs