diff options
Diffstat (limited to 'emacs/.emacs.d')
-rw-r--r-- | emacs/.emacs.d/lisp/my/emms-info-ytdl.el | 12 | ||||
-rw-r--r-- | emacs/.emacs.d/lisp/my/my-libgen.el | 4 | ||||
-rw-r--r-- | emacs/.emacs.d/lisp/my/my-org.el | 1 | ||||
-rw-r--r-- | emacs/.emacs.d/lisp/my/my-utils.el | 11 | ||||
-rw-r--r-- | emacs/.emacs.d/lisp/my/my-wget.el | 18 | ||||
-rw-r--r-- | emacs/.emacs.d/lisp/my/my-ytdl.el | 1 | ||||
-rw-r--r-- | emacs/.emacs.d/lisp/my/tor.el | 57 |
7 files changed, 84 insertions, 20 deletions
diff --git a/emacs/.emacs.d/lisp/my/emms-info-ytdl.el b/emacs/.emacs.d/lisp/my/emms-info-ytdl.el index 489f3fb..0c7a1d2 100644 --- a/emacs/.emacs.d/lisp/my/emms-info-ytdl.el +++ b/emacs/.emacs.d/lisp/my/emms-info-ytdl.el @@ -31,7 +31,7 @@ (require 'emms-info) (require 'json) - +(require 'tor) (defgroup emms-info-ytdl nil "Options for EMMS." @@ -70,12 +70,10 @@ (with-temp-buffer (when (zerop (let ((coding-system-for-read 'utf-8)) - (if emms-info-ytdl-using-torsocks - (my-call-process-with-torsocks - emms-info-ytdl-command nil '(t nil) nil "-j" - (emms-track-name track)) - (call-process emms-info-ytdl-command nil '(t nil) nil - "-j" (emms-track-name track))))) + (my-call-process-with-torsocks + (not emms-info-ytdl-using-torsocks) + emms-info-ytdl-command nil '(t nil) nil "-j" + (emms-track-name track)))) (goto-char (point-min)) (condition-case nil (let ((json-fields (json-read))) diff --git a/emacs/.emacs.d/lisp/my/my-libgen.el b/emacs/.emacs.d/lisp/my/my-libgen.el index 5b84120..912f2df 100644 --- a/emacs/.emacs.d/lisp/my/my-libgen.el +++ b/emacs/.emacs.d/lisp/my/my-libgen.el @@ -188,7 +188,7 @@ my-libgen-plus-host (dom-attr (dom-search - (my-url-fetch-dom (alist-get 'ads (my-libgen-plus-urls info))) + (my-wget-dom (alist-get 'ads (my-libgen-plus-urls info))) (lambda (n) (string-match (format "get\\.php\\?md5=%s" .md5) (or (dom-attr n 'href) "")))) @@ -203,7 +203,7 @@ (my-wget-async (my-libgen-plus-get-download-url info) filename - t + nil (lambda () (my-libgen-check-md5 filename md5))))) (defun my-libgen-plus-urls (info) diff --git a/emacs/.emacs.d/lisp/my/my-org.el b/emacs/.emacs.d/lisp/my/my-org.el index e628c5b..dfddf07 100644 --- a/emacs/.emacs.d/lisp/my/my-org.el +++ b/emacs/.emacs.d/lisp/my/my-org.el @@ -28,6 +28,7 @@ (require 'org) +(require 'tor) ;;; org mode (defun my-org-open-shell-at-attach-dir () diff --git a/emacs/.emacs.d/lisp/my/my-utils.el b/emacs/.emacs.d/lisp/my/my-utils.el index ff65420..98c8caa 100644 --- a/emacs/.emacs.d/lisp/my/my-utils.el +++ b/emacs/.emacs.d/lisp/my/my-utils.el @@ -312,17 +312,6 @@ Example: (format-time-string ... (my-time-from-epoch 1698582504))" (apply 'call-process (append (list command nil t nil) args)) (buffer-string))) -(defun my-call-process-with-torsocks - (program &optional infile destination display &rest args) - (apply 'call-process - (append (list "torsocks" infile destination display program) args))) - -(defun my-start-process-with-torsocks (no-tor name buffer program &rest program-args) - (if no-tor - (apply 'start-process (append (list name buffer program) program-args)) - (apply 'start-process - (append (list name buffer "torsocks" program) program-args)))) - (defun my-touch-new-file (filename) "Touch a new file." (with-temp-buffer (write-file filename))) diff --git a/emacs/.emacs.d/lisp/my/my-wget.el b/emacs/.emacs.d/lisp/my/my-wget.el index a55bb12..f3f6771 100644 --- a/emacs/.emacs.d/lisp/my/my-wget.el +++ b/emacs/.emacs.d/lisp/my/my-wget.el @@ -30,6 +30,7 @@ ;; wget (require 'wget) (require 'my-utils) +(require 'tor) (defvar my-wget-video-archive-directory) ;; FIXME: this list is rather random... (setq my-wget-video-extensions '("mp4" "flv" "mkv" "webm" "ogv" "avi" @@ -85,5 +86,22 @@ no-tor move-if-video-or-large) (setq i (1+ i))))) +(defun my-wget-out-internal (url buffer-processor &optional no-tor) + "Run wget on url, dump the results in a temp buffer, then apply BUFFER-PROCESSOR" + (with-temp-buffer + (my-call-process-with-torsocks no-tor "wget" nil '(t nil) nil "-O" "-" url) + (call-interactively 'delete-trailing-whitespace) + (funcall buffer-processor) + )) + +(defun my-wget-dom (url &optional no-tor) + (my-wget-out-internal + url + (lambda () (libxml-parse-html-region (point-min) (point-max))) + no-tor)) + +(defun my-wget-raw (url &optional no-tor) + (my-wget-out-internal url 'buffer-string no-tor)) + (provide 'my-wget) ;;; my-wget.el ends here diff --git a/emacs/.emacs.d/lisp/my/my-ytdl.el b/emacs/.emacs.d/lisp/my/my-ytdl.el index b04b2a9..26700fd 100644 --- a/emacs/.emacs.d/lisp/my/my-ytdl.el +++ b/emacs/.emacs.d/lisp/my/my-ytdl.el @@ -26,6 +26,7 @@ ;;; Code: +(require 'tor) (defvar my-ytdl-program "yt-dlp") diff --git a/emacs/.emacs.d/lisp/my/tor.el b/emacs/.emacs.d/lisp/my/tor.el new file mode 100644 index 0000000..9ed7d5f --- /dev/null +++ b/emacs/.emacs.d/lisp/my/tor.el @@ -0,0 +1,57 @@ +;;; tor.el -- tor utilities -*- lexical-binding: t -*- + +;; Copyright (C) 2025 Free Software Foundation, Inc. + +;; Author: Yuchen Pei <id@ypei.org> +;; Package-Requires: ((emacs "30.1")) + +;; This file is part of dotted. + +;; dotted is free software: you can redistribute it and/or modify it under +;; the terms of the GNU Affero General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; dotted is distributed in the hope that it will be useful, but WITHOUT +;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General +;; Public License for more details. + +;; You should have received a copy of the GNU Affero General Public +;; License along with dotted. If not, see <https://www.gnu.org/licenses/>. + +;;; Commentary: + +;; tor utilities. + +;;; Code: + + +(defun my-call-process-with-torsocks (no-tor program + &optional infile destination display + &rest args) + (if no-tor + (apply 'call-process + (append (list program infile destination display) args)) + (apply 'call-process + (append (list "torsocks" infile destination display program) args)))) + +(defun my-start-process-with-torsocks (no-tor name buffer program + &rest program-args) + (if no-tor + (apply 'start-process (append (list name buffer program) program-args)) + (apply 'start-process + (append (list name buffer "torsocks" program) program-args)))) + +(defun tor-parse-check-dom (dom) + (let ((content (dom-by-class dom "content"))) + (format "%s\n%s" + (string-trim (dom-text (dom-by-tag content 'h1))) + (string-trim (dom-texts (car (dom-by-tag content 'p))))))) + +(defun tor-check (&optional no-tor) + (require 'my-wget) + (tor-parse-check-dom (my-wget-dom "https://check.torproject.org/" no-tor))) + +(provide 'tor) +;;; tor.el ends here |