Where does FileBot store the "Copy to" directory string?

Support for macOS users
Post Reply
cheaters
Posts: 214
Joined: 09 Oct 2016, 02:01

Where does FileBot store the "Copy to" directory string?

Post by cheaters »

I am running the AMC script. Before a file is COPY from [/path/to/original/file] to [/path/to/renamed/file] is that final destination path stored in an argument that I can use?

:?: Do I have access to the argument containing the name of the directory where it will be stored after FileBot has decided how to rename it but before it has been copied there?

I want to use that information for a shell script.
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Where does FileBot store the "Copy to" directory string?

Post by rednoah »

You can write your own "copy to" shell script and do your own pre-processing and post-processing there as you see fit:
viewtopic.php?t=4915


The -exec option is more suitable if you just want to call a shell script on newly processed files:
viewtopic.php?t=11078
:idea: Please read the FAQ and How to Request Help.
cheaters
Posts: 214
Joined: 09 Oct 2016, 02:01

Re: Where does FileBot store the "Copy to" directory string?

Post by cheaters »

Thanks for the speedy response.

Sorry, I wasn't clear. Let's say AMC script has done its job and found a match and knows what the new directory name will be. Is that something that I can use after it has Copied?

First my shell script runs filebot fn:amc
Next it runs another command to find non-english subtitles, but because I don't know the exact path for the new movie directory yet, the find command I run looks inside /Movies instead of /Movies/Movie_Name_Date. Searching the whole /Movies directory is unnecessary since it has been searched before.

Thank you.
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Where does FileBot store the "Copy to" directory string?

Post by rednoah »

If you want to run a custom shell script on all the folders where we have newly copied files, then that would look like this:

Code: Select all

-exec /path/to/script.sh {folder}
:idea: Your /path/to/script.sh is then called multiple times for each unique {folder} value, which is available inside your script via the $1 argument variable.
:idea: Please read the FAQ and How to Request Help.
cheaters
Posts: 214
Joined: 09 Oct 2016, 02:01

Re: Where does FileBot store the "Copy to" directory string?

Post by cheaters »

:D It takes me hours and sometimes days to figure this stuff out... and that's with your help.

My torrent client is set up to run a shell script which contains my filebot commands. My "on torrent completion run external program" commands in the client are:

Code: Select all

/Users/john/.filebot/scripts/qBT_e-program.sh "%N" "%L" "%F" "%R" "%D" "%C" "%Z" "%T" "%I" "%G"
I am trying to add the destination path to this find/remove command inside my existing shell script. I played around with the idea you presented but had bad results.
I added an additional --action command to run another script but it ran for both --def MovieFormat and --def SeriesFormat . I don't think we can have two --action commands?

In my script the "{$1}" argument variable is --def "ut_title"="${1}" , which is the original title of the movie, not the FileBot corrected title and newly created directory.

According to the page you link to above the source path is $1 and the destination is $2

Code: Select all

!/bin/bash
{
  filebot -script fn:amc --output "/Volumes/PlexMedia/PlexServer_1" \
--action copy \
--conflict index -non-strict \
--log-file amc.log \
--def "ut_kind"="multi" \
--def "ut_title"="${1}" \
--def "ut_label"="${2}" \
--def "ut_tags"="${10}" \
--def "ut_dir"="${3}" \
--def "ut_rpath"="${4}" \
--def "ut_spath"="${5}" \
--def "ut_files"="${6}" \
--def "ut_bytes"="${7}" \
--def "ut_track"="${8}" \
--def "ut_info"="${9}" \
--def excludeList="/Users/john/.filebot/amc_excludes.txt" \
--def pushover=xxx \
--def unsorted=y \
--def music=y \
--def skipExtract=y \
--def seriesFormat="/Volumes/SeedDrive/PlexServer_2/{plex.derive{' {thetvdb-'}{id}{'}'}{' - ['+allOf{tags}{vf}{vs}{crc32}.join(' ')}{']'}}{if (dc > 1) '.'+di}" \
--def movieFormat="/Volumes/PlexMedia/PlexServer_1/{plex.derive{' {imdb-'}{imdbid}{'}'}{' ['+allOf{tags}{audio.language}{if ('Documentary' in genres)'[doc]'}{info:video[0].displayAspectRatioString.colon('"∶"').replace('?', '')}{ws}{vf}{vs}{vc}{crc32}.join(' ')}{']'}}{if (dc > 1) '.'+di}" \
"ut_dir"="${3}" "ut_title"="${1}" "ut_label"="${2}"
}
#this is where I do the find... Add {$1} at the end of the path here?
{
  find /Volumes/PlexMedia/PlexServer_1/Movies -type f -iname "*.srt" | \
  grep -v \\.eng | \
  grep -v "].srt" | \
  while read -r file; do trash -F "$file";done;
}
{
  DATEVAR=$(date '+%Y_%m_%d_%H:%M:%S'); echo "$DATEVAR ""${1}""" >> ~/Desktop/qbtscriptresult.txt
}
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Where does FileBot store the "Copy to" directory string?

Post by rednoah »

1.
jprokos wrote: 06 Mar 2021, 18:30 I am trying to add the destination path to this find/remove command inside my existing shell script.
I see. So you want a process called by your shell script to be able to set variables within the context of the calling shell script? AFAIK, that is fundamentally conceptually not possible since a parent processes cannot communicate with a child processes on this level of detail. There is standard IO though. Your shell script can always parse the standard output of the filebot process though, and then set variables accordingly.



2.
Your post-process script is just deleting *.srt files, so that'd be a rather straight-forward -exec use case. You'll want to refactor that into it's own standalone script and then have filebot call it via -exec on the destination folder as explained above.


Here's what the call stack would look like:
1. qBT calls your qBT_e-program.sh
1.1. qBT_e-program.sh calls filebot
1.1.1. filebot -exec calls your delete-srt-files.sh passing along the destination {folder} as Argument $1
1.1.1.1. delete-srt-files.sh calls find "$1" ...


e.g.

Code: Select all

-exec /path/to/delete-srt-files.sh {folder}
e.g. delete-srt-files.sh

Code: Select all

#!/bin/sh -xu
find "$1" # JUST PRINT FILE PATHS FOR TESTING
:idea: Please read the FAQ and How to Request Help.
cheaters
Posts: 214
Joined: 09 Oct 2016, 02:01

Re: Where does FileBot store the "Copy to" directory string?

Post by cheaters »

Thank you. The test worked. The script was called and there was output in my txt log.

Code: Select all

#!/bin/bash
#find "$1" >> ~/Desktop/SsubDeletetest.txt

Code: Select all

/Volumes/SeedDrive/PlexServer_2/TV Shows/Last Week Tonight with John Oliver/Season 08
/Volumes/SeedDrive/PlexServer_2/TV Shows/Last Week Tonight with John Oliver/Season 08/Last Week Tonight with John Oliver - S08E01 - Episode 210 {thetvdb-278518} - [720p WEB-DL B0D70BE9].mkv
/Volumes/SeedDrive/PlexServer_2/TV Shows/Last Week Tonight with John Oliver/Season 08/Last Week Tonight with John Oliver - S08E02 - Episode 211 {thetvdb-278518} - [720p WEB-DL 53A2A391].mkv
/Volumes/SeedDrive/PlexServer_2/TV Shows/Last Week Tonight with John Oliver/Season 08/Last Week Tonight with John Oliver - S08E03 - Episode 212 {thetvdb-278518} - [720p WEB-DL 4744E726].mkv
/Volumes/SeedDrive/PlexServer_2/TV Shows/Last Week Tonight with John Oliver/Season 08/Last Week Tonight with John Oliver - S08E04 - Episode 213 {thetvdb-278518} - [720p WEB-DL 2A3AC986].mkv
However, it's not finding and removing subtitles as a script.
:?: I think I need to add a "/" to the argument? So it treats the the end of the path as a directory and not a file?

Code: Select all

"$1/"
Right now the path that is printed using $1 looks like this: (using a different example)

Code: Select all

/Volumes/PlexMedia/PlexServer_1/Movies/Sin Nombre (2009)
Shouldn't it look like this:

Code: Select all

/Volumes/PlexMedia/PlexServer_1/Movies/Sin Nombre (2009)/
to search for content inside that directory.

Or maybe the find command needs a quoted path because of the spaces in the path?

I used #!/bin/bash for the shebang and I didn't use -u flag. I don't think that works on macOS with bash or sh

:!: The argument has to be double quoted because the path has spaces.

Code: Select all

'"$1"'
cheaters
Posts: 214
Joined: 09 Oct 2016, 02:01

Re: Where does FileBot store the "Copy to" directory string?

Post by cheaters »

rednoah wrote: 07 Mar 2021, 04:44
Here's what the call stack would look like:
1. qBT calls your qBT_e-program.sh
1.1. qBT_e-program.sh calls filebot
1.1.1. filebot -exec calls your delete-srt-files.sh passing along the destination {folder} as Argument $1
1.1.1.1. delete-srt-files.sh calls find "$1" ...


e.g.

Code: Select all

-exec /path/to/delete-srt-files.sh {folder}
e.g. delete-srt-files.sh

Code: Select all

#!/bin/sh -xu
find "$1" # JUST PRINT FILE PATHS FOR TESTING
I have been working on this for quite awhile and couldn't get the second script to run. I finally figured out how to log the shell script process and have useful information to share. I can PM you the err.txt?

The -exec command seems to running properly. The directory "/Volumes/PlexMedia/PlexServer_1" does exist but that is not where we're supposed to be running the script. It supposed to be run on "/Volumes/PlexMedia/PlexServer_1/Movies/CurrentDirectory"

I am getting results from the "1.1.1.1." script using the find command you suggested above. Which would indicate that it's being called and run on the correct path. I am not sure why the error. It looks like the -exec command is getting the value from "ut_dir"="${3}".

:idea: :?: Do I have the -exec command in the wrong place in the filebot script? Where should it be?

According to the error output:

Code: Select all

[2021-03-28 18:40:57.330] Cannot run program "/Users/john/.filebot/scripts/remove_non-english_subtitles.sh" (in directory "/Volumes/PlexMedia/PlexServer_1"): error=2, No such file or directory
[2021-03-28 18:40:57.336] Processed 26 files
[2021-03-28 18:40:57.342] Sending Pushover notification
[2021-03-28 18:40:58.247] Done ヾ(@⌒ー⌒@)ノ
my script again:

Code: Select all

#!/bin/bash
set -x
{
  filebot -script fn:amc --output "/Volumes/PlexMedia/PlexServer_1" \
--action copy \
--conflict index -non-strict \
--log-file amc.log \
--def "ut_kind"="multi" \
--def "ut_title"="${1}" \
--def "ut_label"="${2}" \
--def "ut_tags"="${10}" \
--def "ut_dir"="${3}" \
--def "ut_rpath"="${4}" \
--def "ut_spath"="${5}" \
--def "ut_files"="${6}" \
--def "ut_bytes"="${7}" \
--def "ut_track"="${8}" \
--def "ut_info"="${9}" \
--def excludeList="/Users/john/.filebot/amc_excludes.txt" \
--def pushover=xxxx \
--def unsorted=y \
--def music=y \
--def skipExtract=y \
--def seriesFormat="/Volumes/SeedDrive/PlexServer_2/{plex.derive{' {thetvdb-'}{id}{'}'}{' - ['+allOf{tags}{vf}{vs}{crc32}.join(' ')}{']'}}{if (dc > 1) '.'+di}" \
--def movieFormat="/Volumes/PlexMedia/PlexServer_1/{plex.derive{' {imdb-'}{imdbid}{'}'}{' ['+allOf{tags}{audio.language}{if ('Documentary' in genres)'[doc]'}{info:video[0].displayAspectRatioString.colon('"∶"').replace('?', '')}{ws}{vf}{vs}{vc}{crc32}.join(' ')}{']'}}{if (dc > 1) '.'+di}" \
"ut_title"="${1}" "ut_label"="${2}" "ut_dir"="${3}" -exec /Users/john/.filebot/scripts/remove_non-english_subtitles.sh {folder}
} 2>&1 >> /Users/john/Desktop/qbt_e-program_exec_results.txt
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Where does FileBot store the "Copy to" directory string?

Post by rednoah »

Does remove_non-english_subtitles.sh exist? Is it executable? Did you test remove_non-english_subtitles.sh independently of the amc script beforehand?

Code: Select all

Cannot run program "/Users/john/.filebot/scripts/remove_non-english_subtitles.sh" (in directory "/Volumes/PlexMedia/PlexServer_1"): error=2, No such file or directory

You can try other commands that can't fail for comparison, and then expand step by step from there:

Code: Select all

-exec echo {f}
:idea: Please read the FAQ and How to Request Help.
Post Reply