Created
November 16, 2023 23:44
-
-
Save zardoz03/a5370b150a30a8d75d406a9180c66506 to your computer and use it in GitHub Desktop.
emacs-lisp ?si= strip script.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require 'url) | |
(require 'cl-lib) | |
(require 'seq) | |
;;^~~~~~~~~~~~~~^ comment if inadequate. | |
(let* ((url "https://youtu.be/dQw4w9WgXcQ?si=GoFuckYourself&t=420") ;; example url | |
(url-obj (url-generic-parse-url url)) | |
(url-ofs (copy-sequence (url-filename url-obj))) | |
;; url-old-filename-string, used after mutate | |
(si-idx (string-match "?si=.*" (url-filename url-obj))) | |
(t-idx (string-match "&t=.*" (url-filename url-obj)))) | |
(when si-idx | |
(setf (url-filename url-obj) | |
(seq-take (url-filename url-obj) si-idx))) | |
(when t-idx ;; keep and append if present | |
(setf (url-filename url-obj) | |
(cl-concatenate 'string | |
(url-filename url-obj) | |
(seq-drop url-ofs t-idx)))) | |
;; serialize. | |
(url-recreate-url url-obj)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment