capturing renamed result as variable

Running FileBot from the console, Groovy scripting, shell scripts, etc
Post Reply
jantjo
Posts: 6
Joined: 11 Nov 2016, 03:04

capturing renamed result as variable

Post by jantjo »

Hey there, looking from some new ideas on this as I've been racking my brain for a couple days. I have a script that parses files and renames/moves them to the appropriate folders. I've set this as a command substitution so I can refer to the output of filebot and pull more data from it, being the renamed files.

Code: Select all

moviefilebot=$(filebot.sh -rename --conflict $filebotconflictmode -no-xattr --log-file $filebotlog --format '{n.replace('\'':'\'','\'' -'\'')} ({y}){'\'' CD'\''+pi}{'\''.'\''+lang} {tags.join('\'', '\'')}' --action $filebotmode $remotemoviefolder/$Releasename --db $filemoviedb --output "/mnt/Movies/" -non-strict &) 

Code: Select all

renamedmkv=$(echo $moviefilebot | awk -F"/mnt/Movies/" '{print $2}' | sed "s/].*//g" | sed "s/'/\'\'/")
renamedidx=$(echo $moviefilebot | awk -F"/mnt/Movies/" '{print $3}' | sed "s/].*//g" | sed "s/'/\'\'/")
renamedsub=$(echo $moviefilebot | awk -F"/mnt/Movies/" '{print $4}' | sed "s/].*//g" | sed "s/'/\'\'/")
the results are spotty especially with special characters in the names such as ' . and it seems to be a word splitting issue with running it in a command subsitution. if I check the logs that it creates it shows fine, but the live output and whats being stored in the variable is wrong so when I go to massage the output it's random.

example.. live output which is stored in variable - notice the '\''

Code: Select all

[TEST] Rename [/home/user/files/movie/Miss.Peregrines.Home.for.Peculiar.Children.2016.1080p.BluRay.x264-SPARKS/Miss.Peregrines.Home.for.Peculiar.Children.2016.1080p.BluRay.x264-SPARKS.mkv] to [/mnt/movies/Miss Peregrine'\''s Home for Peculiar Children (2016).mkv]
Processed 1 files
Whats shown in the log file and what it's actually being called

Code: Select all

[TEST] Rename [/home/user/files/movie/Miss.Peregrines.Home.for.Peculiar.Children.2016.1080p.BluRay.x264-SPARKS/Miss.Peregrines.Home.for.Peculiar.Children.2016.1080p.BluRay.x264-SPARKS.mkv] to [/mnt/movies/Miss Peregrine's Home for Peculiar Children (2016).mkv]
Processed 1 files
so any ideas on how to tackle this? I've tired different method of quotes, trying to sed the output, just trying to suppress the word splitting. the key is whatever solution it has to work with files that dont have special characters and ones that do. I've thought about creating a log for each rename and parsing that, just think that will lead to a file management issue..
User avatar
rednoah
The Source
Posts: 23953
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: capturing renamed result as variable

Post by rednoah »

Have you considered writing this stuff in Groovy as FileBot script. That way you can deal with File objects and don't have to parse console output.

Alternatively, you can always access the FileBot rename history XML file instead of parsing the output.
:idea: Please read the FAQ and How to Request Help.
jantjo
Posts: 6
Joined: 11 Nov 2016, 03:04

Re: capturing renamed result as variable

Post by jantjo »

rednoah wrote:Have you considered writing this stuff in Groovy as FileBot script. That way you can deal with File objects and don't have to parse console output.

Alternatively, you can always access the FileBot rename history XML file instead of parsing the output.

I'll check it out both options, I'll have to figure out away to parse either for the appropriate data, need to find a time stamp or session id. basically im talking this data and building another set of commands. after the files a moved and renamed im creating symbolic links to them. so I need to identify the archive filename and the renamed filename, they just need to handle special characters the same.

Code: Select all

"mkdir ~/files/movie/$Releasename"
"ln -s "/mnt/Movies/$renamedmkv" ~/files/movie/$Releasename/$archivemkv"
"ln -s "/mnt/Movies/$renamedsub" ~/files/movie/$Releasename/$archivesub"
"ln -s "/mnt/Movies/$renamedidx" ~/files/movie/$Releasename/$archiveidx"
User avatar
rednoah
The Source
Posts: 23953
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: capturing renamed result as variable

Post by rednoah »

Have you considered doing something like this?

Code: Select all

filebot -rename -r ~/files/movie --db xattr --action symlink --output /mnt/Movies --format "{fn}"
That'll instantly create all the symlinks you want.
:idea: Please read the FAQ and How to Request Help.
jantjo
Posts: 6
Joined: 11 Nov 2016, 03:04

Re: capturing renamed result as variable

Post by jantjo »

rednoah wrote:Have you considered doing something like this?

Code: Select all

filebot -rename -r ~/files/movie --db xattr --action symlink --output /mnt/Movies --format "{fn}"
That'll instantly create all the symlinks you want.
I'll try it, just taking a look at it I think i'm looking for the reverse, but not to sure if that's possible in the logic.
ie: workflow
rename the original file and move it to destination (/mnt/Movies)
create symlink (in ~/files/movie) of the original name to the renamed file (in /mnt/Movies)

the way im reading (and what i've treid with revert and such) is you create the renamed file in /mnt/Movies as a symlink
User avatar
rednoah
The Source
Posts: 23953
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: capturing renamed result as variable

Post by rednoah »

If you want to move files and create symlinks to the new location in the original location, then you can just use --action keeplink:

Code: Select all

--action keeplink
:idea: Please read the FAQ and How to Request Help.
jantjo
Posts: 6
Joined: 11 Nov 2016, 03:04

Re: capturing renamed result as variable

Post by jantjo »

that works! thanks
Post Reply