From 2ccf1b68376840d640f6620e102ab09632d3e7bb Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Mon, 19 Feb 2024 15:25:07 +0200 Subject: yeetube: Enable socks support - Add yeetube-with-tor-socks - Add yeetube-enable-tor option --- yeetube.el | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/yeetube.el b/yeetube.el index 118abdb..2deb503 100644 --- a/yeetube.el +++ b/yeetube.el @@ -41,6 +41,7 @@ (require 'url) (require 'tabulated-list) (require 'cl-lib) +(require 'socks) (require 'yeetube-mpv) (defgroup yeetube nil @@ -97,6 +98,11 @@ Valid options include: :type 'boolean :group 'yeetube) +(defcustom yeetube-enable-tor nil + "Enable routing through tor" + :type 'boolean + :group 'yeetube) + (defgroup yeetube-faces nil "Faces used by yeetube." :group 'yeetube @@ -296,19 +302,26 @@ This is used to download thumbnails from `yeetube-content', within "Get filter code for sorting search results." (cdr (assoc filter yeetube-filter-code-alist))) +(defmacro yeetube-with-tor-socks (&rest body) + `(let ((url-gateway-method 'socks) + (socks-noproxy '("localhost")) + (socks-server '("Default server" "127.0.0.1" 9050 5))) + ,@body)) + ;;;###autoload (defun yeetube-search (query) "Search for QUERY." (interactive "sYeetube Search: ") - (let ((url-request-extra-headers yeetube-request-headers)) + (let* ((url-request-extra-headers yeetube-request-headers) + (search-url (concat "https://youtube.com/search?q=" + (replace-regexp-in-string " " "+" query) + ;; Filter parameter to remove live videos. + "&sp=" + (yeetube-get-filter-code yeetube-filter)))) (with-current-buffer - (url-retrieve-synchronously - (concat "https://youtube.com/search?q=" - (replace-regexp-in-string " " "+" query) - ;; Filter parameter to remove live videos. - "&sp=" - (yeetube-get-filter-code yeetube-filter)) - 'silent 'inhibit-cookies 30) + (if yeetube-enable-tor + (yeetube-with-tor-socks (url-retrieve-synchronously search-url 'silent 'inhibit-cookies 30)) + (url-retrieve-synchronously search-url 'silent 'inhibit-cookies 30)) (decode-coding-region (point-min) (point-max) 'utf-8) (goto-char (point-min)) (toggle-enable-multibyte-characters) @@ -421,7 +434,8 @@ Optional values: (unless yeetube-ytdlp (error "Executable for yt-dlp not found. Please install yt-dlp")) (call-process-shell-command - (concat "yt-dlp " (shell-quote-argument url) + (concat (when yeetube-enable-tor "torsocks ") + "yt-dlp " (shell-quote-argument url) (when name " -o "(shell-quote-argument name)) (when audio-format -- cgit v1.2.3