From ad8581ed73d09dac341be5fba7e826bc949f97dc Mon Sep 17 00:00:00 2001 From: JSDurand Date: Mon, 10 Jan 2022 23:51:08 +0800 Subject: 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. --- view-conf.el | 37 ++++++++++++++++++++++--------------- 1 file 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 -- cgit v1.2.3-18-g5258