Page 1 of 1
How can i rename files based on history?
Posted: 14 Jul 2024, 05:21
by hama4reall
I'm trying to re-rename files based on the history.xml but I don't see any ways documented in the forum or google.
I'm moving from my previous gnome seedbox to my own debian server, and now I want to re-hardlink all my files just like it was on my previous server but it seems when i was using filebot previously I didn't know of xattr and so no xattr metadata are saved so I'm trying to use the history i just updated the parent directory of my files in the history.xml and now want to know how can i hardlink them i know i might be able to do it with
but there might files i have renamed it couple of time so that might create duplicate files somewhere else.
Re: How can i rename files based on history?
Posted: 14 Jul 2024, 06:02
by rednoah
You'll probably need to write your own script for that. The
history.xml file will tell you all the source / destination files.
Here's something to get you started:
Shell: Select all
#!/bin/sh
filebot -script fn:history --log OFF | while IFS=$'\t' read -r SRC DST
do
echo "$SRC -> $DST"
done
Re: How can i rename files based on history?
Posted: 14 Jul 2024, 07:43
by hama4reall
Thanks very much, do you have any idea to how i can avoid the duplicate matches like files that are renamed couples times and they have couple matches in the history?
Re: How can i rename files based on history?
Posted: 14 Jul 2024, 08:18
by rednoah
hama4reall wrote: ↑14 Jul 2024, 07:43
Thanks very much, do you have any idea to how i can avoid the duplicate matches like files that are renamed couples times and they have couple matches in the history?
What should happen if you have a couple of matches in the history? For
$SRC? For
$DST? For both? Define exactly what you want to do, consider all corner cases, and then modify your code accordingly.
Presumably, you'd
check if $SRC or $DST already exist and then do nothing in that case:
Shell: Select all
#!/bin/sh
filebot -script fn:history --log OFF | while IFS=$'\t' read -r SRC DST
do
# require SRC to exist and require DST to not exist
if [ -f "$SRC" ] && [ ! -f "$DST" ]
then
ln -v "$SRC" "$DST"
fi
done
Re: How can i rename files based on history?
Posted: 14 Jul 2024, 08:57
by hama4reall
They have the same
$SRC but different
$DST and in this case the one which is
most recent must be linked and the old ones to be ignored.
For example in the
history.xml we have a file called
this file has two records which both point to two different destinations now i want the newer record to be processed and hard linked.
Re: How can i rename files based on history?
Posted: 14 Jul 2024, 09:16
by rednoah
What does
filebot -script fn:history print for the file at hand?
Shell: Select all
filebot -script fn:history | grep 'Bear.Man.2023.1080p.Shafilm.mp4'
Re: How can i rename files based on history?
Posted: 14 Jul 2024, 10:09
by hama4reall
I've been trying to make filebot show history with
For an hour, in the
file i see all the history but with the command it just prints
This is a fresh filebot installation in
GUI i imported the history from my old server and closed the program the
history.xml file appeared but filebot in cli doesn't show it.
Re: How can i rename files based on history?
Posted: 14 Jul 2024, 10:15
by hama4reall
So i renamed a file in the cli and run
Now it prints
Console Output: Select all
/home/kurdflim/Videos/After.Everything.2023.1080p.AMZN.WEB-DL.Shafilm.m4v /home/kurdflim/Videos/After Everything (2023).m4v
Done ヾ(@⌒ー⌒@)ノ
But when i do
It prints
Console Output: Select all
<sequence date="2024-07-14T00:21:28.737+03:00">
<rename dir="/home/kurdflim/files/CDN5/4K/Movie" from="The.Bikeriders.2023.2160p.WEB-DL.DDP5.1.SDR.H265-AOC.mp4" to="/home/kurdflim/Media/4KMovies/English/The Bikeriders (2024) [tmdbid-1008409]/The Bikeriders (2024).mp4"/>
</sequence>
<sequence date="2024-07-14T00:26:56.304+03:00">
<rename dir="/home/kurdflim/files/CDN5/Series/Kimse.Bilmez.2019" from="Kimse.Bilmez.S01E07.1080p.Shafilm.mp4" to="/home/kurdflim/Media/Shows/Turkish/Kimse Bilmez (2019) [tmdbid-90210]/Season 01/Kimse Bilmez (2019) - S01E07 - Episode 7.mp4"/>
</sequence>
<sequence date="2024-07-14T13:11:19.726+03:00">
<rename dir="/home/kurdflim/Videos" from="After.Everything.2023.1080p.AMZN.WEB-DL.Shafilm.m4v" to="After Everything (2023).m4v"/>
</sequence>
</history>
Did i imported it wrong or is this expected behavior?
Re: How can i rename files based on history?
Posted: 14 Jul 2024, 10:21
by rednoah
I see. Unlucky there. Looks like
filebot -script fn:history only prints history entries where the destination file currently exists:
https://github.com/filebot/scripts/blob ... .groovy#L6
Looks like you'll have to write the code entirely by yourself... Pick the language of your choice, parse the XML, do the hardlink operations. It'll be ~20 lines of code.
Re: How can i rename files based on history?
Posted: 14 Jul 2024, 10:37
by rednoah
If you're having a hard time writing generic code by yourself / with ChatGPT then here's how you could do it with
FileBot Scripting:
Groovy: Select all
#!/usr/bin/env -S filebot -script
getPersistentRenameLog().each{ src, dst ->
println "* $src -> $dst"
if (src.exists()) {
if (!dst.exists()) {
println src.duplicate(dst)
} else {
println "$dst already exists"
}
} else {
println "$src does not exist"
}
}
Re: How can i rename files based on history?
Posted: 18 Jul 2024, 06:04
by hama4reall
Hi, sorry for my late reply that day i was trying to write a script with gemini all day and i gave up from frustrating and didn't notice your comment, i just tested it and it works but i think it copies the file? Instead of hardlink is this the case?
Re: How can i rename files based on history?
Posted: 18 Jul 2024, 06:08
by rednoah
src.duplicate(dst) will
hardlink if possible, and
copy if necessary.

Are
src and
dst are on the same file system?

What is that file system?
(NOTE: if it's btrfs then src.duplicate(dst) might reflink)
Re: How can i rename files based on history?
Posted: 18 Jul 2024, 07:34
by hama4reall
Got i just checked it's hardlinking them so this is it, the file system is ext4 and both src and dst are one the same file system. So all of the files is hardlinked now so thanks a lot appreciate it.