From 093ffa5fbf7143f4668bb0a3dc9659a5cc836e12 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Sat, 17 Jun 2023 17:20:29 +1000 Subject: Moving things one level deeper To ease gnu stow usage. Now we can do stow -t ~ emacs --- emacs/.emacs.d/lisp/my/my-wget.el | 79 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 emacs/.emacs.d/lisp/my/my-wget.el (limited to 'emacs/.emacs.d/lisp/my/my-wget.el') diff --git a/emacs/.emacs.d/lisp/my/my-wget.el b/emacs/.emacs.d/lisp/my/my-wget.el new file mode 100644 index 0000000..5349257 --- /dev/null +++ b/emacs/.emacs.d/lisp/my/my-wget.el @@ -0,0 +1,79 @@ +;;; my-wget.el -- Extensions for emacs-wget -*- lexical-binding: t -*- + +;; Copyright (C) 2023 Free Software Foundation. + +;; Author: Yuchen Pei +;; Package-Requires: ((emacs "28.2")) + +;; This file is part of dotfiles. + +;; dotfiles 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. + +;; dotfiles 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 dotfiles. If not, see . + +;;; Commentary: + +;; Extensions for emacs-wget. + +;;; Code: + + +;; wget +(require 'wget) +(require 'my-utils) +(defvar my-wget-video-archive-directory) +;; FIXME: this list is rather random... +(setq my-wget-video-extensions '("mp4" "flv" "mkv" "webm" "ogv" "avi" + "rmvb")) +(defun my-wget-ensure-buffer-exists () + (get-buffer-create (or wget-process-buffer " *wget*"))) +(defun my-eww-wget-save-page () + (interactive) + (my-wget-ensure-buffer-exists) + (let* ((filename + (concat (my-make-filename (plist-get eww-data :title)) ".html")) + (full-path (concat wget-download-directory "/" filename))) + (wget-uri (plist-get eww-data :url) + wget-download-directory + (list (concat "-O" filename))) + (kill-new full-path) + (message "Saved webpage to %s (path copied)." full-path))) + +(defun my-wget-async (url filename &optional no-tor move-if-video-or-large) + (set-process-sentinel + (my-start-process-with-torsocks + no-tor "wget" "*wget*" "wget" url "-c" "-O" filename) + (lambda (_process _event) + (when (and move-if-video-or-large + (or + (> (file-attribute-size (file-attributes filename)) + my-wget-size-threshold) + (member (file-name-extension filename) my-wget-video-extensions))) + (setq filename + (my-rename-and-symlink-back + filename (expand-file-name my-wget-video-archive-directory) nil))) + (message "Fetched %s and saved to: %s" url filename)))) + +(defun wget-async-urls-with-prefix (urls prefix &optional no-tor move-if-video-or-large) + (let ((i 1)) + (dolist (url urls) + (my-wget-async + url + (concat prefix + (make-string (- 4 (length (number-to-string i))) ?0) + (number-to-string i) + "." (file-name-extension url)) + no-tor move-if-video-or-large) + (setq i (1+ i))))) + +(provide 'my-wget) +;;; my-wget.el ends here -- cgit v1.2.3