Page 1 of 1

Re: Revert Renamed Files to their Original Names

Posted: 30 Mar 2014, 15:09
by s3frank
Hi there,
I use Filebot on a Mac and I am very happy with the tool. Amazing to be honest.
I run it after nzbget is finished downloading stuff, invoked from simple bash shell script.
But I am struggling to capture the new destination folder and I was wondering if there is an easy way to simply call filebot so that it returns nothing but the full path to the last rename action it did of movie file?

I have been trying the history and revert commands (in test mode) but cannot get it to return my last action or any for that matter.

Thanks,

-FF

rednoah wrote:Description:
FileBot keeps an internal history of all rename operations in case you want to revert files to their original names. Run this script on the specified file or folder and revert all files to their original names.

Revert files to their original paths:

Code: Select all

filebot -script fn:revert path/to/files
Options:
--action define revert operation, e.g. --action move (default) will move files back to their original location whereas --action rename will only change the filename back to the original filename but keep the file in it's current folder. You can run the script in test mode via --action test.

Download Script:
http://filebot.net/scripts/revert.groovy

Re: Re: Revert Renamed Files to their Original Names

Posted: 30 Mar 2014, 17:34
by rednoah
Not sure how you're calling filebot but why can't you just grep the information from the console log? It contains all the input/output paths.

When using fn:history you can avoid using grep by passing in your own output format:

Code: Select all

filebot -script fn:history --format '$to' --log off
1 line 1 path, easy to parse

Re: Re: Revert Renamed Files to their Original Names

Posted: 31 Mar 2014, 05:48
by s3frank
I am not a super scripter in bash but I am familiar with grep. I actually had that working for a while but when I upgraded from v3.4 to v4.0 the output format changed and it broke my script. This is the reasons I am trying a more reliable method so that my scripts can work longer without having to verify with updates.

So ideally I don't catch and parse the log at all, I would simply call the history script with a parameter that will only return the most recent entry in the database. As I only process files sequentially on my system this will always work correctly.

Here's how I call filebot today:
filebot -no-xattr -script fn:amc --output $SYNOPATH --action move --conflict override -non-strict --def music=n subtitles=en,nl backdrops=y artwork=y "$FMT_SERIES" "$FMT_MOVIES" "$FMT_MUSIC" $NZBPP_DIRECTORY

Thanks

Re: Re: Revert Renamed Files to their Original Names

Posted: 31 Mar 2014, 06:09
by rednoah
Yep, the script above will show you all rename history in sequential order, the last line will be the last file renamed. The only problem you have is that if in the last batch multiple files have been renamed in the last call then fn:history output can't tell you which files belong to which rename batch.

Alternatively you could read the data you need directly from ~/.filebot/history.xml

Re: Re: Revert Renamed Files to their Original Names

Posted: 01 Apr 2014, 16:37
by s3frank
yeah as you can see I do have that problem due to the subtitle downloads taking place as well. However, if I look in the list those are always following the actual movie / series entry so I could basically run the history query and search for the directory match. That would return 3 matches at most and 1 at a minimum. I basically always grab the first line then and things should be sweet then.

Now my final question is how to do I tell the history query to only return matching records based on the original directory path which I have in my script in a variable?

Sorry if this is silly question, like I said my bash isn't the best in the world and I've been hitting my head and google for example on how to pass the history query a directory as a param.

thanks so much for your help!

-FF

Re: Re: Revert Renamed Files to their Original Names

Posted: 01 Apr 2014, 21:33
by rednoah
The history script can either give you all history, or history for a given folder (that's destination, not source).

You can use grep and sed:
http://www.cyberciti.biz/faq/howto-use- ... inux-unix/

Here's what I came up with:

Code: Select all

filebot -script fn:history --format '$from\t$to' --log off | egrep -e '/complete' | sed -r -e 's/^.+\t//g'

Re: Re: Revert Renamed Files to their Original Names

Posted: 03 Apr 2014, 14:18
by s3frank
Thanks, I can figure it out from here. Love your work mate!