diff options
Diffstat (limited to 'emacs/.emacs.d/lisp')
-rw-r--r-- | emacs/.emacs.d/lisp/my/my-dired.el | 38 | ||||
-rw-r--r-- | emacs/.emacs.d/lisp/my/my-ytdl.el | 14 |
2 files changed, 48 insertions, 4 deletions
diff --git a/emacs/.emacs.d/lisp/my/my-dired.el b/emacs/.emacs.d/lisp/my/my-dired.el index c90b8c4..ee6f7b0 100644 --- a/emacs/.emacs.d/lisp/my/my-dired.el +++ b/emacs/.emacs.d/lisp/my/my-dired.el @@ -151,5 +151,43 @@ With a prefix-arg, call it without using `vc-rename-file'." (advice-add 'dired-next-line :after #'my-dired-display-file) (advice-remove 'dired-next-line #'my-dired-display-file))) +(defun my-dired-rename-by-mtime-at-point () + "Generates new file name based on mtime. + +Format: yyyymmdd_hhmmss.ext" + (interactive) + (my-dired-rename-by-mtime (expand-file-name (dired-file-name-at-point)))) + +(defun my-dired-rename-by-mtime (file-name) + "Generates new file name based on mtime. + +Format: yyyymmdd_hhmmss[_N].ext" + (let* ((ext (file-name-extension file-name)) + (dir (file-name-directory file-name)) + (new-file-name-base + (file-name-concat + dir + (concat + (format-time-string + "%Y%m%d_%H%M%S" + (file-attribute-modification-time (file-attributes file-name)))))) + (new-file-name + (format "%s.%s" new-file-name-base ext)) + (counter 0)) + (unless (equal file-name new-file-name) + (while (file-exists-p new-file-name) + (setq counter (1+ counter) + new-file-name (format "%s_%d" new-file-name-base counter))) + (dired-rename-file file-name new-file-name nil)))) + +(defun my-dired-do-rename-by-mtime () + "Generates new file name based on mtime. + +Format: yyyymmdd_hhmmss.ext" + (interactive) + (seq-do + 'my-dired-rename-by-mtime + (dired-map-over-marks (dired-get-filename) nil))) + (provide 'my-dired) ;;; my-dired.el ends here diff --git a/emacs/.emacs.d/lisp/my/my-ytdl.el b/emacs/.emacs.d/lisp/my/my-ytdl.el index e902722..721b299 100644 --- a/emacs/.emacs.d/lisp/my/my-ytdl.el +++ b/emacs/.emacs.d/lisp/my/my-ytdl.el @@ -65,13 +65,13 @@ (defvar my-ytdl-audio-download-dir "~/Downloads" "Directory for ytdl to download audios to.") -(defun my-ytdl-internal (urls type &optional cut-segments) +(defun my-ytdl-internal (urls type &optional no-tor) (my-with-default-directory (if (eq type 'video) - my-ytdl-video-download-dir - my-ytdl-audio-download-dir) + my-ytdl-video-download-dir + my-ytdl-audio-download-dir) (apply 'my-start-process-with-torsocks (append - (list nil (format "ytdl-%s" urls) (format "*ytdl-%s*" urls) + (list no-tor (format "ytdl-%s" urls) (format "*ytdl-%s*" urls) my-ytdl-program) (if (eq type 'video) my-ytdl-video-args my-ytdl-audio-args) (split-string urls))))) @@ -87,5 +87,11 @@ (interactive "sURL(s): ") (my-ytdl-internal urls 'audio)) +;;; fixme: autoload +(defun my-ytdl-video-no-tor (urls) + "Download videos with ytdl." + (interactive "sURL(s): ") + (my-ytdl-internal urls 'video t)) + (provide 'my-ytdl) ;;; my-ytdl.el ends here |