Deep Dive: Making Sonarr Work So You Don’t Have To!

Alright, this is probably the most requested guide of all. Sonarr is probably one of the best tools to use in conjunction with Plex Media Server, so it’s best to take advantage of every ability it has to offer. In this guide, we are going to focus on the following areas:

  • Managing an existing media collection
  • Renaming/moving media files
  • Integrating Sonarr with PMS
  • Automatically running scripts upon media import

With these tasks being automated by Sonarr, you’ll find yourself spending a lot less time tinkering with your PMS and more time enjoying your media collection! Let’s get started. This guide will be using the file paths from our other guide, Using Amazon Cloud Drive with Plex Media Server on Ubuntu… And Encrypting It! So, if you haven’t used that guide to set up your media directories, you’ll have to substitute your own here.

Open Sonarr in a browser with “:8989” and read on…

Step 1 – Managing an existing media collection

Starting Fresh

If you haven’t started using Sonarr yet, go ahead and either add a new series or start importing from disk. When you select your first series, you’ll have to choose a path. Browse to ‘/home/plex/media/TV Shows’ in the path field. This is so all your renamed shows get put into this directory and are able to be uploaded to Amazon Cloud Drive later on.sonarr_path

Importing Series from Disk

If you haven’t started using Sonarr yet, but you’ve already TV media on your server, you can start off with the “Import series from disk” option. Go ahead and choose your root TV folder, and Sonarr will take care of matching everything up.

Changing the Default Path

If you’ve already started using Sonarr and have series imported, but you’ve followed our previous guides this far, let’s change the default root path for your existing series. Click the “Series Editor” button on the “Series” page, then click the top-left checkbox to select all your series. In the drop-down menu under “Root Folder” select “Add a different path” and browse to ‘/home/plex/media/TV Shows’ and hit “Save.” This is so all your renamed shows get put into this directory and are able to be uploaded to Amazon Cloud Drive later on.

Step 2 – Setting up Renaming

Enable File Renaming

To enable renaming of episodes, click the settings icon at the top of the Sonarr web page, then click the “Media Management” tab. Find the button for “Rename Episodes” and turn it on. I typically keep the default settings here, but you can change the naming conventions to whatever you like. PMS works just fine with the defaults.

Enable Upgrading Episodes

You’ll want to enable advanced settings to make the next change

sonarr_adv_set.PNG

Towards the bottom of the page, find the “File Management” section. Enable the “Download propers” option to ensure you’ve got the best releases for each episode.

Step 3 – Integrating Sonarr with PMS

Next, let’s get Sonarr and PMS talking to eachother. Well, just Sonarr talking to PMS. Sonarr don’t take no orders… Except from you, of course. So open the Sonarr settings, and go to the “Connect” tab. Add a new connection, and choose the “Plex Media Server” option. Go ahead and fill this out with your PMS information, using the options in the image below:

sonarr_pms

Now Sonarr can let PMS know when to scan the TV library after new items are added.

Step 4 – Automate rclone Uploading with Scripts

There is an updated version of the script specified below over at the new Script Hub!

And here is the crown jewel of this Sonarr guide; fully automating the uploading and cleaning up of your local files. I know you’ll want to dive right in:

Writing the Script

First thing we’ll have to do is write a script to handle all the legwork. Get into your scripts directory we created a few guides back, then start a new script called “uploadTV.sh” with Nano:

cd ~/scripts
nano uploadTV.sh

And go ahead and paste in the following script. If you haven’t followed our guide “Converting your Media to MP4 for Universal Playback” for converting your media (this guide isn’t finished yet, but if you plan on completing it, just place a “#” in front of those italicized lines), or don’t want to automatically convert your episodes to MP4, don’t copy the italicized lines below, just start copying at the “Uploading to ACD” line:

#!/bin/sh

echo "Converting video if needed"

/usr/bin/python /home/plex/sickbeard_mp4_automator/manual.py -i "${sonarr_episodefile_path}" -tv ${sonarr_series_tvdbid} -s ${sonarr_episodefile_seasonnumber} -e ${sonarr_episodefile_episodenumbers}

echo "Uploading to ACD"

/usr/sbin/rclone copy /home/plex/.local/L,ULJSSLPjETMTzk5OhzCioC/ acd:Plex/L,ULJSSLPjETMTzk5OhzCioC && rm -Rf "/home/plex/local/TV Shows/"*

exit

The text in red should equal the name of your encrypted “TV Shows” directory as it appears in your ‘/home/plex/.local’ directory.

Make the script executable:

chmod +x uploadTV.sh

Connecting the Script in Sonarr

First, you’ll have to enable completed download handling in Sonarr. Go to the Sonarr web portal, click the “Download Client” tab, and turn on “Completed download handling.”

Click over to the “Connect” tab, add a new connection, and choose the “Custom Script” option. Enter the information as follows:

sonarr_custom_script

Save that connection, and that’s it! Sonarr will now invoke this script after renaming and moving your file, uploading it to ACD and emptying the local “TV Shows” folder when it’s finished.

Wrap-Up

So that takes care of TV show automation. The next guide will focus on movie automation with CouchPotato and aim to accomplish the same type of task process. When Sonarr and CouchPotato are working in a fully-automated fashion, we will set up PlexRequests to allow our Plex friends to request media, and you won’t even have to lift a finger to get that media downloaded, uploaded, and available on Plex! Unless you want to, that is. As always, feel free to drop a comment below if you’re running into any issues, or leave me a message on Reddit. Thanks for reading!

30 thoughts on “Deep Dive: Making Sonarr Work So You Don’t Have To!

  1. Pingback: The (Almost) Complete Guide to Creating the Ultimate Plex Server | enzTV

  2. This is dangerous if you’re downloading faster than you can upload. I would recommend doing a check in your script uploadTV.sh to something like the following:

    #!/bin/bash

    if [[ $(ps -ef | grep -c “rclone copy”) -ne 1 ]]; then
    # rclone copy running, don’t run it again
    else
    # skip rclone copy
    fi

    Or if you want to get fancier (I would), do a while true/false rclone copy running and then trigger it to run again:

    #!/bin/bash

    while [ true ]; do
    if [[ $(ps -ef | grep -c “rclone -v copy”) -ne 1 ]]; then
    echo “rclone is running, sleeping 60 seconds”
    sleep 60s
    else
    echo “rclone is NOT running, executing…”
    /usr/sbin/rclone copy /home/plex/.local/L,ULJSSLPjETMTzk5OhzCioC/ acd:Plex/L,ULJSSLPjETMTzk5OhzCioC && rm -Rf “/home/plex/local/TV Shows/”*
    fi
    done

    You get it.

    Liked by 1 person

    • That’s a good check to have, but Sonarr won’t begin processing another file until this script is complete, so that should prevent any issues. Although it’s probably best to have a check in the script anyhow. I’ll modify it, thanks.

      Like

    • you seem to know your stuff with scripts. Do you have one that checks to see if my acd mount is still up and if not it mounts it?
      #!/bin/sh

      echo “Remount Initiated $(date)”
      appname=$(basename $0)

      # Change this to the location of your Amazon Cloud Mountpoint
      acdmount=”/home/plex/.acd”

      if [ $(ls -l $acdmount | grep -v ‘^total’ | wc -l) -gt 0 ]; then
      echo Everything Looks ok
      exit
      fi

      if [ $(ps -Al | grep $appname | wc -l) -gt 2 ]; then
      echo “Already Running! Count $(ps -Al | grep $appname | wc -l)”
      exit
      fi
      echo “Remounting $(date)”

      /usr/local/bin/acd_cli umount “$acdmount”
      syncresult=$(/usr/local/bin/acd_cli sync 2>&1)
      if [ $(echo $syncresult | grep -i error | wc -l) -gt 0 ]; then
      echo Error with the DB
      rm /home/plex/.cache/acd_cli/nodes.db
      /usr/local/bin/acd_cli sync
      sleep 10
      fi
      echo $syncresult
      /usr/local/bin/acd_cli mount “$acdmount”

      echo “Remount Done $(date)”

      this gets stuck on fusermount error and I have to ctrl + c to stop it and it doesn’t mount it back

      Like

    • This provided great insight. I modified it a bit for my purpose, adding the break and specifying a series title to reduce the amount of checks that rclone will do to push up on episode:

      NOW=$(date +”%m-%d-%Y-%H-%M-%S”)
      while [ true ]; do
      if [[ $(ps -ef | grep -c “rclone -v copy”) -ne 1 ]]; then
      echo “rclone is running, sleeping 60 seconds”
      sleep 60s
      else
      echo “rclone is NOT running, executing…”
      /usr/sbin/rclone -v –log-file=/home/plex/scripts/logs/rclone.$NOW.txt copy –transfers=30 /home/plex/local/TV/”$sonarr_series_title” GOOGLE:Plex/TV/”$sonarr_series_title”
      break
      fi
      done

      Like

  3. I found refreshing the library after stuff gets uploaded works better since if you refresh before it say’s media unavailable until you refresh library again. I added a couple of commands to your script and it works really well. I noticed that my acdcli mount was getting unmounted after the script ran so I also added a remount script after it finishes uploading.

    #!/bin/sh
    echo “Uploading to ACD”

    /usr/local/bin/acdcli sync
    /usr/sbin/rclone move /home/plex/.local/5wzUXjSOtie40xc-LRMP3bML ACD:/Plex/5wzUXjSOtie40xc-LRMP3bML
    /usr/local/bin/acdcli sync
    /home/plex/scripts/remount.sh
    export LD_LIBRARY_PATH=/usr/lib/plexmediaserver
    /usr/lib/plexmediaserver/Plex\ Media\ Scanner –scan –refresh –section 2
    exit

    Like

  4. Hi Enz!

    I’ve been following your guides, and I think I got everything to work – at least, sabnzbd is downloading stuff from both sonarr and couchpotato. However, I’m running into a problem – when an episode is downloaded, it shows up on my plex library… Then it is erased. On my ACD there’s only one folder within the encrypted tv shows folder. So Iguess I’m a bit lost as to what to do now?

    Thanks!

    Like

    • Can you confirm that it was uploaded to acd? If you follow the other guide what ever you downloaded should show up encrypted in /hone/plex/.acd and decrypted in /one/plex/media if it is then just refresh library on plex.

      Like

      • I’m seeing the tv shows encrypted in the acd web interface, in /plex.
        Inside my VPS (digital console) I’ve checked the following under /home/plex
        I see all the downloaded things (both from couchpotato and sonarr) in /Downloads/complete.
        If I go to /local/Movies or /local/TV both are empty.
        If I go to /acd is empty, same for /.acd
        So I guess I did something wrong. Interestingly, the files are saving in Amazon Cloud Drive, encrypted. I just can’t access them from Plex.

        Like

      • I checked everything again, and same – nothing shows up in the directories in my VPS, but I have data uploaded (and encrypted!) to Amazon Cloud.

        Also, SABnzbd stopped downloading since apparently sonarr stopped processing downloaded files and my VPS is full. Any idea why this may be?

        Thanks!

        Like

      • So, I installed FileZilla to see what’s going on, and I found out something interesting:

        If I log as root on Filezilla, I can’t see the folder /home/plex/local; but I can see the folder /home/plex/.local – which includes the encrypted folders (but no files). I also cannot see the folder media.

        If I log as plex on Filezilla, I can see all the previous folders. However, they have no files (except for .acd).

        Is this an indicator of what’s going on?

        Thanks!

        Like

      • Sorry to bother you one last time, but I may have found a solution, and I just wanted to let you know.

        Apparently acdcli unmounts every so often due to inactivity, so I would have to force the mount.sh script from the console. However, based on https://github.com/yadayada/acd_cli/issues/299 I deleted nodes.db and so far it’s running smoothly now.

        Anyways, thanks so much for the guide, and I anxiously wait for the couchpotato automation (would you consider doing headphones as well?)

        Thanks!

        Like

  5. I’m currently utilizing your guide , but with a twist. The base OS (ubuntu) has all the drives mounted just like you do, but I’m using dockers for all apps. So the first issue I’ve come across thus far is running this script you’ve posted. Specifically getting to the rclone to happen. Basically I can have my sonarr docker convert things to mp4, however I cannot run the rclone command from that docker, as obvious the ACD mount is in the underlying base OS. That said, I think the simple solution is to simply cron a nightly rclone / delete local job on the host os. Have you any examples with that in mind?

    Like

  6. Hey there,!

    I currently wonder how I am supposed to get sonarr to for example rename+move files instead of moving exisitng files since I wantr them to at least be seeded localy for sometime before beeing removed.

    Any thoughts on this?

    Like

  7. I’ve been following this guide almost exactly. The only exceptions are that I am on Ubuntu 14.04.5 which means I have to use Upstart commands instead of Systemd. The only thing this has affected for me so far is Section 2.2 of installing Sonarr. When I got to this section, Step 1 says to add the directory “/home/plex/media/TV Shows/” to Sonarr. This directory exists on my server, but all I see (aside from the hidden files/folders) in Sonarr is “Library”, “Downloads”, and “scripts”. I’m thinking this may be a permissions issue?

    Like

  8. “… you’ll have to choose a path. Browse to ‘/home/plex/media/TV Shows’ in the path field. This is so all your renamed shows get put into this directory and are able to be uploaded to Amazon Cloud Drive later on.”

    I always thought this is the ‘/home/plex/local/TV Shows’ folder
    Which got uploaded into Amazon Cloud
    And showed with unionfs as “/home/plex/media/TV Shows”

    Sonarr downloads and sorts into the LOCAL folder
    And not into MEDIA

    Doesn’t it?

    Like

    • Agreed. Sonarr should put the renamed files in ~/local, then the script moves them to ACD, then ~/acd mirrors what is on ACD and ~/media mirrors both ~/acd and ~/local, but only ~/local has write access? I could use a diagram lol.

      Another problem I have is Deluge is downloading to the directory “…/deluge/Downloads”. Does Sonarr take completed files from this directory and move them to what we specify once they’re finished downloading? Because right now, they’re being copied and the originals are still in /Downloads.

      Like

      • You need to first understand that you CANNOT write to the ~/acd directory due to the limitations of rclone. You can only read the ~/acd directory. Now, Radarr and Sonarr only look at one directory for all your media. Whatever exists already is scanned by them, and whatever doesn’t exist will be acquired by them and they’ll try to WRITE that data to the directory where everything else lives. Like I said, you can’t do that. The data can’t just be written to ACD like that.

        This is where unionFS comes in. We can create a single directory out of two separate directories; one for reading only (~/acd) and one that can be written to (~/local), however BOTH directories can be presented as one to Sonarr, Radarr, and Plex (~/media). Now, we can WRITE data to the same location we point Radarr and Sonarr to. UnionFS handles figuring out which directory is read and which is write. ~/local is the writable directory, and ~acd is the read directory, however they’re both “merged” as ~/media. When you copy something to ~/media, unionFS is actually putting it in ~/local for you. If you were doing all your downloading and copying and renaming manuallly, there’s nothing preventing you from using ~/local. But for Radarr and Sonarr, they can’t handle two separate paths for single items. Once you upload to ACD, your files are gone from ~/local and now reside in ~/acd. How would Sonarr and Radarr know this? They wouldn’t.

        So, the ~/media directory is simply an easy way to use two different directories in two different ways, but simplify things by using one directory. You copy your media to ~/media and technically it is in ~/local, but as media is uploaded from ~/local to ACD, it moves to ~/acd however you’ll still see it in ~/media both before and after, because it’s just a merged copy of both directories.

        Does that make sense?

        Like

      • There is one important point missing.
        Sonarr / Radarr only look at one directory.
        Which is in this case truely /home/plex/ACD/media/xx
        But you have to extend the rclone mount with the flag “–allow-other” and also you have to modify the unionfs mount command with “–allow-other” as for me even when Sonarr / Radarr was running with the same username, the docker startup of thise containers was not possible.

        Now I have Sonarr and Radarr in the docker container and they both have access to their fodlers TV and Movies
        Within the “media” folder and they move to the “local” drive in the background! As that mount is RW.
        Media part coming from ACD is “RO”

        Like

  9. What Sonarr settings are you using? Deluge is downloading to /var/lib/deluge/Downloads then Sonarr is copying them to ~/local which is fine, but the original file is still in /var/lib/deluge/Downloads. I have “Remove” within “Completed Download Handling” enabled in Sonarr. I also have the “Auto Remove Plus” plugin in Deluge. When torrents reach the seed limit, they are removed from the web ui, but stay on the damn Hard Drive.

    Also, as a relevant side note, the sickbeard instructions say to disable “Completed Download Handling”.

    As an irrelevant side note, I downloaded a torrent file for a whole season. When I went into the “files” tab on Deluge I could see each individual episode as well as a folder containing the subtitles. None of the subs made it to plex. They’re in /var/lib/deluge/Downloads, but not in ~/local. Cant figure it out, thanks for the help.

    Have a beer on me Enztv.

    Like

    • “Completed Download Handling” is so Sonarr can handle the download queue on its own, and the “Remove” option just means it will remove the item from the queue once it transfers. As for the original file staying behind, check under your “Media Management” tab in your Sonarr settings with “Advanced” enabled, you should see the option “Use Hardlinks instead of Copy” which can be turned off if you want the media to actually be removed from the original location.

      The Sickbeard script instructions tell you to turn off “Completed Download Handling” because that script assumes you’re using that post-processing script, which will initiate a scan by Sonarr after it runs. I don’t use that because otherwise when you download multiple items, as they finish converting and triggering Sonarr, you’ll get simultaneous file copies going, and Sonarr will call the upload script multiple times without finishing those copies one at a time. This can cause issues as you’ll be attempting to upload to ACD while a file is being copied to the source directory. If you just depend on Sonarr’s completed download handling, it will only import one file at a time and it will wait until the upload script completes before moving on to the next file. However, I don’t use Deluge so I can’t speak to how Sonarr will interface with Deluge specifically. I use SABnzbd, though I’d imagine if you have Sonarr sending downloads to Deluge, it should work fine for completed download handling. Also, remember to change the Drone Factory interval setting to zero in Sonarr’s download client settings.

      Lastly, as for the subtitles, there is a new option in the “Media Management” section of Sonarr’s settings called “Import Extra Files” that will move those subtitles. Make sure you’re on the latest version of Sonarr. Just specify the extensions you want to move in the field below that option. I’ve been testing that out and it seems to work well. I used to have a section in my custom scripts that moved subtitles to a temporary directory then had Sonarr move them with the media file, but I’ve since commented that out and my subtitles are moving just fine.

      And thanks for the donation! Much appreciated!

      Like

      • Thank you for the information. I hate hijacking a post like this, but hopefully it helps other people.
        I have hardlinks disabled, “completed download handling” and “remove” enabled, and the “drone factory interval” set to 0. Sonarr sends the download request to Deluge, once it’s done downloading, Sonarr runs the script to upload it to ACD leaving a copy in the original location. Once it is done seeding, Deluge deletes said copy from the hard drive.

        So, everything is (I think) working perfectly now with one exception. I’m using the script in Step 4 on this page, but have no idea how to install sickbeard_mp4_automator. I went to their GitHub page and it says I need to first install x then y then ffmpeg and ffprobe binaries, and etc. Every time I try to install these they go straight to ~/.local which is really annoying, but I moved them and now Sonarr is spewing so many errors when running the manual.py script. I’d be able to debug it, but Sonarr’s logs dont tell you much. If you know of an easy way to install this, I would be greatly appreciated.

        Like

      • Well, first thing we need to know is what OS you’re running. I’m assuming some form of Linux, in which case you should actually be able to install ffmpeg with your default package manager, so on Ubuntu it would be “sudo apt install -y ffmpeg” and that would place ffmpeg and ffprobe in /usr/bin by default. Then, you’ll need to make sure PIP is installed for python with “sudo apt install -y python-pip” and lastly install all the required dependencies for Sickbeard MP4 Automator by using “pip install XXXX”

        Like

  10. I’m getting the same issue. I actually jumped the gun in my earlier post when I said everything is working perfectly. I guess I jinxed myself.

    [Here](http://imgur.com/a/2ZVqS) is an Imgur link to some screenshots of the issues Plex and Sonarr are giving me. I’m on Ubuntu 16.04 on an online.net headless server; specifically the xc dedibox which is more than fast enough to transcode 3+ 1080p videos.

    I’ve tried resolving these issues myself, but am new to Linux.

    Like

Leave a comment