nathan-sain / foundry-world-tools

A Python CLI for managing Foundry VTT assets on the file system
MIT License
10 stars 5 forks source link

Replaceall does not correct image paths in actor biographies #12

Closed EternalDeiwos closed 2 years ago

EternalDeiwos commented 2 years ago

As per title.

For example, I have a path that looks like this: characters/reghed-shaman/Reghed Shaman-bio-1.png after running:

fwt dedup --ext=".png" --ext=".webp" --byname --preferred=".*webp" .
# check, cleanup and delete trash
fwt renameall --remove="[0-9]{3}_-_" --replace="/_+/-/" --lower .
# check, cleanup and delete trash

The result should be: characters/reghed-shaman/reghed-shaman-bio-1.webp

nathan-sain commented 2 years ago

Let's see if we can get this worked out. I'm not sure how the original path is included in the bio and I'm curious if the bio is being changed after each of the commands you included above. Can post a comment below with more about the problem?

  1. How is the original path in the bio used? Please include the original path in your comment, and if it's in an HTML tag please include the entire tag as it originally existed.
  2. Please include the path in the bio after running each of the commands above.

Thanks!

EternalDeiwos commented 2 years ago

It appears in the bio as HTML, after running those commands above it looks like this:

<img src="worlds/idrotfm/characters/reghed-shaman/Reghed Shaman-bio-1.png" />

I'm not precisely sure but before running those commands it looked something like this:

<img src="worlds/idrotfm/characters/224_-_Reghed_Shaman/Reghed Shaman-bio-1.png" />

The relative paths (.) in the commands above resolve to the world root folder /.../worlds/idroftm such that it would contain /.../worlds/idroftm/world.json.

nathan-sain commented 2 years ago

FWT was enclosing the string replacements in quote marks by default, which didn't match the paths in the escaped HTML of the bio.value attribute. I've disabled that behavior and run the following test:

foundry@b195a18ce418:/data/Data/worlds/cor-idrotfm$ fwt download --type actors --asset-dir characters .
foundry@b195a18ce418:/data/Data/worlds/cor-idrotfm$ grep -i -o -E '<img[^>]+Reghed[^>]+>' data/actors.db
<img src=\"worlds/cor-idrotfm/characters/224_-_Reghed_Shaman/Reghed Shaman-bio-1.png\">
foundry@b195a18ce418:/data/Data/worlds/cor-idrotfm$ ls -l characters/224_-_Reghed_Shaman/
total 598
-rw-rw-r--+ 1 foundry foundry 463662 Oct  9 08:13 'Reghed Shaman-bio-1.png'
-rw-rw-r--+ 1 foundry foundry  66190 Oct  9 08:10  avatar.webp
-rw-rw-r--+ 1 foundry foundry  66190 Oct  9 08:10  token.webp
foundry@b195a18ce418:/data/Data/worlds/cor-idrotfm$ cwebp -preset drawing -sharp_yuv -mt -psnr 45 "characters/224_-_Reghed_Shaman/Reghed Shaman-bio-1.png" -o "characters/224_-_Reghed_Shaman/Reghed Shaman-bio-1.webp"
foundry@b195a18ce418:/data/Data/worlds/cor-idrotfm$ fwt --logfile=/tmp/fwt_dedup.log dedup --ext=".png" --ext=".webp" --byname --preferred=".*webp" .
foundry@b195a18ce418:/data/Data/worlds/cor-idrotfm$ grep -i -o -E '<img[^>]+Reghed[^>]+>' data/actors.db
<img src=\"worlds/cor-idrotfm/characters/224_-_Reghed_Shaman/Reghed Shaman-bio-1.webp\">
foundry@b195a18ce418:/data/Data/worlds/cor-idrotfm$ fwt --logfile=/tmp/fwt_renameall.log renameall --remove="[0-9]{3}_-_" --replace="/_+/-/" --lower .
foundry@b195a18ce418:/data/Data/worlds/cor-idrotfm$ grep -i -o -E '<img[^>]+Reghed[^>]+>' data/actors.db
<img src=\"worlds/cor-idrotfm/characters/reghed-shaman/reghed shaman-bio-1.webp\">

Please update FWT and attempt to dedup and rename again.

EternalDeiwos commented 2 years ago

Confirmed working. Thanks @nathan-sain