Page 1 of 1

capturing renamed result as variable

Posted: 15 Dec 2016, 05:03
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..

Re: capturing renamed result as variable

Posted: 15 Dec 2016, 08:10
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.

Re: capturing renamed result as variable

Posted: 15 Dec 2016, 13:37
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"

Re: capturing renamed result as variable

Posted: 15 Dec 2016, 16:00
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.

Re: capturing renamed result as variable

Posted: 15 Dec 2016, 16:53
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

Re: capturing renamed result as variable

Posted: 15 Dec 2016, 16:56
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

Re: capturing renamed result as variable

Posted: 15 Dec 2016, 17:55
by jantjo
that works! thanks