From f5844d701826809827563fdd33d3de8ebeb650dc Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Thu, 25 Jan 2024 07:35:09 +0200 Subject: emacs: Move dired & yeetube custom func to commands module --- .emacs.d/modules/thanos-commands.el | 88 +++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) (limited to '.emacs.d/modules') diff --git a/.emacs.d/modules/thanos-commands.el b/.emacs.d/modules/thanos-commands.el index da5b4ae..7dba0c7 100644 --- a/.emacs.d/modules/thanos-commands.el +++ b/.emacs.d/modules/thanos-commands.el @@ -145,5 +145,93 @@ (define-key global-map (kbd "C-c a") thanos/applications-map) +(defun dired-watch-video () + "Watch play file with mpv." + (interactive) + (call-process-shell-command + (format "mpv \"%s\"" (dired-get-filename)) nil 0)) + +(defun dired-set-wallpaper () + "Set NAME as wallpaper using feh." + (interactive) + (call-process-shell-command + (format "feh --bg-scale %s" (dired-get-filename)) nil 0)) + +(defun dired-delete-files-except () + "Delete all files inside directory except match." + (interactive) + (let* ((directory (read-directory-name "Select directory: ")) + (files (directory-files directory t)) + (except-match (read-string "Except the ones that have: "))) + (dolist (file files) + (unless (or (string= "." (substring file -1)) + (string= ".." (substring file -2)) + (string-match except-match file)) + (dired-delete-file file t))))) + +(defun dired-delete-file-match () + "Delete all files inside directory except match." + (interactive) + (let* ((directory (read-directory-name "Select directory: ")) + (files (directory-files directory t)) + (match (read-string "Delete files that match: "))) + (dolist (file files) + (when (string-match-p match file) + (dired-delete-file file t))))) + +(defun dired-rename-capitalize-file () + "Capitalize the base name of the file at point in a Dired buffer." + (interactive) + (let* ((file (dired-get-file-for-visit)) + (new-file (capitalize (file-name-nondirectory file)))) + (if (string-prefix-p "." file) + (message "Skipping file starting with '.'") + (progn + (rename-file file (concat (file-name-directory file) new-file)) + (revert-buffer) + (message "Renamed %s to %s" file new-file))))) + +;; yeetube +(defun yeetube-download-videos-ffmpeg () + "Download videos using ffmpeg." + (interactive) + (let ((url "") + (name "") + (download-counter 1) + (stored-contents nil)) + ;; Read links and names until "q" is entered + (while (not (string= url "q")) + (setf url (read-string "Enter URL (q to quit): ")) + (unless (string= url "q") + (setf name (read-string (format "Custom name (download counter: %d) " download-counter))) + (push (cons url name) stored-contents) + (setf download-counter (1+ download-counter)))) + ;; Process the collected links and names + (dolist (pair stored-contents) + (let ((url (car pair)) + (name (cdr pair))) + (async-shell-command + (format + "ffmpeg -protocol_whitelist file,crypto,data,https,tls,tcp -stats -i '%s' -codec copy '%s.mp4'" + url name)))))) + +(defun yeetube-download-vimeo-videos () + "Download videos from vimeo services." + (interactive) + (let ((url "") + (name "") + (download-counter 1)) + (while (not (string= url "q")) + (setf url (read-string "Enter URL (q to quit): ")) + (unless (string= url "q") + (setf name (read-string (format "Custom name (download counter: %d) " download-counter))) + (setf download-counter (1+ download-counter)) + (call-process-shell-command + (format + "yt-dlp '%s' -o '%s'" + (replace-regexp-in-string "\\.json" ".m3u8" url) name) + nil 0))))) + + (provide 'thanos-commands) ;;; thanos-commands.el ends here -- cgit v1.2.3