[Linux] Command Line option to rename artwork with filename?

Running FileBot from the console, Groovy scripting, shell scripts, etc
Post Reply
schossel
Posts: 7
Joined: 19 Nov 2017, 13:32

[Linux] Command Line option to rename artwork with filename?

Post by schossel »

Hi,
I'm using the latest Linux version on the command line with the following code:

Code: Select all

sudo filebot -script fn:amc --action move -non-strict "/home/computer/movies" --log-file amc.log --def skipExtract=y --def unsorted=y --lang German --def artwork=y --def minFileSize=150 --def movieFormat="/home/computer/movies/movies_sorted/{n} ({y})/{folder.name}" --def clean=y
This works but all the artwork files are named folder.jpg, disc.png, poster.jpg...etc. I tried a few things to get them renamed to "Star Wars-folder.jpg, Star Wars-disc.png, Star Wars-poster.jpg.
I tried with the above code and movieFormat something like "fn.match..." but it only changes the filename (as expected).
Next try was with

Code: Select all

filebot -script fn:replace --def "e=fanart" "r={fn}" /home/computer/movies/movies_sorted --action copy
to get both fanart.jpg and Star Wars.jpg but {fn} doesn't work the way I expected in this situation and I can't find more parameters for fn:replace.

Is there any solution for my problem on the command line?

Thanks in advance!
User avatar
rednoah
The Source
Posts: 22986
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: [Linux] Command Line option to rename artwork with filename?

Post by rednoah »

The replace script only supports simple regular expression based substitution, so what you're trying to do is not possible.

I recommend writing a bash script that does the following:

Code: Select all

For each folder
    find fanart file
    find video file
    if both exists, rename fanart file according to the video file
:idea: Please read the FAQ and How to Request Help.
schossel
Posts: 7
Joined: 19 Nov 2017, 13:32

Re: [Linux] Command Line option to rename artwork with filename?

Post by schossel »

Yeah, I considered doing that but I wanted to aks before I do unnecessary work.
User avatar
rednoah
The Source
Posts: 22986
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: [Linux] Command Line option to rename artwork with filename?

Post by rednoah »

Make sure to share your solution for the next guy. ;)
:idea: Please read the FAQ and How to Request Help.
schossel
Posts: 7
Joined: 19 Nov 2017, 13:32

Re: [Linux] Command Line option to rename artwork with filename?

Post by schossel »

If I will realize it, I'll share it here.
schossel
Posts: 7
Joined: 19 Nov 2017, 13:32

Re: [Linux] Command Line option to rename artwork with filename?

Post by schossel »

Quick 'n dirty...

Assuming a file structure like:

Code: Select all

/home/mypc/movies/
   |__ Star Wars (1978)
        |__ Star Wars 720p AC3.avi
        |__ folder.jpg
        |__ movie.nfo
        |__ logo.png

Code: Select all

#!/bin/bash
for folder in /home/mypc/movies/*
do
    cd "$folder";
    filename_for_rename_with_extension=$(find . -name *.avi -o -name *.mkv -o -name *.mp4);
    filename_for_rename_trimmed=$(basename "$filename_for_rename_with_extension");
    filename_for_rename="${filename_for_rename_trimmed%.*}";
            
    for file in *;
	do       
        foldername="$(basename "$folder")";
        filename=$(basename "$file");
		extension="${file##*.}"
        if [ "$extension" = "jpg" ] || [ "$extension" = "png" ] || [ "$extension" = "nfo" ]; then
         echo "$filename" "$filename_for_rename"-"$filename";
         cp "$filename" "$filename_for_rename"-"$filename";
        fi
	done
    cd ..;
done
Run in movie root (ex. /home/mypc/movies/), it jumps into the first folder (ex. /home/mypc/movies/Star Wars (1978)), looks for the movie file (ex. Star Wars 720p AC3.avi) .mkv .avi .mp4 and saves the name. Then, it takes all files in that folder and checks if they are .jpg .png .nfo and if they are, they 'll get renamed from folder.jpg to Star Wars 720p AC3-folder.jpg BUT the original folder.jpg will NOT be deleted. You have 2 files now! If you want the folder.jpg deleted after it was renamed use mv (move) instead of cp (copy) in the code!
Change

Code: Select all

cp "$filename" "$filename_for_rename"-"$filename";
to

Code: Select all

mv "$filename" "$filename_for_rename"-"$filename";

If you prefer the foldername-folder.jpg (Star Wars (1978)) you can change the code to

Code: Select all

cp "$filename" "$foldername"-"$filename";
which should give you Star Wars (1978)-folder.jpg

So, if chosing filename, this will be:

Code: Select all

Star Wars (1978)
|__ Star Wars 720p AC3.avi
|__ folder.jpg
|__ movie.nfo
|__ logo.png
|__ Star Wars 720p AC3-folder.jpg
|__ Star Wars 720p AC3-movie.nfo
|__ Star Wars 720p AC3-logo.png
if chosing the foldername, this will be:

Code: Select all

Star Wars (1978)
|__ Star Wars 720p AC3.avi
|__ folder.jpg
|__ movie.nfo
|__ logo.png
|__ Star Wars (1978)-folder.jpg
|__ Star Wars (1978)-movie.nfo
|__ Star Wars (1978)-logo.png
and with changing cp to mv the source files will be deleted:

Code: Select all

Star Wars (1978)
|__ Star Wars 720p AC3.avi
|__ Star Wars 720p AC3-folder.jpg
|__ Star Wars 720p AC3-movie.nfo
|__ Star Wars 720p AC3-logo.png
I'm not the best programmer in the world, but the script should do the trick.
Proposals for improvement are highly appreciated!
I hope this will help someone else regaring the artwork problem.
thielj
Posts: 55
Joined: 05 Nov 2017, 22:15

Re: [Linux] Command Line option to rename artwork with filename?

Post by thielj »

It would be great if there was an option for these files to be passed to the movie formatter script!
Defaulting to 'no' to preserve backward compatibility.
User avatar
rednoah
The Source
Posts: 22986
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: [Linux] Command Line option to rename artwork with filename?

Post by rednoah »

If you want to use the format engine to come up with new paths for the logo files, then using FileBot/Groovy scripting is probably the way to go.

Your comment did remind me of Plain File mode though, and that you might be able to use that to batch rename image files:

Code: Select all

filebot -rename -r . --db xattr -non-strict --filter f.image --format "{folder.name}-{fn}" --action TEST
This well prepend the folder name in front of the current file name for each image file.


If you want the name of the first sibling video file, then the format will get a bit more complicated:

Code: Select all

{folder.files.find{ it.video }.nameWithoutExtension}
Unfortunately, you won't be able to use {movie} bindings, because FileBot doesn't add xattr tags to image files.
:idea: Please read the FAQ and How to Request Help.
Post Reply