if-then-else

All about user-defined episode / movie format expressions
Post Reply
Xelebrate
Posts: 2
Joined: 19 Oct 2015, 21:29

if-then-else

Post by Xelebrate » 26 Dec 2015, 21:02

I am trying to sort my movies into different folders depending the year of creation of the movie...

So every movie until 1969 has to move to /volume2/Classic-Movies/ and every newer movie should go to /volume1/Movie-Sammlung ...

I am downloading with JD and the following script ist working very nice (shortened):

Code: Select all


SERIEN="/volume2/Serien/{n}/{n} - Staffel {s}/{n} - {S00E00} - {t} [{d}] [{vf} {af.replace('6ch',' 5.1').replace('8ch',' 7.2').replace('3', ' 2.1').replace('2ch',' Stereo').replace('7ch',' 6.1').replace('3ch',' 2.1')}] [☆ {omdb.rating}]"
FILME="/volume1/Movie-Sammlung/{n} [{y}, {director}] - [{vf}] [{ac} {af.replace('6ch',' 5.1').replace('8ch',' 7.2').replace('3', ' 2.1').replace('2ch',' Stereo').replace('7ch',' 6.1').replace('3ch',' 2.1')}] [{vc}] [{minutes} Min] [★ {omdb.rating}]"

/volume1/@appstore/filebot/filebot.sh -script fn:amc --lang de --log-file $LOG --action move "$PFAD_1" -r --def "seriesFormat=$SERIEN" "movieFormat=$FILME" -non-strict --def clean=y   

/volume1/@appstore/filebot/filebot.sh -script fn:cleaner "$PFAD_1" --def root=y

/volume1/@appstore/filebot/filebot.sh -script fn:amc --lang de --log-file $LOG --action move "$PFAD_2" -r --def "seriesFormat=$SERIEN" "movieFormat=$FILME" -non-strict --def clean=y   

/volume1/@appstore/filebot/filebot.sh -script fn:cleaner "$PFAD_2" --def root=y

I have reviewed a lot of scripts, but have still no idea how to solve this problem.
Can someone give me hint for this, please? :)

User avatar
rednoah
The Source
Posts: 16812
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Need a hint ...

Post by rednoah » 27 Dec 2015, 07:09

if-then-else 101

Code: Select all

{y < 1970 ? 'OLD' : 'NEW'}
:idea: Please read the FAQ and How to Request Help.

Xelebrate
Posts: 2
Joined: 19 Oct 2015, 21:29

Re: Need a hint ...

Post by Xelebrate » 28 Dec 2015, 11:00

Well, thank you very much - this is working very well!
Sometimes it's just to easy ... ;)

Great Support!

suffx
Posts: 10
Joined: 17 Mar 2017, 11:12

Re: if-then-else

Post by suffx » 05 Oct 2017, 12:42

Hi,

I have pretty much the same issue and use a similar script.

I want to put files which contain a specific string (for example "sample") into a different folder than movies, tv shows and unsorted things. When Movies are going into /volume1/video/movies, i want samples to go into /volume1/video/misc. Preferably unprocessed, so the files dont get touched, but just moved to the misc folder.

I dont get where to put the exact if statement and what it has to look like. Here is my script:

Code: Select all

LOG="/volume1/video/Serien/amc.log"
EXC="/volume1/video/Serien/amc.txt"
MISC="/volume1/video/Downloads/misc/"
SERIEN="/volume1/video/Serien/{n}/{s}/{n} - {s00e00} - {t} ({y}) {vf}@{channels}"
SERIENOUT="/volume1/video/Serien/{n}/{s}/{n}/"
FILME="/volume1/video/Filme/{n} ({y}) {source}({vf}@{vc}) ({channels}@{ac}) [{rating}]/{n} ({y}) {source}({vf}@{vc}) ({channels}@{ac}) [{rating}]"
UNSORTIERT="/volume1/video/Downloads/videos/unsortiert - {file.structurePathTail}"

	
##FileBot ausführen
/var/packages/filebot/target/filebot.sh -script fn:amc --lang de --log-file $LOG --action move "$1" --def "seriesFormat=$SERIEN" "movieFormat=$FILME" "animeFormat=$ANIME" "unsortedFormat=$UNSORTIERT" "artwork=y" -non-strict --def unsorted=y --def skipExtract=y --conflict skip --def clean=y 

If thats the code:

Code: Select all

{y < 1970 ? 'OLD' : 'NEW'}
do i have to change it to:

Code: Select all

{fn =~ sample ? 'MISC Path' : Movie Path}
If thats the right code, where in my script do i have to put that?

User avatar
rednoah
The Source
Posts: 16812
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: if-then-else

Post by rednoah » 05 Oct 2017, 17:46

That would be part of your custom format expression.

I recommend using the Format Editor GUI to prototype and play with custom formats:
https://www.filebot.net/naming.html
:idea: Please read the FAQ and How to Request Help.

suffx
Posts: 10
Joined: 17 Mar 2017, 11:12

Re: if-then-else

Post by suffx » 06 Oct 2017, 07:11

Im not really sure how to put that in my naming scheme. How can i seperate between different folder within the naming scheme?

my Download folder ist for exapmle: /volume1/video/Downloads/package/sample/sample.mp4
$1 is /volume1/video/Downloads/package/ and /sample/ is the subfolder inside /package/

I Want Movies or files that Contain for example "sample" in the file or Folder Name to be Moved to
/volume1/Video/Download/misc

And normal Movies should Go to
/volume1/Video/Download/Movies

I tried this:

Code: Select all

input="$1*/"
echo input $input
if [[ $input == *"sample"* ]];
then
	echo "ECHO" "$1"*/
    FILME=$MISC
else
	echo "NO ECHO" "$1"*/
    FILME=$FILME
fi
With "$1"*/ i get the whole path including subfolders, thats what i want. But my if statement works for the normal $1 path, but doesnt work for the subfolder path, containing the useful informations.

So if i put in "package" instead of "sample" in the if statement, it works. Otherwise it doesn't

Edit: I think i have a working solution now:

Code: Select all

for d in $1*/ ; do
    echo d = "$d"
done

if [[ $d == *"sample"* ]];
then
    FILME=$MISC
	UNSORTIERT=$MISC
	echo "Misc" $FILME
else
	FILME=$FILME
	echo "Filme" $FILME
fi
Have to see if its robust and works wit hevery cases

Edit 2: ok, doenst work with JD. If i start the script via ssh and pass the path as arguement myself, it works. But when JD passes the Path after extracting, it doesnt. Im not sure why, but the Log says that Argument 0 is the path where the package gets doenloaded, but it doesnt include the subfolder path. Maybe thats the reason?

I tried using archive.getExtractToFolder() instead of archive.getFolder() in JD eventscripter, but it still doenst work.
Any hints?

suffx
Posts: 10
Joined: 17 Mar 2017, 11:12

Re: if-then-else

Post by suffx » 09 Oct 2017, 06:33

Sorry for double post, but i bet there is a very easy way to realzise this. I just can't figure out how to get this working within the naming scheme. Especially because i want filebot to move the files in completely different folders if specific strings occur in the package or filenames.

Edit: i think i've got it now...
this worked with the gui editor, have to try it with cli now

Code: Select all

{fn =~ /sample/ ? 'D:\\Samples' : 'D:\\Bilder'}/{n} - {s00e00} - {t}

User avatar
rednoah
The Source
Posts: 16812
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: if-then-else

Post by rednoah » 09 Oct 2017, 11:52

I'd write it like this:

Code: Select all

D:/{fn =~ /sample/ ? 'Samples' : 'Episodes'}/{plex.name}
:idea: Please read the FAQ and How to Request Help.

CuddleBear
Posts: 2
Joined: 21 Oct 2017, 17:45

Re: if-then-else

Post by CuddleBear » 21 Oct 2017, 18:44

just got filebot last night and i am struggling with a simple if statement with Atmos.

trying to do something simple like this but fail to do so.

Code: Select all

{aco.match (/Atmos/) ? 'Atmos' : "{ac}"}
simple, if aco contains Atmos it will write atmos, if not then use ac the normal codec writeout.

i get the write atmos part but not the other codecs part.

User avatar
rednoah
The Source
Posts: 16812
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: if-then-else

Post by rednoah » 21 Oct 2017, 21:49

Keep in mind the Unwind-on-Undefined behavior. The match() function return either a match or throw an exception, so the else code is unreachable.

e.g. this is probably what you're trying to do:

Code: Select all

{any{aco.match(/Atmos/)}{ac}}
@see viewtopic.php?f=5&t=1895
:idea: Please read the FAQ and How to Request Help.

CuddleBear
Posts: 2
Joined: 21 Oct 2017, 17:45

Re: if-then-else

Post by CuddleBear » 22 Oct 2017, 00:17

thanks alot for the reply and sorry for jacking the thread for a bit <3
yeah that one worked great! simple wording for audio codecs, just perfect.

kim
Power User
Posts: 807
Joined: 15 May 2014, 16:17

Re: if-then-else

Post by kim » 22 Oct 2017, 01:51

btw: there is a problem with most (~90%) of videos with MP3 format and {aco}
is shows "Joint stereo"

Post Reply