filebot and sonarr import again

Any questions? Need some help?
KRONZO
Posts: 30
Joined: 31 Dec 2017, 23:20

filebot and sonarr import again

Post by KRONZO »

Hi Rednoah

I've decided to try and fix this my patch got to be to annoying.
Im trying to get sonarr to import files renamed by filebot, you helped me a little earlier this year.
viewtopic.php?p=31795#p31795
i've gotten filebot to pass the name to the import script i think, but my best result is, that nothing throws an error but no import happens, I think i need a path variable in the import code but i do not know what and im not sure FB is passing the path correctly so i'm hoping you can help me again.

this is what --def exec calls (i think i need something in path) (running on windows 10)

Code: Select all

$url = "http://localhost:2587/api/command"
$json = '{"name": "downloadedepisodesscan","path": "" , "importMode":"Move"}' 

Write-Host "Publishing update $version ($branch) to: $url"
Invoke-RestMethod -Uri $url -Method Post -Body $json -Headers @{"X-Api-Key"="4dd3cc179te04d15kt9288313d8d21087d"}

and the FB test AMC

Code: Select all

filebot -script fn:amc --output "D:/tempdir" --action hardlink -non-strict --def seriesFormat="{fn}/{fn}" "D:/testmedia"  --def exec="D:\testmedia\sonarrimport.ps1 {quote f}"
and finally the output Image

as you can see there is nothing in path in the picture, when i manually insert path everything works

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

Re: filebot and sonarr import again

Post by rednoah »

The command looks good to me. The issue is likely in your script. You can add some debugging information to your script to find out what's going on.


1.
This definitely won't work, since you'll probably want the file path of your Argument 1 here:

Code: Select all

"path": ""

2.
When you send a request, the request will give you a response. You'll want to print this response, so that you can read the error message that sonarr is giving you back for bad requests.


3.
Generating valid json can be tricky. Use this:
https://stackoverflow.com/a/44597342/1514467
:idea: Please read the FAQ and How to Request Help.
KRONZO
Posts: 30
Joined: 31 Dec 2017, 23:20

Re: filebot and sonarr import again

Post by KRONZO »

Hi Rednoah
Yeah i figured i need to pass the filebot path to the "path": "" but i have no idea how to, i've tried $filepath and all the variants i could find.
I dont know how to use what you linked to, i've spent days and hours on this and is at an impasse (isn't there some kind of wildcard to catch the path fb is sending)
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: filebot and sonarr import again

Post by rednoah »

Well, presumably, a PowerShell tutorial on how to use variables and Strings will hold the solution.

Here's a --def exec expression that should work:

Code: Select all

Invoke-RestMethod -Uri 'http://localhost:2587/api/command' -Method Post -Body {quote groovy.json.JsonOutput.toJson(name: 'downloadedepisodesscan', path: f.path , importMode: 'Move')} -Headers @{'X-Api-Key'='4dd3cc179te04d15kt9288313d8d21087d'}
:idea: Does not use any "..." so you can use --def exec="..." without having to escape "..." characters.

:idea: Does use groovy.json.JsonOutput to generate valid json text.

:idea: You'll want to print the response as well, so read this https://stackoverflow.com/a/40703109/1514467 and modify the command accordingly.
:idea: Please read the FAQ and How to Request Help.
KRONZO
Posts: 30
Joined: 31 Dec 2017, 23:20

Re: filebot and sonarr import again

Post by KRONZO »

Thank you a lot for your help on this.
I tried this

Code: Select all

Invoke-RestMethod -Uri 'http://localhost:2587/api/command' -Method Post -Body {quote groovy.json.JsonOutput.toJson(name: 'downloadedepisodesscan', path: f.path , importMode: 'Move')} -Headers @{'X-Api-Key'='4dd3cc179te04d15kt9288313d8d21087d'}
unfortunately it gave an error in both powershell and sonarr
powershell.
Execute: D:\testmedia\sonarrimport.ps1 @'
D:\tempdir\judge.judy.s23e10.when.the.marine.is.away.the.gun.is.in.play.he.likes.it.hot.720p.hdtv.x264-w4f\judge.judy.s23e10.when.the.marine.is.away.the.gun.is.in.play.he.likes.it.hot.720p.hdtv.x264-w4f.mkv
'@
Invoke-RestMethod : The remote server returned an error: (500) Internal Server Error.
At D:\testmedia\sonarrimport.ps1:1 char:1
+ Invoke-RestMethod -Uri 'http://localhost:9595/api/command' -Method Po ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebExc
eption
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
and in sonarr
Request Failed. POST /api/command: Unexpected character encountered while parsing value: q. Path '', line 0, position 0. (Json snippet '<--error-->quote groovy.json.Js')
exeption
Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: q. Path '', line 0, position 0. (Json snippet '<--error-->quote groovy.json.Js') ---> Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: q. Path '', line 0, position 0.
at Newtonsoft.Json.JsonTextReader.ParseValue()
at Newtonsoft.Json.JsonTextReader.Read()
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ReadForType(JsonReader reader, JsonContract contract, Boolean hasConverter)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
at NzbDrone.Common.Serializer.Json.Deserialize(String json, Type type) in C:\BuildAgent\work\5d7581516c0ee5b3\src\NzbDrone.Common\Serializer\Json.cs:line 52
--- End of inner exception stack trace ---
at NzbDrone.Common.Serializer.Json.Deserialize(String json, Type type) in C:\BuildAgent\work\5d7581516c0ee5b3\src\NzbDrone.Common\Serializer\Json.cs:line 56
at NzbDrone.Api.Extensions.ReqResExtensions.FromJson(Stream body, Type type) in C:\BuildAgent\work\5d7581516c0ee5b3\src\NzbDrone.Api\Extensions\ReqResExtensions.cs:line 31
at NzbDrone.Api.Extensions.ReqResExtensions.FromJson[T](Stream body, Type type) in C:\BuildAgent\work\5d7581516c0ee5b3\src\NzbDrone.Api\Extensions\ReqResExtensions.cs:line 24
at NzbDrone.Api.Extensions.ReqResExtensions.FromJson[T](Stream body) in C:\BuildAgent\work\5d7581516c0ee5b3\src\NzbDrone.Api\Extensions\ReqResExtensions.cs:line 19
at NzbDrone.Api.REST.RestModule`1.ReadResourceFromRequest(Boolean skipValidate) in C:\BuildAgent\work\5d7581516c0ee5b3\src\NzbDrone.Api\REST\RestModule.cs:line 188
at NzbDrone.Api.REST.RestModule`1.<set_CreateResource>b__41_0(Object options) in C:\BuildAgent\work\5d7581516c0ee5b3\src\NzbDrone.Api\REST\RestModule.cs:line 155
at CallSite.Target(Closure , CallSite , Func`2 , Object )
at Nancy.Routing.Route.<>c__DisplayClass4.<Wrap>b__3(Object parameters, CancellationToken context)
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: filebot and sonarr import again

Post by rednoah »

rednoah wrote: 18 Oct 2018, 09:45 Does not use any "..." so you can use --def exec="..." without having to escape "..." characters.
rednoah wrote: 18 Oct 2018, 09:45 You'll want to print the response as well, so read this https://stackoverflow.com/a/40703109/1514467 and modify the command accordingly.

YES:

Code: Select all

filebot ... --def exec="Invoke-RestMethod -Uri 'http://localhost:2587/api/command' -Method Post -Body {quote groovy.json.JsonOutput.toJson(name: 'downloadedepisodesscan', path: f.path , importMode: 'Move')} -Headers @{'X-Api-Key'='4dd3cc179te04d15kt9288313d8d21087d'} | Select-Object -Expand Content"
:idea: We avoid using PS1 scripts because neither of us is any good at writing PS1 scripts. :lol:


NO:

Code: Select all

filebot ... --def exec="D:\testmedia\sonarrimport.ps1 {quote f}"
:idea: The problem isn't FileBot. The problem is not knowing how to write PS1 scripts, therefore encapsulating all the tricky parts in the PS1 script ain't exactly a good idea.
:idea: Please read the FAQ and How to Request Help.
KRONZO
Posts: 30
Joined: 31 Dec 2017, 23:20

Re: filebot and sonarr import again

Post by KRONZO »

I thank you again
(also for the laugh)
:idea: We avoid using PS1 scripts because neither of us is any good at writing PS1 scripts. :lol:
this time it gives an filebot error regarding api key
SyntaxError:
[X-Api-Key] is a constant expression, but it should be a variable expression at line: 1 column: 12. File: Script3.groovy
javax.script.ScriptException: SyntaxError:
[X-Api-Key] is a constant expression, but it should be a variable expression at line: 1 column: 12. File: Script3.groovy
at net.filebot.format.ExpressionFormat.compile(ExpressionFormat.java:85)
at net.filebot.format.ExpressionFormat.<init>(ExpressionFormat.java:43)
at net.filebot.cli.ScriptShellBaseClass.getMediaInfo(ScriptShellBaseClass.java:237)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at Script1$_run_closure56.doCall(Script1.groovy:526)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at Script1.run(Script1.groovy:526)
at net.filebot.cli.ScriptShell.evaluate(ScriptShell.java:64)
at net.filebot.cli.ScriptShell.runScript(ScriptShell.java:74)
at net.filebot.cli.ArgumentProcessor.runScript(ArgumentProcessor.java:154)
at net.filebot.cli.ArgumentProcessor.run(ArgumentProcessor.java:36)
at net.filebot.Main.main(Main.java:127)

Failure (°_°)
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: filebot and sonarr import again

Post by rednoah »

We learn that FileBot is interpreting the @{key=value} bit because FileBot by design interprets {...} bits as Groovy code.

Therefore we apply some trickery and write Groovy code that prints PS1 code:

Code: Select all

-Headers { /@{'X-Api-Key'='4dd3cc179te04d15kt9288313d8d21087d'}/ }
:idea: Please read the FAQ and How to Request Help.
KRONZO
Posts: 30
Joined: 31 Dec 2017, 23:20

Re: filebot and sonarr import again

Post by KRONZO »

I'm sorry now we are back to the path problem again ;(

Sonarr
Request Failed. POST /api/command: Unexpected character encountered while parsing value: d. Path 'name', line 1, position 7. (Json snippet '{name:d<--error-->ownloadedepisodessca')

Code: Select all

Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: d. Path 'name', line 1, position 7. (Json snippet '{name:d<--error-->ownloadedepisodessca') ---> Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: d. Path 'name', line 1, position 7.
   at Newtonsoft.Json.JsonTextReader.ReadStringValue(ReadType readType)
   at Newtonsoft.Json.JsonTextReader.ReadAsString()
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ReadForType(JsonReader reader, JsonContract contract, Boolean hasConverter)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
   at NzbDrone.Common.Serializer.Json.Deserialize(String json, Type type) in C:\BuildAgent\work\5d7581516c0ee5b3\src\NzbDrone.Common\Serializer\Json.cs:line 52
   --- End of inner exception stack trace ---
   at NzbDrone.Common.Serializer.Json.Deserialize(String json, Type type) in C:\BuildAgent\work\5d7581516c0ee5b3\src\NzbDrone.Common\Serializer\Json.cs:line 56
   at NzbDrone.Api.Extensions.ReqResExtensions.FromJson(Stream body, Type type) in C:\BuildAgent\work\5d7581516c0ee5b3\src\NzbDrone.Api\Extensions\ReqResExtensions.cs:line 31
   at NzbDrone.Api.Extensions.ReqResExtensions.FromJson[T](Stream body, Type type) in C:\BuildAgent\work\5d7581516c0ee5b3\src\NzbDrone.Api\Extensions\ReqResExtensions.cs:line 24
   at NzbDrone.Api.Extensions.ReqResExtensions.FromJson[T](Stream body) in C:\BuildAgent\work\5d7581516c0ee5b3\src\NzbDrone.Api\Extensions\ReqResExtensions.cs:line 19
   at NzbDrone.Api.REST.RestModule`1.ReadResourceFromRequest(Boolean skipValidate) in C:\BuildAgent\work\5d7581516c0ee5b3\src\NzbDrone.Api\REST\RestModule.cs:line 188
   at NzbDrone.Api.REST.RestModule`1.<set_CreateResource>b__41_0(Object options) in C:\BuildAgent\work\5d7581516c0ee5b3\src\NzbDrone.Api\REST\RestModule.cs:line 155
   at CallSite.Target(Closure , CallSite , Func`2 , Object )
   at Nancy.Routing.Route.<>c__DisplayClass4.<Wrap>b__3(Object parameters, CancellationToken context)

Code: Select all

Invoke-RestMethod : The remote server returned an error: (500) Internal Server Error.
At line:1 char:1
+ Invoke-RestMethod -Uri 'http://localhost:9595/api/command' -Method Po ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: filebot and sonarr import again

Post by rednoah »

So what's the command that is executed?

The Execute part of the log will tell us more:

Code: Select all

Execute: <the command that is executed>
:?: Check if the json structure we send is the json structure sonarr expects.
:idea: Please read the FAQ and How to Request Help.
KRONZO
Posts: 30
Joined: 31 Dec 2017, 23:20

Re: filebot and sonarr import again

Post by KRONZO »

ok now you are asking me to work for my food ;) I will enable the log and be back
KRONZO
Posts: 30
Joined: 31 Dec 2017, 23:20

Re: filebot and sonarr import again

Post by KRONZO »

Code: Select all

Execute: Invoke-RestMethod -Uri 'http://localhost:9595/api/command' -Method Post -Body @'
{"name":"downloadedepisodesscan","path":"D:\\tempdir\\judge.judy.s23e10.when.the.marine.is.away.the.gun.is.in.play.he.likes.it.hot.720p.hdtv.x264-w4f\\judge.judy.s23e10.when.the.marine.is.away.the.gun.is.in.play.he.likes.it.hot.720p.hdtv.x264-w4f.mkv","importMode":"Move"}
'@ -Headers @{'X-Api-Key'='4dd3cc179fe04d7313d8d21087d'} | Select-Object -Expand Content
Execute: Invoke-RestMethod -Uri 'http://localhost:9595/api/command' -Method Post -Body @'
{"name":"downloadedepisodesscan","path":"D:\\tempdir\\judge.judy.s23e11.oh.how.i.wish.i.hadnt.taken.that.nude.photo.of.myself.720p.hdtv.x264-w4f\\judge.judy.s23e11.oh.how.i.wish.i.hadnt.taken.that.nude.photo.of.myself.720p.hdtv.x264-w4f.mkv","importMode":"Move"}
'@ -Headers @{'X-Api-Key'='4dd3cc179fe04d78928d8d21087d'} | Select-Object -Expand Content
Execute: Invoke-RestMethod -Uri 'http://localhost:9595/api/command' -Method Post -Body @'
{"name":"downloadedepisodesscan","path":"D:\\tempdir\\Movies\\The Spy Who Dumped Me (2018)\\The Spy Who Dumped Me (2018).mkv","importMode":"Move"}
'@ -Headers @{'X-Api-Key'='4dd3ccd789288313d8h456454hp5d21087d'} | Select-Object -Expand Content
the execute part of the log I can't see anything wrong, but why would I :lol: i'm not very good at this
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: filebot and sonarr import again

Post by rednoah »

Looks good to me. Json Formatter says it's VALID JSON. So that means Sonarr fails to parse valid json, which means you'll need to go to the Sonarr forums, report this as a bug, and ask for a fix or a workaround.
:idea: Please read the FAQ and How to Request Help.
KRONZO
Posts: 30
Joined: 31 Dec 2017, 23:20

Re: filebot and sonarr import again

Post by KRONZO »

fair enough.
thank you for your excellent Support, I am very grateful for all your help
KRONZO
Posts: 30
Joined: 31 Dec 2017, 23:20

Re: filebot and sonarr import again

Post by KRONZO »

hi Again
i'm hoping for one more try ;)
the guys over at sonarr says it will work if i only pass the folder name and not the file, is this possible ?
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: filebot and sonarr import again

Post by rednoah »

Sure, replace f.path with folder.path in your --def exec expression.
:idea: Please read the FAQ and How to Request Help.
KRONZO
Posts: 30
Joined: 31 Dec 2017, 23:20

Re: filebot and sonarr import again

Post by KRONZO »

jesus christ ;)
thank you I would have started to mess around with the quote f

;D
ZeroByDivide
Posts: 170
Joined: 16 Dec 2014, 01:39

Re: filebot and sonarr import again

Post by ZeroByDivide »

If you would like, I've created an import script for sonarr and radarr a while back with the help from rednoah and it works wonders.

You can find it here https://github.com/JourneyOver/filebot

File is called "Update_Sonarr_Radarr.groovy", just download said file then go in and edit the "PLACEAPIKEYHERE" bit with your API. If you don't want to use radarr bit for the script you can either comment it out or just remove it entirely up to you.

Executive call you'd place in your normal filebot script to call said import script would be "exec=filebot -script /path/to/Update_Sonarr_Radarr.groovy --def type={type} id={id}"
Muddro
Posts: 33
Joined: 22 Mar 2014, 21:38

Re: filebot and sonarr import again

Post by Muddro »

ZeroByDivide wrote: 26 Oct 2018, 19:23 If you would like, I've created an import script for sonarr and radarr a while back with the help from rednoah and it works wonders.

You can find it here https://github.com/JourneyOver/filebot

File is called "Update_Sonarr_Radarr.groovy", just download said file then go in and edit the "PLACEAPIKEYHERE" bit with your API. If you don't want to use radarr bit for the script you can either comment it out or just remove it entirely up to you.

Executive call you'd place in your normal filebot script to call said import script would be "exec=filebot -script /path/to/Update_Sonarr_Radarr.groovy --def type={type} id={id}"
Can you emxplain to me how this works? I have been going nuts trying to find a solution for rar'd files and sonarr/radarr. Do I need to mess with the extraction location in my amc script?
ZeroByDivide
Posts: 170
Joined: 16 Dec 2014, 01:39

Re: filebot and sonarr import again

Post by ZeroByDivide »

Muddro wrote: 31 Jan 2019, 18:54
ZeroByDivide wrote: 26 Oct 2018, 19:23 If you would like, I've created an import script for sonarr and radarr a while back with the help from rednoah and it works wonders.

You can find it here https://github.com/JourneyOver/filebot

File is called "Update_Sonarr_Radarr.groovy", just download said file then go in and edit the "PLACEAPIKEYHERE" bit with your API. If you don't want to use radarr bit for the script you can either comment it out or just remove it entirely up to you.

Executive call you'd place in your normal filebot script to call said import script would be "exec=filebot -script /path/to/Update_Sonarr_Radarr.groovy --def type={type} id={id}"
Can you emxplain to me how this works? I have been going nuts trying to find a solution for rar'd files and sonarr/radarr. Do I need to mess with the extraction location in my amc script?
Sent you a PM explaining on how to set things up. Sorry I didn't really set up a readme or anything to explain really on the repository. I'll eventually get one set up, but time right now is kinda not on my side becuase I'm busy trying to find a job/place to live due to both my parents passing away this month and other irl circumstances going on.
Muddro
Posts: 33
Joined: 22 Mar 2014, 21:38

Re: filebot and sonarr import again

Post by Muddro »

ZeroByDivide wrote: 01 Feb 2019, 00:39
Muddro wrote: 31 Jan 2019, 18:54
ZeroByDivide wrote: 26 Oct 2018, 19:23 If you would like, I've created an import script for sonarr and radarr a while back with the help from rednoah and it works wonders.

You can find it here https://github.com/JourneyOver/filebot

File is called "Update_Sonarr_Radarr.groovy", just download said file then go in and edit the "PLACEAPIKEYHERE" bit with your API. If you don't want to use radarr bit for the script you can either comment it out or just remove it entirely up to you.

Executive call you'd place in your normal filebot script to call said import script would be "exec=filebot -script /path/to/Update_Sonarr_Radarr.groovy --def type={type} id={id}"
Can you emxplain to me how this works? I have been going nuts trying to find a solution for rar'd files and sonarr/radarr. Do I need to mess with the extraction location in my amc script?
Sent you a PM explaining on how to set things up. Sorry I didn't really set up a readme or anything to explain really on the repository. I'll eventually get one set up, but time right now is kinda not on my side becuase I'm busy trying to find a job/place to live due to both my parents passing away this month and other irl circumstances going on.
Thanks. Just came back here, but had it working. Very much appreciate the hard work you put into this. I do have a question though on a possible modification. Currently this works fine but is limited to one instance of radarr and sonarr. Some people run a second instance of each for 4k stuff. Is there a way to have it trigger for normal stuff a certain instance of sonarr, and another for 4k items?
ZeroByDivide
Posts: 170
Joined: 16 Dec 2014, 01:39

Re: filebot and sonarr import again

Post by ZeroByDivide »

Muddro wrote: 03 Feb 2019, 20:30
ZeroByDivide wrote: 01 Feb 2019, 00:39
Muddro wrote: 31 Jan 2019, 18:54

Can you emxplain to me how this works? I have been going nuts trying to find a solution for rar'd files and sonarr/radarr. Do I need to mess with the extraction location in my amc script?
Sent you a PM explaining on how to set things up. Sorry I didn't really set up a readme or anything to explain really on the repository. I'll eventually get one set up, but time right now is kinda not on my side becuase I'm busy trying to find a job/place to live due to both my parents passing away this month and other irl circumstances going on.
Thanks. Just came back here, but had it working. Very much appreciate the hard work you put into this. I do have a question though on a possible modification. Currently this works fine but is limited to one instance of radarr and sonarr. Some people run a second instance of each for 4k stuff. Is there a way to have it trigger for normal stuff a certain instance of sonarr, and another for 4k items?
Sent you another PM, hopefully it works for you but I'm not sure. :s
terxw
Posts: 2
Joined: 13 Mar 2019, 08:16

Re: filebot and sonarr import again

Post by terxw »

Sorry to bother you ZeroByDivide

I am tryind to use your script but i get this error:

Code: Select all

Processed 1 files
Execute: filebot -script ./Update_Sonarr_Radarr.groovy --def type=Movie id=338952

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.reflection.CachedConstructor$1 (file:/usr/share/filebot/jar/groovy.jar) to constructor java.nio.HeapByteBuffer(byte[],int,int,int,int,int)
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.reflection.CachedConstructor$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
Cannot get property 'id' on null object
java.lang.NullPointerException: Cannot get property 'id' on null object
        at Script1.run(Script1.groovy:35)
        at net.filebot.cli.ScriptShell.evaluate(ScriptShell.java:64)
        at net.filebot.cli.ScriptShell.runScript(ScriptShell.java:74)
        at net.filebot.cli.ArgumentProcessor.runScript(ArgumentProcessor.java:154)
        at net.filebot.cli.ArgumentProcessor.run(ArgumentProcessor.java:36)
        at net.filebot.Main.main(Main.java:131)

Failure (°_°)
My cmd is

Code: Select all

export SCRIPT_DIR="."
--def "exec=filebot -script $SCRIPT_DIR/Update_Sonarr_Radarr.groovy --def type={type} id={id}"
what could be problem?

Thank for your script!
ZeroByDivide
Posts: 170
Joined: 16 Dec 2014, 01:39

Re: filebot and sonarr import again

Post by ZeroByDivide »

terxw wrote: 16 Mar 2019, 15:01 Sorry to bother you ZeroByDivide

I am tryind to use your script but i get this error:

Code: Select all

Processed 1 files
Execute: filebot -script ./Update_Sonarr_Radarr.groovy --def type=Movie id=338952

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.reflection.CachedConstructor$1 (file:/usr/share/filebot/jar/groovy.jar) to constructor java.nio.HeapByteBuffer(byte[],int,int,int,int,int)
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.reflection.CachedConstructor$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
Cannot get property 'id' on null object
java.lang.NullPointerException: Cannot get property 'id' on null object
        at Script1.run(Script1.groovy:35)
        at net.filebot.cli.ScriptShell.evaluate(ScriptShell.java:64)
        at net.filebot.cli.ScriptShell.runScript(ScriptShell.java:74)
        at net.filebot.cli.ArgumentProcessor.runScript(ArgumentProcessor.java:154)
        at net.filebot.cli.ArgumentProcessor.run(ArgumentProcessor.java:36)
        at net.filebot.Main.main(Main.java:131)

Failure (°_°)
My cmd is

Code: Select all

export SCRIPT_DIR="."
--def "exec=filebot -script $SCRIPT_DIR/Update_Sonarr_Radarr.groovy --def type={type} id={id}"
what could be problem?

Thank for your script!
Are you just calling my script and not doing a full filebot command with the AMC script and such? I'd need to see your full filebot command, along with a full log otherwise I can't really see exactly what it is that you are doing wrong as right now it just looks like you are just calling my script alone which I don't think will work exactly (never tried though so I can't say for sure if it would or not be able to be standalone), you would need to append the

Code: Select all

--def "exec=filebot -script /path/to/Update_Sonarr_Radarr.groovy --def type={type} id={id}"
to the end of a normal filebot command that is using things like the amc script.

Example:

Code: Select all

filebot -script fn:amc --output "X:/Media" --action duplicate --conflict skip -non-strict --log-file amc.log --def unsorted=y music=y artwork=y "ut_label=%L" "ut_state=%S" "ut_title=%N" "ut_kind=%K" "ut_file=%F" "ut_dir=%D" --def "exec=filebot -script /path/to/Update_Sonarr_Radarr.groovy --def type={type} id={id}"
Also make sure that you are going in the Update_Sonarr_Radarr.groovy script, and replacing the "PLACEAPIKEYHERE" bits with your the APIs for your sonarr / radarr, and if you are running behind a url base you need to edit lines 13 and 20 for sonarr / 35 and 42 for radarr.

I'm going to eventually set up a readme on my repository, but I just haven't had the time to really do it as I've been pretty busy IRL and when I do have time I'm usually busy working on something else.
terxw
Posts: 2
Joined: 13 Mar 2019, 08:16

Re: filebot and sonarr import again

Post by terxw »

ZeroByDivide wrote: 19 Mar 2019, 03:57

Are you just calling my script and not doing a full filebot command with the AMC script and such? I'd need to see your full filebot command, along with a full log otherwise I can't really see exactly what it is that you are doing wrong as right now it just looks like you are just calling my script alone which I don't think will work exactly (never tried though so I can't say for sure if it would or not be able to be standalone), you would need to append the

Code: Select all

--def "exec=filebot -script /path/to/Update_Sonarr_Radarr.groovy --def type={type} id={id}"
to the end of a normal filebot command that is using things like the amc script.

Example:

Code: Select all

filebot -script fn:amc --output "X:/Media" --action duplicate --conflict skip -non-strict --log-file amc.log --def unsorted=y music=y artwork=y "ut_label=%L" "ut_state=%S" "ut_title=%N" "ut_kind=%K" "ut_file=%F" "ut_dir=%D" --def "exec=filebot -script /path/to/Update_Sonarr_Radarr.groovy --def type={type} id={id}"
Also make sure that you are going in the Update_Sonarr_Radarr.groovy script, and replacing the "PLACEAPIKEYHERE" bits with your the APIs for your sonarr / radarr, and if you are running behind a url base you need to edit lines 13 and 20 for sonarr / 35 and 42 for radarr.

I'm going to eventually set up a readme on my repository, but I just haven't had the time to really do it as I've been pretty busy IRL and when I do have time I'm usually busy working on something else.
Thank you for your time!

Yes I am calling the exec after full filebot with amc script command, action, hardlink, movie identification are alright, just the exec part fails

I am running transmission and filebot in docker .

Code: Select all

SCRIPT_DIR="/data/transmission-home/"
CONFIG_OUTPUT="/data/storage/Movies/_sorted"

ACTION="HARDLINK"                                                                                                                                                                                                                         
                                                                                                                                                                                                                                           
LAN="EN"                                                                                                                                                                                                                                  
#                                                                                                                                                                                                                                         
LANS="EN" 
export DISPLAY="";                                                                                                                                                                                                                        
/usr/bin/filebot  -script fn:amc --output  "$CONFIG_OUTPUT" -non-strict --conflict SKIP --db TheMovieDB --lang sk --action "$ACTION" --encoding UTF-8 --log all --log-file "$LOG"  --def "excludeList=amc7.txt" --def "subtitles=en,cs,sk" "artwork=n" "clean=y" "unsorted=n" "extras=y" "storeReport=y" --def "movieFormat=Movies/{localize.cs.n} - {primaryTitle} ({y}) {vf} {vc} {ac} {any{media.AudioLanguageList.ISO3.upper()}{fn.matchAll(/(CZ|cz|cse|CZECH|Czech)/) ? ' CZ' : '' }{fn.matchAll(/(SK|SVK|svk|Slovak|Sk)/) ? ' SK' : '' }}/{primaryTitle} ({y}) {vf} {vc} {ac} {any{media.AudioLanguageList.ISO3.upper()}{fn.matchAll(/(CZ|cz|cse|CZECH|Czech)/) ? ' CZ' : '' }{fn.matchAll(/(SK|SVK|svl|Slovak|Sk)/) ? ' SK' : '' }} ({fn.replaceAll(/[:]+$/, ' - ').upperInitial()})" --def "seriesFormat=TV/{localize.cs.n} ({primaryTitle}) {any{media.AudioLanguageList.ISO3.upper()}{fn.matchAll(/(CZ|cz|cse|CZECH|Czech)/) ? ' CZ' : '' }{fn.matchAll(/(SK|SVK|svk|Slovak|Sk)/) ? ' SK' : '' }{'$LANS'}}/{episode.special ? {localize.cs.n}+' - Specials' : {localize.cs.n}+' - Season '+s.pad(2)}/{localize.cs.n} - {episode.special ? 'S00E'+special.pad(2) : s00e00} - {t} {any{media.AudioLanguageList.ISO3.upper()}{fn.matchAll(/(CZ|cz|cse|CZECH|Czech)/) ? ' CZ' : '' }{fn.matchAll(/(SK|SVK|svk|Slovak|Sk)/) ? ' SK' : '' }{'$LANS'}}{'.'+lang}" --def "ut_dir=$ARG_PATH" "ut_kind=multi" --def "exec=filebot -script $SCRIPT_DIR/Update_Sonarr_Radarr.groovy --def type={type} id={id}"



Filebot log

Code: Select all

Run script [fn:amc] at [Thu Mar 21 19:15:32 UTC 2019]
Parameter: excludeList = amc.txt
Parameter: subtitles = en,cs,sk
Parameter: artwork = n
Parameter: clean = y
Parameter: unsorted = n
Parameter: extras = y
Parameter: storeReport = y
Parameter: movieFormat = Movies/{localize.cs.n} - {primaryTitle} ({y}) {vf} {vc} {ac} {any{media.AudioLanguageList.ISO3.upper()}{fn.matchAll(/(CZ|cz|cse|CZECH|Czech)/) ? ' CZ' : '' }{fn.matchAll(/(SK|SVK|svk|Slovak|Sk)/) ? ' SK' : '' }}/{primaryTitle} ({y}) {vf} {vc} {ac} {any{media.AudioLanguageList.ISO3.upper()}{fn.matchAll(/(CZ|cz|cse|CZECH|Czech)/) ? ' CZ' : '' }{fn.matchAll(/(SK|SVK|svl|Slovak|Sk)/) ? ' SK' : '' }} ({fn.replaceAll(/[:]+$/, ' - ').upperInitial()})
Parameter: seriesFormat = TV/{localize.cs.n} ({primaryTitle}) {any{media.AudioLanguageList.ISO3.upper()}{fn.matchAll(/(CZ|cz|cse|CZECH|Czech)/) ? ' CZ' : '' }{fn.matchAll(/(SK|SVK|svk|Slovak|Sk)/) ? ' SK' : '' }{'EN'}}/{episode.special ? {localize.cs.n}+' - Specials' : {localize.cs.n}+' - Season '+s.pad(2)}/{localize.cs.n} - {episode.special ? 'S00E'+special.pad(2) : s00e00} - {t} {any{media.AudioLanguageList.ISO3.upper()}{fn.matchAll(/(CZ|cz|cse|CZECH|Czech)/) ? ' CZ' : '' }{fn.matchAll(/(SK|SVK|svk|Slovak|Sk)/) ? ' SK' : '' }{'EN'}}{'.'+lang}
Parameter: ut_dir = /data/storage/pve/Downloads/completed/McQueen.2018.BDrip.AAC.1080p.x264-VINEnc.mp4
Parameter: ut_kind = multi
Parameter: ut_title = McQueen.2018.BDrip.AAC.1080p.x264-VINEnc.mp4
Parameter: ut_label = N/A
Parameter: exec = filebot -script /data/transmission-home/Update_Sonarr_Radarr.groovy --def type={type} id={id}
Use excludes: /data/storage/Movies/_sorted/amc7.txt (2)
Input: /data/storage/pve/Downloads/completed/McQueen.2018.BDrip.AAC.1080p.x264-VINEnc.mp4
xattr: [McQueen.2018.BDrip.AAC.1080p.x264-VINEnc.mp4] => [McQueen (2018)]
Group: [mov:mcqueen 2018] => [McQueen.2018.BDrip.AAC.1080p.x264-VINEnc.mp4]
Get [English] subtitles for 1 files
Looking up subtitles by hash via OpenSubtitles
No matching subtitles found: /data/storage/pve/Downloads/completed/McQueen.2018.BDrip.AAC.1080p.x264-VINEnc.mp4
Get [Czech] subtitles for 1 files
Looking up subtitles by hash via OpenSubtitles
No matching subtitles found: /data/storage/pve/Downloads/completed/McQueen.2018.BDrip.AAC.1080p.x264-VINEnc.mp4
Get [Slovak] subtitles for 1 files
Looking up subtitles by hash via OpenSubtitles
No matching subtitles found: /data/storage/pve/Downloads/completed/McQueen.2018.BDrip.AAC.1080p.x264-VINEnc.mp4
Rename movies using [TheMovieDB]
Auto-detect movie from context: [/data/storage/pve/Downloads/completed/McQueen.2018.BDrip.AAC.1080p.x264-VINEnc.mp4]
[HARDLINK] from [/data/storage/pve/Downloads/completed/McQueen.2018.BDrip.AAC.1080p.x264-VINEnc.mp4] to [/data/storage/Movies/_sorted/Movies/McQueen - McQueen (2018) 1080p x264 AAC/McQueen (2018) 1080p x264 AAC (McQueen.2018.BDrip.AAC.1080p.X264-VI
NEnc).mp4]
Processed 1 files
Execute: filebot -script /data/transmission-home/Update_Sonarr_Radarr.groovy --def type=Movie id=508003

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.reflection.CachedConstructor$1 (file:/usr/share/filebot/jar/groovy.jar) to constructor java.nio.HeapByteBuffer(byte[],int,int,int,int,int)
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.reflection.CachedConstructor$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
Cannot get property 'id' on null object
java.lang.NullPointerException: Cannot get property 'id' on null object
        at Script1.run(Script1.groovy:35)
        at net.filebot.cli.ScriptShell.evaluate(ScriptShell.java:64)
        at net.filebot.cli.ScriptShell.runScript(ScriptShell.java:74)
        at net.filebot.cli.ArgumentProcessor.runScript(ArgumentProcessor.java:154)
        at net.filebot.cli.ArgumentProcessor.run(ArgumentProcessor.java:36)
        at net.filebot.Main.main(Main.java:131)

Failure (°_°)
Saving report as /home/kangus/.filebot/reports/2019-03-21_21_37_McQueen_2018_BDrip_AAC_1080p_x264-VINEnc.html
Done ヾ(@⌒ー⌒@)ノ
Here is my Update_Sonarr_Radarr.groovy script

Code: Select all

// TVDB/TMDB ID                                                                                                                                                                                                                            
def id = id as int                                                                                                                                                                                                                         
                                                                                                                                                                                                                                           
// Video Type                                                                                                                                                                                                                              
def type = type                                                                                                                                                                                                                            
                                                                                                                                                                                                                                           
// Sonarr API Configuration                                                                                                                                                                                                                
if (type =~ /Episode/) {                                                                                                                                                                                                                   
    def url = new URL('http://IPADDRES:9015')                                                                                                                                                                                          
    def header = ['X-Api-Key': '11111111111111111111']                                                                                                                                                                         
                                                                                                                                                                                                                                           
    def sonarrSeriesId = new JsonSlurper()                                                                                                                                                                                                 
        .parseText(new URL(url, '/api/series')                                                                                                                                                                                             
            .get(header)                                                                                                                                                                                                                   
            .text)                                                                                                                                                                                                                         
        .find {                                                                                                                                                                                                                            
            it.tvdbId == id                                                                                                                                                                                                                
        }.id                                                                                                                                                                                                                               
                                                                                                                                                                                                                                           
    println new URL(url, '/api/command').post(                                                                                                                                                                                             
        JsonOutput.toJson(                                                                                                                                                                                                                 
            [name: 'rescanSeries', seriesId: sonarrSeriesId]                                                                                                                                                                               
        ).getBytes('UTF-8'),                                                                                                                                                                                                               
        'application/json',                                                                                                                                                                                                                
        header                                                                                                                                                                                                                             
    ).text                                                                                                                                                                                                                                 
}                                                                                                                                                                                                                                          
                                                                                                                                                                                                                                           
// Radarr API Configuration                                                                                                                                                                                                                
if (type =~ /Movie/) {                                                                                                                                                                                                                     
    def url = new URL('http://IPADDRESS:9014')                                                                                                                                                                                          
    def header = ['X-Api-Key': '111111111111111111111111']                                                                                                                                                                         
                                                                                                                                                                                                                                           
    def radarrMovieId = new JsonSlurper()                                                                                                                                                                                                  
        .parseText(new URL(url, '/api/movie')                                                                                                                                                                                              
            .get(header)                                                                                                                                                                                                                   
            .text)                                                                                                                                                                                                                         
        .find {                                                                                                                                                                                                                            
            it.tmdbId == id                                                                                                                                                                                                                
        }.id                                                                                                                                                                                                                               
                                                                                                                                                                                                                                           
    println new URL(url, '/api/command').post(                                                                                                                                                                                             
        JsonOutput.toJson(                                                                                                                                                                                                                 
            [name: 'rescanMovie', movieId: radarrMovieId]                                                                                                                                                                                  
        ).getBytes('UTF-8'),                                                                                                                                                                                                               
        'application/json',                                                                                                                                                                                                                
        header                                                                                                                                                                                                                             
    ).text                                                                                                                                                                                                                                 
} 
Post Reply