history script --format option not working

Running FileBot from the console, Groovy scripting, shell scripts, etc
Post Reply
cheaters
Posts: 214
Joined: 09 Oct 2016, 02:01

history script --format option not working

Post 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?
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: How about sharing your CLI scripts?

Post 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


:idea: 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
:arrow: https://stackoverflow.com/a/28806991/1514467
:idea: Please read the FAQ and How to Request Help.
cheaters
Posts: 214
Joined: 09 Oct 2016, 02:01

Re: history script --format option not working

Post 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
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: history script --format option not working

Post by rednoah »

xargs -0 -n1 basename does indeed execute basename for each file path. Spawning a new process is indeed slow.


:arrow: 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
:idea: Please read the FAQ and How to Request Help.
Post Reply