Show HN: MetaMove – Batch renaming operations based on file metadata

51
Show HN: MetaMove – Batch renaming operations based on file metadata

MetaMove is written in Python3 and targets at easing batch renaming operations in step with file meta knowledge.

MetaMove abuses eval blended with f-strings. It be some form of wrapper, that handles file operations and requires a Python3 format string generate recent file names.

python3 metamove.py --form f --dry --title "take a look at/" "test1/{title}-{int(stat.st_mtime)}.{ext}"
utilization: metamove.py [-h] [-R] [--type {f,d}] [--name NAME] [--dry] [--regex REGEX] sample

positional arguments:
  sample          destination directory with Python f-string for renaming operations, e.g. "test1/{title}-{int(stat.st_mtime)}.{ext}"

optional arguments:
  -h, --reduction       inform this reduction message and exit
  -R, --recursive  Activating this switch will traverse recursively by subdirectories.
  --form {f,d}     "f" for file or "d" for directory, defaults to both
  --title NAME      glob that will match on recordsdata, an equivalent to "salvage -title *.txt"
  --dry            develop no longer truly develop the rest however showing the tip outcome
  --regex REGEX    regex to extract filename parts, would possibly possibly also impartial also be accessed within the 'sample' using the 'regex' array

Curly braces

That that you just would possibly consume any expression that Python3 allows internal f-string curly braces

A number of examples to receive you started:

  • title — Filename with out extension
  • ext — File extension with out main dot
  • mime — File mime form
  • stat knowledge take care of
  • IDv3 tags take care of
    • mp3.ticket.artist — IDv3 artist ticket
    • mp3.ticket.title — IDv3 title ticket
    • mp3.ticket.album — IDv3 album ticket
    • and a whole lot of more: https://github.com/nicfit/eyeD3
  • file title parts if --regex is receive 22 situation:
    • regex[0] — first match
    • regex[1] — 2d match
    • and a whole lot of more depending for your regex and different of fits

Examples

Dry dash all recordsdata from folder take a look at to test1 and rename them accordingly.

python3 metamove.py --form f --dry --title "take a look at/" "test1/{title}-{int(stat.st_mtime)}.{ext}"

End result:

Dry dash mp3 recordsdata from folder take a look at to test1, form them by mp3.ticket.artist into folders and consume mp3.ticket.title as filename.
python3 metamove.py --form f --dry --title "/*.mp3" "test1/{mp3.ticket.artist}/{mp3.ticket.title}.{ext}"

End result:

test1/Kevin MacLeod/Impact Moderato.mp3″>
./metamove.py --form f --dry --title "/*.mp3" "test1/{mp3.ticket.artist}/{mp3.ticket.title}.{ext}"
take a look at/file_example_MP3_1MG.mp3 -> test1/Kevin MacLeod/Impact Moderato.mp3

Dry dash recordsdata from take a look at to test1 and strip away the non-alphabetic characters from the filename.

python3 metamove.py --form f --dry --title "take a look at/" --regex "[A-Za-z]*" "test1/{regex[0]}.{ext}"

End result:

  • Globbing the recordsdata turned into as soon as kinda laborious to resolve out and would possibly possibly impartial no longer be ideal.
  • Renaming mp3 recordsdata in step with IDv3 meta knowledge works.
  • Renaming a whole lot of recordsdata in step with stat meta knowledge is furthermore honest.
  • The utilization of regex expressions to receive entry to parts of the filename.
  • Dry runs furthermore work and are advised earlier than truly
  • Join the pack! Join 8000+ others registered customers, and receive chat, develop groups, submit updates and develop chums in each place in the area!
    www.knowasiak.com/register

    Ava Chan
    WRITTEN BY

    Ava Chan

    I'm a researcher at Utokyo :) and a big fan of Ava Max