MetaMove
MetaMove is written in Python3 and aims at easing batch renaming operations based on file meta data.
MetaMove abuses eval
combined with f-strings
. It's some sort of wrapper, that handles file operations and requires a Python3 format string generate new file names.
python3 metamove.py --type f --dry --name "test/**" "test1/{name}-{int(stat.st_mtime)}.{ext}"
Usage
usage: metamove.py [-h] [-R] [--type {f,d}] [--name NAME] [--dry] [--regex REGEX] pattern
positional arguments:
pattern destination directory with Python f-string for renaming operations, e.g. "test1/{name}-{int(stat.st_mtime)}.{ext}"
optional arguments:
-h, --help show this help message and exit
-R, --recursive Activating this switch will traverse recursively through subdirectories.
--type {f,d} "f" for file or "d" for directory, defaults to both
--name NAME glob that will match on files, similar to "find -name *.txt"
--dry do not actually do anything but showing the result
--regex REGEX regex to extract filename parts, can be accessed in the 'pattern' using the 'regex' array
Curly braces
You can use any expression that Python3 allows inside f-string curly braces
A few examples to get you started:
name
-- Filename without extensionext
-- File extension without leading dotmime
-- File mime type- stat information like
stat.st_atime
-- Last access datestat.st_mtime
-- Last modification datestat.st_ctime
-- Last inode modification date- and others: https://pathlib.readthedocs.io/en/0.5/#st-attrs
- IDv3 tags like
mp3.tag.artist
-- IDv3 artist tagmp3.tag.title
-- IDv3 title tagmp3.tag.album
-- IDv3 album tag- and many more: https://github.com/nicfit/eyeD3
- file name parts if
--regex
is set:regex[0]
-- first matchregex[1]
-- second match- and many more depending on your regex and number of matches
Examples
Dry move all files from folder test
to test1
and rename them accordingly.
python3 metamove.py --type f --dry --name "test/**" "test1/{name}-{int(stat.st_mtime)}.{ext}"
Result:
test/file_example_MP3_1MG.mp3 -> test1/file_example_MP3_1MG-1640635451.mp3
test/test1.txt -> test1/test1-1640635453.txt
test/test2.dir -> test1/test2-1640635456.dir
Dry move mp3 files from folder test
to test1
, sort them by mp3.tag.artist
into folders and use mp3.tag.title
as filename.
python3 metamove.py --type f --dry --name "**/*.mp3" "test1/{mp3.tag.artist}/{mp3.tag.title}.{ext}"
Result:
./metamove.py --type f --dry --name "**/*.mp3" "test1/{mp3.tag.artist}/{mp3.tag.title}.{ext}"
test/file_example_MP3_1MG.mp3 -> test1/Kevin MacLeod/Impact Moderato.mp3
Dry move files from test
to test1
and strip away the non-alphabetic characters from the filename.
python3 metamove.py --type f --dry --name "test/**" --regex "[A-Za-z]*" "test1/{regex[0]}.{ext}"
Result:
test/file_example_MP3_1MG.mp3 -> test1/file.mp3
test/test1.txt -> test1/test.txt
test/test2.dir -> test1/test.dir
What works
- Globbing the files was kinda hard to figure out and may not be perfect.
- Renaming mp3 files based on IDv3 meta data works.
- Renaming other files based on stat meta data is also fine.
- Using regex expressions to access parts of the filename.
- Dry runs also work and are recommended before actually performing the action.
Wishlist
- Plugins (e.g. exif, geographics, time formatting)
Try it out
Dependencies can be installed via
pip install -r requirements.txt
or
make init