Jump to content

Emby Connect API/Radarr


fizzyade

Recommended Posts

 

 

2019-08-17 16:43:25.341 Info HttpServer: HTTP POST http://emby-server:8096/mediabrowser/Library/Media/Updated. UserAgent: curl/7.58.0

2019-08-17 16:43:25.354 Debug LibraryMonitor: New file refresher created for /movies/Scary Movie 3 (2003)

 

That looks good, right?

Link to comment
Share on other sites

  • 3 months later...
stuartgib

I've converted fizzyade's bash script into a powershell script for anyone else running sonarr/radarr on their windows pc and emby on a separate nas.

#! /usr/bin/pwsh
 
#EMBY
$apiKey = "<your emby api key>"
$url = "http://<emby server ip>:8096"
#PATHS
$local_tv_path = [regex]::escape("\\UNC\Media\TV Shows\")
$local_movie_path = [regex]::escape("\\UNC\Media\Movies\")
$remote_tv_path = "/volume1/Media/TV Shows/"
$remote_movie_path = "/volume1/Media/Movies/"
#SONARR
$sonarr_episodefile_path = $env:sonarr_episodefile_path
$sonarr_series_path = $env:sonarr_series_path
$sonarr_eventtype = $env:sonarr_eventtype
#RADARR
$radarr_moviefile_path = $env:radarr_moviefile_path
$radarr_movie_path = $env:radarr_movie_path
$radarr_eventtype = $env:radarr_eventtype

IF ([string]::IsNullOrWhitespace($apiKey)){

      '*******************************'

      '* Error: No API Key specified.*'

      '*******************************'

      exit

}

IF ([string]::IsNullOrWhitespace($url)){

      '********************************'

      '* Error: No Emby URL specified.*'

      '********************************'

      exit

}

IF ([string]::IsNullOrWhitespace($sonarr_eventtype) -and [string]::IsNullOrWhitespace($radarr_eventtype)){

      '******************************************************************'

      '* Error: Must be called as a custom script from Sonarr or Radarr.*'

      '******************************************************************'

      exit

}

#SONARR
if($sonarr_eventtype -eq 'Download' -or $sonarr_eventtype -eq 'Upgrade') {
   $UpdateType = "Series"
   $path = $sonarr_episodefile_path -replace $local_tv_path #strips the local tv path from the path
   $path = $path -replace "\\", "/" #substitutes back slashes with forward slashes to convert to uri format
   $path = $remote_tv_path + $path #adds the remote tv path to the uri
   #$path = $path -replace " ", "%20" #substitutes spaces with %20
}elseif($sonarr_eventtype -eq "Rename") {
   $UpdateType = "Series"
   $path = $sonarr_series_path -replace $local_tv_path
   $path = $path -replace "\\", "/"
   $path = $remote_tv_path + $path
   #$path = $path -replace " ", "%20"
}elseif($sonarr_eventtype -eq "Test") {
   exit
}elseif($radarr_eventtype -eq 'Download' -or $radarr_eventtype -eq 'Upgrade') {
   $UpdateType = "Movie"
   $path = $radarr_moviefile_path -replace $local_movie_path
   $path = $path -replace "\\", "/"
   $path = $remote_movie_path + $path
   #$path = $path -replace " ", "%20"h
}elseif($radarr_eventtype -eq "Rename") {
   $UpdateType = "Movie"
   $path = $radarr_movie_path -replace $local_movie_path
   $path = $path -replace "\\", "/"
   $path = $remote_movie_path + $path
   #$path = $path -replace " ", "%20"
}elseif($radarr_eventtype -eq "Test") {
   exit
}else {
#   $UpdateType = $null
}

$postparams = '{"Updates":[{"Path":"' + $path + '","UpdateType":"' + $UpdateType + '"}]}'


Invoke-WebRequest -uri "$url/emby/Library/Media/Updated?api_key=$apiKey" -ContentType "application/json" -Method POST -body $postparams

 

Edited by stuartgib
  • Like 1
Link to comment
Share on other sites

fizzyade
16 hours ago, stuartgib said:

I've converted fizzyade's bash script into a powershell script for anyone else running sonarr/radarr on their windows pc and emby on a separate nas.

 

Awesome.  Hopefully others will find it useful.

Link to comment
Share on other sites

  • 4 weeks later...
On 8/21/2020 at 9:29 PM, stuartgib said:

I've converted fizzyade's bash script into a powershell script for anyone else running sonarr/radarr on their windows pc and emby on a separate nas.


#! /usr/bin/pwsh
 
#EMBY
$apiKey = "<your emby api key>"
$url = "http://<emby server ip>:8096"
#PATHS
$local_tv_path = [regex]::escape("\\UNC\Media\TV Shows\")
$local_movie_path = [regex]::escape("\\UNC\Media\Movies\")
$remote_tv_path = "/volume1/Media/TV Shows/"
$remote_movie_path = "/volume1/Media/Movies/"
#SONARR
$sonarr_episodefile_path = $env:sonarr_episodefile_path
$sonarr_series_path = $env:sonarr_series_path
$sonarr_eventtype = $env:sonarr_eventtype
#RADARR
$radarr_moviefile_path = $env:radarr_moviefile_path
$radarr_movie_path = $env:radarr_movie_path
$radarr_eventtype = $env:radarr_eventtype

IF ([string]::IsNullOrWhitespace($apiKey)){

      '*******************************'

      '* Error: No API Key specified.*'

      '*******************************'

      exit

}

IF ([string]::IsNullOrWhitespace($url)){

      '********************************'

      '* Error: No Emby URL specified.*'

      '********************************'

      exit

}

IF ([string]::IsNullOrWhitespace($sonarr_eventtype) -and [string]::IsNullOrWhitespace($radarr_eventtype)){

      '******************************************************************'

      '* Error: Must be called as a custom script from Sonarr or Radarr.*'

      '******************************************************************'

      exit

}

#SONARR
if($sonarr_eventtype -eq 'Download' -or $sonarr_eventtype -eq 'Upgrade') {
   $UpdateType = "Series"
   $path = $sonarr_episodefile_path -replace $local_tv_path #strips the local tv path from the path
   $path = $path -replace "\\", "/" #substitutes back slashes with forward slashes to convert to uri format
   $path = $remote_tv_path + $path #adds the remote tv path to the uri
   #$path = $path -replace " ", "%20" #substitutes spaces with %20
}elseif($sonarr_eventtype -eq "Rename") {
   $UpdateType = "Series"
   $path = $sonarr_series_path -replace $local_tv_path
   $path = $path -replace "\\", "/"
   $path = $remote_tv_path + $path
   #$path = $path -replace " ", "%20"
}elseif($sonarr_eventtype -eq "Test") {
   exit
}elseif($radarr_eventtype -eq 'Download' -or $radarr_eventtype -eq 'Upgrade') {
   $UpdateType = "Movie"
   $path = $radarr_moviefile_path -replace $local_movie_path
   $path = $path -replace "\\", "/"
   $path = $remote_movie_path + $path
   #$path = $path -replace " ", "%20"h
}elseif($radarr_eventtype -eq "Rename") {
   $UpdateType = "Movie"
   $path = $radarr_movie_path -replace $local_movie_path
   $path = $path -replace "\\", "/"
   $path = $remote_movie_path + $path
   #$path = $path -replace " ", "%20"
}elseif($radarr_eventtype -eq "Test") {
   exit
}else {
#   $UpdateType = $null
}

$postparams = '{"Updates":[{"Path":"' + $path + '","UpdateType":"' + $UpdateType + '"}]}'


Invoke-WebRequest -uri "$url/emby/Library/Media/Updated?api_key=$apiKey" -ContentType "application/json" -Method POST -body $postparams

 

What should be my approach since I'm in the opposite direction, running Sonarr/Radarr on FreeNAS and emby on a Windows PC?

I think I should still use the @fizzyade's bash script, but may need to change the remote path. Could I get some guidance on that?

Thanks for the help,
CFC

Link to comment
Share on other sites

  • 3 weeks later...
stuartgib

You'll need to run fizzyades bash script on a freenas machine. I'm not sure if there is a way to run powershell on that machine.

You might need to convert the forward slashes in the uri into backslashes for windows to recognize it.

if [ "$sonarr_eventtype" == "Download" ];  then
  UpdateType="Series"
  Path=$(echo "$sonarr_episodefile_path" | sed "s|$local_tv_path|$remote_tv_path|")
  Path=$(echo "$sonarr_episodefile_path" | sed -e "s/\\/\//g")
fi
I'd start with that and see how you go, but i'm not familiar enough with bash to know if i've fucked it up.
You would add that second path substitution in each event type.

  • Like 1
Link to comment
Share on other sites

  • 7 months later...
laffinalldaway

Hello. I have tried the bash script method, but when I chose the "script.sh" file (which I have CHMOD'd it), I get the "file/directory does not exist" prompt on radarr/sonarr.

Would anyone have any idea what I may be doing wrong?

radarr/sonarr is running in my Unraid server, while emby is running on Ubuntu on another machine.

I have added a path to both radarr/sonarr docker to point to a folder where the bash script is located. The pull down in the file selection section in the Custom script window shows me the script.sh and allows me to select it. Unfortunately, I am told it does not exist.

Link to comment
Share on other sites

On 5/20/2021 at 6:13 PM, laffinalldaway said:

Hello. I have tried the bash script method, but when I chose the "script.sh" file (which I have CHMOD'd it), I get the "file/directory does not exist" prompt on radarr/sonarr.

Would anyone have any idea what I may be doing wrong?

radarr/sonarr is running in my Unraid server, while emby is running on Ubuntu on another machine.

I have added a path to both radarr/sonarr docker to point to a folder where the bash script is located. The pull down in the file selection section in the Custom script window shows me the script.sh and allows me to select it. Unfortunately, I am told it does not exist.

Hi, are you sure the path is valid?

Link to comment
Share on other sites

laffinalldaway
1 hour ago, Luke said:

Hi, are you sure the path is valid?

It should be. I added a host path in docker on unraid machine.

When attempting to add a custom script connection, I manually add the path. I get the warning. I also tried to select file. Same result.

Screenshot_2021-05-25 Connect Settings - Radarr.png

Screenshot_2021-05-25 Connect Settings - Radarr(1).png

Screenshot_2021-05-25 Tower UpdateContainer.png

Link to comment
Share on other sites

fizzyade

And that folder unraid has been set as a mapped path on your container to /scripts ?

Edited by fizzyade
Link to comment
Share on other sites

laffinalldaway
50 minutes ago, fizzyade said:

And are the permissions set correctly on the folder and the script itself?

I used chmod. I ran into the current problem.

When that didn't work, I tried "Fix Permission" in Unraid, to make sure all permissions were set correctly.

Link to comment
Share on other sites

fizzyade
42 minutes ago, laffinalldaway said:

I used chmod. I ran into the current problem.

When that didn't work, I tried "Fix Permission" in Unraid, to make sure all permissions were set correctly.

Open a console in the docker container and check you can run the script, it's possible you've got an issue with UID/GID mappings or something, I can't think of anything else to be honest, from your description it sounds like it should work, opening a terminal inside the container will let you poke around and ensure that everything is actually as you think it is.

Link to comment
Share on other sites

  • 2 months later...
  • 3 months later...

Is this script still relevant?   I just moved all of my aRR's off of my windows server, which Emby still resides on.   The aRR's are now running on my NAS in Docker.    Since switching everything over, updates have just not been working for me.   I feel like I've thrown just about everything that I can at it with no luck.   Any help would be much appreciated

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...