Running AMC script with complicated naming scheme

Running FileBot from the console, Groovy scripting, shell scripts, etc
Post Reply
greenskye
Posts: 4
Joined: 06 Dec 2015, 06:13

Running AMC script with complicated naming scheme

Post by greenskye »

I'm trying to run the AMC script on linux with a custom naming scheme. I didn't develop this scheme myself, just found it posted online somewhere and it's worked well for me. Trying to use it via command line has proven frustrating however.

This is my naming scheme:

Code: Select all

D:/Movies/{collection.replaceFirst(/^(?i)(The)\s(.+)/, /$2, $1/).replaceFirst(/^(?i)(Collection of the)\s(.+)/, /$2 Collection/).replaceAll(/Saga Collection/, "Saga").replaceAll(/[`´‘’ʻ""“”]/, "'").replaceAll(/[:|]/, " - ").replaceAll(/[?]/, "!").replaceAll(/[*\s]+/, " ")}/{norm = {it.upperInitial().lowerTrail().replaceTrailingBrackets().replaceAll(/[`´‘’ʻ""“”]/, "'").replaceAll(/[:|]/, " - ").replaceAll(/[?]/, "!").replaceAll(/[*\s]+/, " ").replaceAll(/\b[IiVvXx]+\b/, { it.upper() }).replaceAll(/\b[0-9](?i:th|nd|rd)\b/, { it.lower() }).replaceFirst(/^(?i)(The)\s(.+)/, /$2, $1/)}; norm(n)}{if (norm(n) != norm(primaryTitle)) ' ('+norm(primaryTitle)+')'}{fn.contains('3D') || fn.contains('3-D') ? ' '+'3D':""} ({y}{' '+any{certification}{imdb.certification}.replaceAll(/^\d+$/, 'PG-$0')})/{norm(n.space('.'))}{fn.contains('3D') || fn.contains('3-D') ? ' '+'3D':""}{'.(' + fn.matchAll(/extended|uncensored|remastered|unrated|uncut|directors.cut|special.edition/)*.upperInitial()*.lowerTrail().sort().join(', ').replaceAll(/[._]/, ".") + ')'}{".Part.$pi"}{".[$vf.$vc.$ac.$af]"}{'.'+lang}
I've tried using the escape script and xargs, but both give me this error:

Code: Select all

/bin/bash: -c: line 0: syntax error near unexpected token `('
/bin/bash: -c: line 0: `. /mnt/cache/.PhAzE-Common/Filebot/startcfg.sh; /usr/local/Filebot/filebot.sh -script fn:amc --output /mnt/user/Downloads --action copy -non-strict /mnt/user/Downloads/movies --def excludeList=amc.txt --action test --def movieFormat={collection.replaceFirst(/^(?i)(The)\s(.+)/, /$2, $1/).replaceFirst(/^(?i)(Collection of the)\s(.+)/, /$2 Collection/).replaceAll(/Saga Collection/, "Saga").replaceAll(/[`´‘’ʻ""“”]/, "'").replaceAll(/[:|]/, " - ").replaceAll(/[?]/, "!").replaceAll(/[*\s]+/, " ")}/{norm = {it.upperInitial().lowerTrail().replaceTrailingBrackets().replaceAll(/[`´‘’ʻ""“”]/, "'").replaceAll(/[:|]/, " - ").replaceAll(/[?]/, "!").replaceAll(/[*\s]+/, " ").replaceAll(/\b[IiVvXx]+\b/, { it.upper() }).replaceAll(/\b[0-9](?i:th|nd|rd)\b/, { it.lower() }).replaceFirst(/^(?i)(The)\s(.+)/, /$2, $1/)}; norm(n)}{if (norm(n) != norm(primaryTitle)) ' ('+norm(primaryTitle)+')'}{fn.contains('3D') || fn.contains('3-D') ? ' '+'3D':""} ({y}{' '+any{certification}{imdb.certification}.replaceAll(/^\d+$/, 'PG-$0')})/{norm(n.space('.'))}{fn.contains('3D') || fn.contains('3-D') ? ' '+'3D':""}{'.(' + fn.matchAll(/extended|uncensored|remastered|unrated|uncut|directors.cut|special.edition/)*.upperInitial()*.lowerTrail().sort().join(', ').replaceAll(/[._]/, ".") + ')'}{".Part.$pi"}{".[$vf.$vc.$ac.$af]"}{'.'+lang}'
I'd like to keep using my naming scheme if at all possible, but I understand if it's just too big and unwieldy to modify properly.
greenskye
Posts: 4
Joined: 06 Dec 2015, 06:13

Re: Running AMC script with complicated naming scheme

Post by greenskye »

I did read both of those, but I must still be missing something.

Here's my original unaltered naming format for reference:

Code: Select all

{collection.replaceFirst(/^(?i)(The)\s(.+)/, /$2, $1/).replaceFirst(/^(?i)(Collection of the)\s(.+)/, /$2 Collection/).replaceAll(/Saga Collection/, "Saga").replaceAll(/[`´‘’ʻ""“”]/, "'").replaceAll(/[:|]/, " - ").replaceAll(/[?]/, "!").replaceAll(/[*\s]+/, " ")}/{norm = {it.upperInitial().lowerTrail().replaceTrailingBrackets().replaceAll(/[`´‘’ʻ""“”]/, "'").replaceAll(/[:|]/, " - ").replaceAll(/[?]/, "!").replaceAll(/[*\s]+/, " ").replaceAll(/\b[IiVvXx]+\b/, { it.upper() }).replaceAll(/\b[0-9](?i:th|nd|rd)\b/, { it.lower() }).replaceFirst(/^(?i)(The)\s(.+)/, /$2, $1/)}; norm(n)}{if (norm(n) != norm(primaryTitle)) ' ('+norm(primaryTitle)+')'}{fn.contains('3D') || fn.contains('3-D') ? ' '+'3D':""} ({y}{' '+any{certification}{imdb.certification}.replaceAll(/^\d+$/, 'PG-$0')})/{norm(n.space('.'))}{fn.contains('3D') || fn.contains('3-D') ? ' '+'3D':""}{'.(' + fn.matchAll(/extended|uncensored|remastered|unrated|uncut|directors.cut|special.edition/)*.upperInitial()*.lowerTrail().sort().join(', ').replaceAll(/[._]/, ".") + ')'}{".Part.$pi"}{".[$vf.$vc.$ac.$af]"}{'.'+lang}
This is what I get when I run it through the escape script:

Code: Select all

"{collection.replaceFirst(/\^(?i)(The)\\s(.+)/, /\$2, \$1/).replaceFirst(/\^(?i)(Collection of the)\\s(.+)/, /\$2 Collection/).replaceAll(/Saga Collection/, \"Saga\").replaceAll(/[\`´‘’ʻ\"\"“”]/, \"'\").replaceAll(/[:|]/, \" - \").replaceAll(/[?]/, \"!\").replaceAll(/[*\\s]+/, \" \")}/{norm = {it.upperInitial().lowerTrail().replaceTrailingBrackets().replaceAll(/[\`´‘’ʻ\"\"“”]/, \"'\").replaceAll(/[:|]/, \" - \").replaceAll(/[?]/, \"!\").replaceAll(/[*\\s]+/, \" \").replaceAll(/\\b[IiVvXx]+\\b/, { it.upper() }).replaceAll(/\\b[0-9](?i:th|nd|rd)\\b/, { it.lower() }).replaceFirst(/\^(?i)(The)\\s(.+)/, /\$2, \$1/)}; norm(n)}{if (norm(n) != norm(primaryTitle)) ' ('+norm(primaryTitle)+')'}{fn.contains('3D') || fn.contains('3-D') ? ' '+'3D':\"\"} ({y}{' '+any{certification}{imdb.certification}.replaceAll(/\^\\d+\$/, 'PG-\$0')})/{norm(n.space('.'))}{fn.contains('3D') || fn.contains('3-D') ? ' '+'3D':\"\"}{'.(' + fn.matchAll(/extended|uncensored|remastered|unrated|uncut|directors.cut|special.edition/)*.upperInitial()*.lowerTrail().sort().join(', ').replaceAll(/[._]/, \".\") + ')'}{\".Part.\$pi\"}{\".[\$vf.\$vc.\$ac.\$af]\"}{'.'+lang}"
Running that format in my command:

Code: Select all

filebot -script fn:amc --output "/mnt/user/Downloads" --action copy -non-strict "/mnt/user/Downloads/movies" --def excludeList=amc.txt --action test --def "movieFormat={collection.replaceFirst(/\^(?i)(The)\\s(.+)/, /\$2, \$1/).replaceFirst(/\^(?i)(Collection of the)\\s(.+)/, /\$2 Collection/).replaceAll(/Saga Collection/, \"Saga\").replaceAll(/[\`´‘’ʻ\"\"“”]/, \"'\").replaceAll(/[:|]/, \" - \").replaceAll(/[?]/, \"!\").replaceAll(/[*\\s]+/, \" \")}/{norm = {it.upperInitial().lowerTrail().replaceTrailingBrackets().replaceAll(/[\`´‘’ʻ\"\"“”]/, \"'\").replaceAll(/[:|]/, \" - \").replaceAll(/[?]/, \"!\").replaceAll(/[*\\s]+/, \" \").replaceAll(/\\b[IiVvXx]+\\b/, { it.upper() }).replaceAll(/\\b[0-9](?i:th|nd|rd)\\b/, { it.lower() }).replaceFirst(/\^(?i)(The)\\s(.+)/, /\$2, \$1/)}; norm(n)}{if (norm(n) != norm(primaryTitle)) ' ('+norm(primaryTitle)+')'}{fn.contains('3D') || fn.contains('3-D') ? ' '+'3D':\"\"} ({y}{' '+any{certification}{imdb.certification}.replaceAll(/\^\\d+\$/, 'PG-\$0')})/{norm(n.space('.'))}{fn.contains('3D') || fn.contains('3-D') ? ' '+'3D':\"\"}{'.(' + fn.matchAll(/extended|uncensored|remastered|unrated|uncut|directors.cut|special.edition/)*.upperInitial()*.lowerTrail().sort().join(', ').replaceAll(/[._]/, \".\") + ')'}{\".Part.\$pi\"}{\".[\$vf.\$vc.\$ac.\$af]\"}{'.'+lang}"
gives me a "-bash: !\: event not found" error.

Some research reveals that the escape script doesn't seem to properly handle exclamation marks. Apparently they get parsed without respect for quotation marks. You can escape them with backslash, but then the backslash is not escaped either. More information here:http://superuser.com/a/301330.

Code: Select all

replaceAll("!")
becomes

Code: Select all

replaceAll(\""'!'"\")
Tested this with echo and it all seemed to work. My newly formatted naming scheme became:

Code: Select all

{collection.replaceFirst(/\^(?i)(The)\\s(.+)/, /\$2, \$1/).replaceFirst(/\^(?i)(Collection of the)\\s(.+)/, /\$2 Collection/).replaceAll(/Saga Collection/, \"Saga\").replaceAll(/[\`´‘’ʻ\"\"“”]/, \"'\").replaceAll(/[:|]/, \" - \").replaceAll(/[?]/, \""'!'"\").replaceAll(/[*\\s]+/, \" \")}/{norm = {it.upperInitial().lowerTrail().replaceTrailingBrackets().replaceAll(/[\`´‘’ʻ\"\"“”]/, \"'\").replaceAll(/[:|]/, \" - \").replaceAll(/[?]/, \""'!'"\").replaceAll(/[*\\s]+/, \" \").replaceAll(/\\b[IiVvXx]+\\b/, { it.upper() }).replaceAll(/\\b[0-9](?i:th|nd|rd)\\b/, { it.lower() }).replaceFirst(/\^(?i)(The)\\s(.+)/, /\$2, \$1/)}; norm(n)}{if (norm(n) != norm(primaryTitle)) ' ('+norm(primaryTitle)+')'}{fn.contains('3D') || fn.contains('3-D') ? ' '+'3D':\"\"} ({y}{' '+any{certification}{imdb.certification}.replaceAll(/\^\\d+\$/, 'PG-\$0')})/{norm(n.space('.'))}{fn.contains('3D') || fn.contains('3-D') ? ' '+'3D':\"\"}{'.(' + fn.matchAll(/extended|uncensored|remastered|unrated|uncut|directors.cut|special.edition/)*.upperInitial()*.lowerTrail().sort().join(', ').replaceAll(/[._]/, \".\") + ')'}{\".Part.\$pi\"}{\".[\$vf.\$vc.\$ac.\$af]\"}{'.'+lang}
However actually attempting to use it:

Code: Select all

filebot -script fn:amc --output "/mnt/user/Downloads" --action copy -non-strict "/mnt/user/Downloads/movies" --def excludeList=amc.txt --action test --def "movieFormat={collection.replaceFirst(/\^(?i)(The)\\s(.+)/, /\$2, \$1/).replaceFirst(/\^(?i)(Collection of the)\\s(.+)/, /\$2 Collection/).replaceAll(/Saga Collection/, \"Saga\").replaceAll(/[\`´‘’ʻ\"\"“”]/, \"'\").replaceAll(/[:|]/, \" - \").replaceAll(/[?]/, \""'!'"\").replaceAll(/[*\\s]+/, \" \")}/{norm = {it.upperInitial().lowerTrail().replaceTrailingBrackets().replaceAll(/[\`´‘’ʻ\"\"“”]/, \"'\").replaceAll(/[:|]/, \" - \").replaceAll(/[?]/, \""'!'"\").replaceAll(/[*\\s]+/, \" \").replaceAll(/\\b[IiVvXx]+\\b/, { it.upper() }).replaceAll(/\\b[0-9](?i:th|nd|rd)\\b/, { it.lower() }).replaceFirst(/\^(?i)(The)\\s(.+)/, /\$2, \$1/)}; norm(n)}{if (norm(n) != norm(primaryTitle)) ' ('+norm(primaryTitle)+')'}{fn.contains('3D') || fn.contains('3-D') ? ' '+'3D':\"\"} ({y}{' '+any{certification}{imdb.certification}.replaceAll(/\^\\d+\$/, 'PG-\$0')})/{norm(n.space('.'))}{fn.contains('3D') || fn.contains('3-D') ? ' '+'3D':\"\"}{'.(' + fn.matchAll(/extended|uncensored|remastered|unrated|uncut|directors.cut|special.edition/)*.upperInitial()*.lowerTrail().sort().join(', ').replaceAll(/[._]/, \".\") + ')'}{\".Part.\$pi\"}{\".[\$vf.\$vc.\$ac.\$af]\"}{'.'+lang}"
gives me this error:

Code: Select all

/bin/bash: -c: line 0: syntax error near unexpected token `('
/bin/bash: -c: line 0: `. /mnt/cache/.PhAzE-Common/Filebot/startcfg.sh; /usr/local/Filebot/filebot.sh -script fn:amc --output /mnt/user/Downloads --action copy -non-strict /mnt/user/Downloads/movies --def excludeList=amc.txt --action test --def movieFormat={collection.replaceFirst(/\^(?i)(The)\s(.+)/, /$2, $1/).replaceFirst(/\^(?i)(Collection of the)\s(.+)/, /$2 Collection/).replaceAll(/Saga Collection/, "Saga").replaceAll(/[`´‘’ʻ""“”]/, "'").replaceAll(/[:|]/, " - ").replaceAll(/[?]/, "!").replaceAll(/[*\s]+/, " ")}/{norm = {it.upperInitial().lowerTrail().replaceTrailingBrackets().replaceAll(/[`´‘’ʻ""“”]/, "'").replaceAll(/[:|]/, " - ").replaceAll(/[?]/, "!").replaceAll(/[*\s]+/, " ").replaceAll(/\b[IiVvXx]+\b/, { it.upper() }).replaceAll(/\b[0-9](?i:th|nd|rd)\b/, { it.lower() }).replaceFirst(/\^(?i)(The)\s(.+)/, /$2, $1/)}; norm(n)}{if (norm(n) != norm(primaryTitle)) ' ('+norm(primaryTitle)+')'}{fn.contains('3D') || fn.contains('3-D') ? ' '+'3D':""} ({y}{' '+any{certification}{imdb.certification}.replaceAll(/\^\d+$/, 'PG-$0')})/{norm(n.space('.'))}{fn.contains('3D') || fn.contains('3-D') ? ' '+'3D':""}{'.(' + fn.matchAll(/extended|uncensored|remastered|unrated|uncut|directors.cut|special.edition/)*.upperInitial()*.lowerTrail().sort().join(', ').replaceAll(/[._]/, ".") + ')'}{".Part.$pi"}{".[$vf.$vc.$ac.$af]"}{'.'+lang}'
I'm not sure why I can echo this command perfectly and yet trying to run it results in problems.
User avatar
rednoah
The Source
Posts: 23953
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Running AMC script with complicated naming scheme

Post by rednoah »

Well, since you're not on Windows you should use the better solution:
viewtopic.php?f=4&t=1041#p9794

Image
:idea: Please read the FAQ and How to Request Help.
greenskye
Posts: 4
Joined: 06 Dec 2015, 06:13

Re: Running AMC script with complicated naming scheme

Post by greenskye »

Using xargs gives me the same error.

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

Re: Running AMC script with complicated naming scheme

Post by rednoah »

r3369 and newer will allow you to do this:

Code: Select all

--def "movieFormat=@/path/to/movieFormat.txt"
:idea: Please read the FAQ and How to Request Help.
greenskye
Posts: 4
Joined: 06 Dec 2015, 06:13

Re: Running AMC script with complicated naming scheme

Post by greenskye »

I take it that release isn't out yet? I have 4.6.1 which is r3315. I checked github, but I'm not sure how or where to search for r3369. Thanks for helping me.
User avatar
rednoah
The Source
Posts: 23953
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Running AMC script with complicated naming scheme

Post by rednoah »

:idea: Please read the FAQ and How to Request Help.
User avatar
rednoah
The Source
Posts: 23953
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Running AMC script with complicated naming scheme

Post by rednoah »

As it turns out, the args4j library I use for argument parsing already has built-in support for something like that... :lol:

Code: Select all

filebot @/path/to/file
This may have been possible for years... :lol:
:idea: Please read the FAQ and How to Request Help.
Post Reply