4 ms·
I had someone try to tell me this or some similar alternative method once, but for this particular use-case my method seemed faster. Usually I'm viewing the dir
by opan 2y ago
I had someone try to tell me this or some similar alternative method once, but for this particular use-case my method seemed faster. Usually I'm viewing the dir with the file in ranger, hit r (shortcut for :open_with ), type mpv, enter, I in mpv for info, q to quit, a in ranger to rename the file with old name pretyped in. It's a pretty smooth workflow. Assuming I start from the same place in ranger I have to press colon and type `shell -w file %s` and hit enter which may or may not be faster but I think is more keystrokes. I could bind it to a key in ranger if I found an open one and then that might be better. It's sometimes weeks between instances of the mis-saved images or else I might've tried harder to optimize this. The shell script idea is neat.
- latexr 2y ago> The shell script idea is neat. Could be something as simple as: file_path="${1}" mime="$(file --mime-type --brief "${file_path}")" ext="${mime#image/}" mv "${file_path}" "${file_path%.*}.${ext}" That does no checks (e.g. is the file an image) and may not work on something on something like a video, but it’ll do for common image types such as png, jpeg, webp, heic, gif…
- amiga386 2y agoPersonally I use a shell script to do it automatically for me... with "file": #!/bin/bash # Usage: fix-extensions <media file(s)> # Renames the files to consistent file extensions based on content for file in "$@"; do [ -f "$file" ] || continue dir=$(dirname "$file") name=$(basename "$file") prefix="${name%.*}" ext="${name##*.}" magic=$(file -b "$file") newext="" case "$magic" in *"Apple QuickTime movie"*) newext=mov;; "ISO Media, Apple iTunes Video"*) newext=mp4;; "ISO Media, MP4"*) newext=mp4;; "ISO Media, MPEG-4 (.MP4)"*) newext=mp4;; "Macromedia Flash data"*) newext=swf;; "Macromedia Flash Video") newext=flv;; "Matroska data") newext=mkv;; "Microsoft ASF"*) newext=wmv;; "MPEG sequence"*) newext=mpeg;; "Ogg data, OGM video"*) newext=ogm;; "RealMedia file") newext=rm;; "RIFF "*" data, AVI,"*) newext=avi;; "WebM") newext=webm;; esac if [ -z "$newext" ]; then echo >&2 "$file: not renaming, unknown extension for type '$magic'" elif [ "$ext" != "$newext" ]; then mv -v "$file" "$dir/$prefix.$newext" fi done