Page 1 of 1
history script --format option not working
Posted: 01 Apr 2021, 19:33
by cheaters
rednoah wrote: ↑13 Nov 2012, 12:41
Description:
FileBot keeps an internal history of all rename operations in case you want to revert files to their original names or just want to find out the original name of a given file. Here's a script to help with that.
Print old and new names in rows for easy comparison:
Code: Select all
filebot -script fn:history --format '${from.name}\n${to.name}\n'
Options:
--format specify your own line format
I realize this was from ten years ago...
I tried this on macOS and it fails to create new lines in output. It seems to use tabs instead of new lines.
I am wondering if it's related to how
sed has trouble replacing a space with a newline?
I can use:
Code: Select all
$ filebot -script fn:history --format '${from.name}\t${to.name}\t' | grep -v "\.srt" > history.txt
$ tr "\t" "\n" </Users/john/history.txt >/Users/john/historytemp.txt && mv /Users/john/historytemp.txt /Users/john/history.txt
$ cat "history.txt" | sed 's!.*/!!'
The.Greatest.Show.on.Earth.1952.1080p.BluRay.x265-RARBG.mp4
The Greatest Show on Earth (1952) {imdb-tt0044672} [[en] 1.370 WS 1080p BluRay x265 493BF762].mp4
But that seems overly complicated...

I would really like to get the names of
from and
to without the base paths for both. Can FileBot do this?
Re: How about sharing your CLI scripts?
Posted: 02 Apr 2021, 02:20
by rednoah
Looks like the history script no longer supports the
--format option:
https://github.com/filebot/scripts/blob ... ory.groovy
I'll update the docs accordingly:
viewtopic.php?p=2459#p2459

You can fork the script if you want to customize the line format.
EDIT:
Alternatively, you can parse the default output and print the basename for each file path:
Code: Select all
filebot -script fn:history | tr '\t\n' '\0' | xargs -0 -n1 basename
https://stackoverflow.com/a/28806991/1514467
Re: history script --format option not working
Posted: 02 Apr 2021, 17:31
by cheaters
Thank you.
That takes a long time to run with 34,000 lines of history. I don't think
basename is meant to be run that way?
Code: Select all
real 0m22.386s
user 0m11.157s
sys 0m14.146s
The following gets me what I want in a readable format. (On macOS it requires GNU
sed/
gsed). I am open to a better/faster/simpler way.

I was trying to figure out how to run all command before output to a file but ran into issues I couldn't resolve, so I output to a file first then run
sed on the file.
Code: Select all
$ time filebot -script fn:history | grep -v "\.srt" | tr "\t" "\n" > ./history.txt && gsed -i 's!.*/!!;0~2G' ./history.txt
...
The.Greatest.Show.on.Earth.1952.1080p.BluRay.x265-RARBG.mp4
The Greatest Show on Earth (1952) {imdb-tt0044672} [[en] 1.370 WS 1080p BluRay x265 493BF762].mp4
...
real 0m1.680s
user 0m5.952s
sys 0m0.456s
Re: history script --format option not working
Posted: 03 Apr 2021, 03:03
by rednoah
xargs -0 -n1 basename does indeed execute
basename for each file path. Spawning a new process is indeed slow.

You can mitigate the problem by calling
basename a small number times with a large number of arguments each time:
Code: Select all
filebot -script fn:history | tr '\t\n' '\0' | xargs -0 -n1000 basename -a