Unlimited Plex Media Server (using Amazon's Unlimited Storage Backend) Pt2

Posted on Thu 25 February 2016 in Plex

Update: It may be that acd_cli has been updated to be able to manage larger files. I haven't confirmed this, so I'm not going to update this yet.

Note: This blog does not condone piracy and no pirated content was used in the creation of this post or the series. We only condone downloading and hosting of freely available series and movies when you have the appropriate rights.

Alright, we have our cloud based Plex server, so let’s work out how we’re going to be putting media on it. I don’t really fancy downloading it locally then uploading it to Amazon Cloud, so we’re going to set our dedicated server up to be able to download torrents and automatically upload them to Amazon Cloud for us.

Assumptions made in this post: You’ve followed part 1 of this series. You’re logged in as the Plex user. rTorrent = The torrent server back-end ruTorrent – The torrent server front-end we’ll be using Note: If you already run apache, bear in mind the script we will be using may affect some of your settings, and you should back them up first.

Using Our Dedicated Server to Download and Upload to Amazon Cloud

Using an absolutely fantastic script by Kerwood on Github, we can have rTorrent, ruTorrent and a bunch of plugins installed for us. Grab his script, make it executable and run it.

wget https://raw.githubusercontent.com/Kerwood/rtorrent.auto.install/master/Rtorrent-Auto-Install-3.0.2-Debian-Wheezy
chmod +x Rtorrent-Auto-Install-3.0.2-Debian-Wheezy
sudo ./Rtorrent-Auto-Install-3.0.2-Debian-Wheezy

At the time of writing, 3.0.2 is the most up to date.

Follow the on-screen instructions, install all of the plugins (because why not) and spend an hour or so watching it compile. Make sure Putty has keep-alive turned on so it doesn’t timeout, and for the love of God run it in a screen so you can do other things at the same time.

Make sure to press 3 and download all the plugins, to exit that screen press 0. Press 0 to begin the compilation and installation.

It is advised to use Apache to stay in sync with this guide. We will be doing a lot of modification of config files later on and I’m not sure how well that works with nginx.

By default, the script will have you downloads folder as /home/username/Downloads. We’ll be modifying that in a minute anyway.

cd into /home/plex/Downloads and then make two folders inside, toupload and downloading

mkdir toupload
mkdir downloading

toupload is where finished downloads will save to be automatically uploaded to clouddrive. Downloading will contain then currently downloading torrents.

Once rTorrent is definitely finished installing, you can head over to http://yourip/rutorrent

First, we want to make absolutely and utterly certain that we do not upload any unfinished torrents to Amazon, as that would be annoying. So open up rutorrent in your browser and open up the cog at the top. You may want to modify the settings to your liking, but I’m assuming leaving things in home/Download is fine for you.

Under the “Downloads” tab, change your default directory for downloads to ~/Downloads/downloading. This is so we don’t mix up our finished and unfinished torrents.

Under the “Autotools” tab, tick the “AutoMove” checkbox and select the “toupload” folder as our finished torrent location.

Feel free to test at this point to ensure your downloads sit in the downloading folder when expected, and move to toupload when finished.

If that all works, we can continue building our script! Acd_clid doesn’t currently support uploading from the FUSE mount, so we need a script that does it for us.

So what does our script need to do?

  • Detect changes in our toupload folder
  • Upload changed files
  • Delete the files from the toupload folder

So first off we’re going to have to be able to detect the changes. There’s a great little package that can do that:

sudo apt-get install inotify-tools This is the script that I threw together that seems fairly effective:

1
2
3
4
5
6
7
8
#!/bin/bash
FOLDER="/home/plex/toupload"
inotifywait -m $FOLDER -e create -e moved_to |
        while read path action file; do
                echo "The file '$file' appeared in directory '$path' via '$action'"
                acd_cli ul $FOLDER/"$file" /Media/Unsorted/
                rm -rf $FOLDER/"$file"
        done

Simply create a script under /home/plex with nano autoupload.sh, paste in the script and modify it to your liking. You will need to change the cd and inotifywait commands to your download location. If you’ve been following it like mine, it should be /home/plex/toupload.

Use chmod +x autoupload.sh to give it execute permission. We’ll then need to open up a screen. If you’re using su to use the plex user, you’ll need to run the command script /dev/null first, otherwise screen won't open (trust me).

Run screen, then start the script with ./autoupload.sh

Later on, you can hold down Ctrl and press A, then release both and press D to detach from the screen and leave the script running in the background. For now, I advise keeping it up and giving it a quick test by downloading something with rTorrent.

Bear in mind that if you restart your server, you will have to manually start acd_cli and the upload script, as this guide does not deal with automatic starting yet.

You should now have an auto-uploading torrent server which uploads into clouddrive! You can change the script to upload into whatever folder you like. At the moment mine uploads into /Media/, and unfortunately it doesn’t separate into TV or Movies. But we’ll sort that out in our next tutorial when we start setting up automatic movie and TV series downloading (Yup, that’s next! And I've tested it and everything, it works).

So what do we need right now?

Well, at the moment, acd_cli doesn’t ever actually sync our FUSE mount. Sure, it uploads, but Plex doesn’t get updated with new content. It won’t be sorted too well, but we can still stream files.

So let’s make our local drive update using crontab.

First of all, we need to get into crontab. Type crontab -e and press “2” for nano.

This post won’t go over how crontab works, all you need to know is that if you add this to the crontab file, acd_cli will sync every minute:

* * * * * /usr/local/bin/acd_cli sync

It should now sync automatically if you add something to the drive!

Awesome! What now?

Well, at this point we’ve got a pretty decently working server. We can download torrents, they upload to clouddrive then delete themselves locally, then the server will refresh, PleX will update, and we can watch things!

It isn’t sorted so well at the moment, but in the next section when we set up automatic downloading we’ll be able to set up uploading into different folders.

For now, have fun!