LAST UPDATED: 7th February 2017 Flexget & Deluge Setup on Ubuntu Server Setup Ubuntu User
once you log in to your seedbox/vps for the first time with your root account, go ahead and create a new user called “djnitehawk” with the following commands. feel free to change “djnitehawk” to whatever you like. but if you do that, you should change each and every line of code where it says “djnitehawk” throughout the tutorial. begin by entering the following commands in the terminal: sudo adduser djnitehawk sudo adduser djnitehawk sudo exit
Install requisites
once logged in with your new user, issue the following commands to
update/upgrade the repos and install a few requisites. sudo apt-get update sudo apt-get install nano curl unrar software-properties-common python-software-properties python-pip Prepare the download folders
run the following commands to setup the folder structure inside your home
folder. mkdir /home/djnitehawk/Downloads echo "dont delete this dir" > /home/djnitehawk/Downloads/.lock mkdir /home/djnitehawk/Downloads/MOVIES echo "dont delete this dir" > /home/djnitehawk/Downloads/MOVIES/.lock mkdir /home/djnitehawk/Downloads/OTHER echo "dont delete this dir" > /home/djnitehawk/Downloads/OTHER/.lock mkdir /home/djnitehawk/Downloads/STORAGE echo "dont delete this dir" > /home/djnitehawk/Downloads/STORAGE/.lock mkdir /home/djnitehawk/Downloads/TV-SHOWS echo "dont delete this dir" > /home/djnitehawk/Downloads/TV-SHOWS/.lock mkdir /home/djnitehawk/Downloads/RATIO echo "dont delete this dir" > /home/djnitehawk/Downloads/RATIO/.lock mkdir /home/djnitehawk/Ready echo "dont delete this dir" > /home/djnitehawk/Ready/.lock mkdir /home/djnitehawk/Ready/Completed echo "dont delete this dir" > /home/djnitehawk/Ready/Completed/.lock mkdir /home/djnitehawk/Ready/MEDIA echo "dont delete this dir" > /home/djnitehawk/Ready/MEDIA/.lock mkdir /home/djnitehawk/Ready/MEDIA/MOVIES echo "dont delete this dir" > /home/djnitehawk/Ready/MEDIA/MOVIES/.lock mkdir /home/djnitehawk/Ready/MEDIA/STORAGE echo "dont delete this dir" > /home/djnitehawk/Ready/MEDIA/STORAGE/.lock mkdir /home/djnitehawk/Ready/MEDIA/TV-SHOWS echo "dont delete this dir" >
/home/djnitehawk/Ready/MEDIA/TV-SHOWS/.lock chown -R djnitehawk:djnitehawk /home/djnitehawk/Downloads chown -R djnitehawk:djnitehawk /home/djnitehawk/Ready chmod 777 -R /home/djnitehawk/Downloads chmod 777 -R /home/djnitehawk/Ready Deluge Setup
run the following commands to install and configure deluge sudo add-apt-repository ppa:deluge-team/ppa sudo apt-get update sudo apt-get install deluged mkdir ~/.config mkdir ~/.config/deluge cd ~/.config/deluge nano auth
djnitehawk:DELUGE_PASSWORD:10
configure deluge daemon by entering the following command: nano core.conf
{ "file": 1, "format": 1 }{ "info_sent": 0, "lsd": false, "send_info": true, "move_completed_path": "", "enc_in_policy": 1, "queue_new_to_top": false, "ignore_limits_on_local_network": true, "rate_limit_ip_overhead": true, "daemon_port": 54321, "natpmp": false, "max_active_limit": 30, "utpex": false, "max_active_downloading": 3, "max_active_seeding": 30, "allow_remote": true, "max_half_open_connections": 50, "download_location": "/home/djnitehawk/Downloads/RATIO", "compact_allocation": true, "max_upload_speed": 30720.0, "cache_expiry": 60, "prioritize_first_last_pieces": false, "auto_managed": true, "enc_level": 2, "max_connections_per_second": 10, "dont_count_slow_torrents": false, "random_outgoing_ports": false, "max_upload_slots_per_torrent": 30, "new_release_check": true, "enc_out_policy": 1, "outgoing_ports": [ 12346, 12346 ], "seed_time_limit": 0, "cache_size": 1024, "share_ratio_limit": 0.0, "max_download_speed": 30720.0, "geoip_db_location": "/usr/share/GeoIP/GeoIP.dat", "torrentfiles_location": "", "stop_seed_at_ratio": false, "peer_tos": "0x00", "listen_interface": "", "upnp": false, "max_download_speed_per_torrent": -1, "max_upload_slots_global": -1, "enabled_plugins": [ "Execute" ], "random_port": false, "autoadd_enable": false, "max_connections_global": 300, "enc_prefer_rc4": true, "listen_ports": [ 12345, 12345 ], "dht": false, "stop_seed_ratio": 2.0, "seed_time_ratio_limit": 0.0, "max_upload_speed_per_torrent": -1, "copy_torrent_file": false, "del_copy_torrent_file": false, "move_completed": false, "proxies": { "peer": { "username": "", "password": "", "type": 0, "hostname": "", "port": 8080 }, "web_seed": { "username": "", "password": "", "type": 0, "hostname": "", "port": 8080 }, "tracker": { "username": "", "password": "", "type": 0, "hostname": "", "port": 8080 }, "dht": { "username": "", "password": "", "type": 0, "hostname": "", "port": 8080 } }, "add_paused": false, "max_connections_per_torrent": 100, "remove_seed_at_ratio": false, "autoadd_location": "", "plugins_location": "/home/djnitehawk/.config/deluge/plugins" }
run the following command to setup a service for the deluge daemon so
that it will run in the background across system restarts: sudo nano /etc/systemd/system/deluged.service
[Unit] Description=Deluge Daemon After=network-online.target [Service] Type=simple User=djnitehawk Group=djnitehawk UMask=000 WorkingDirectory=/home/djnitehawk/.config/deluge ExecStart=/usr/bin/deluged -d Restart=always RestartSec=3 [Install] WantedBy=multi-user.target
sudo systemctl start deluged sudo systemctl enable deluged sudo systemctl status deluged
in the “EXECUTE” section, add a new command by selecting “TORRENT
COMPLETE” as the “EVENT” and enter the following as the “COMMAND”: /home/djnitehawk/tex/tex.sh
Torrent Auto Extractor Setup
enter the following commands in order to setup the auto extractor
script. cd ~/ sudo chmod -R 777 tex cd tex echo "" > tex.sh; chmod 777 tex.sh; nano tex.sh
#! /bin/bash TR_TORRENT_DIR="$3" TR_TORRENT_NAME="$2" if [[ -z "$TR_TORRENT_DIR" ]] || [[ -z "$TR_TORRENT_NAME" ]]; then echo "Torrent Dir or Torrent Name undefined..." echo "Exiting..." exit 0 fi OLD_IFS="$IFS" IFS=$'\n' sleep 10s MOV_DIR="/home/djnitehawk/Ready/MEDIA/MOVIES" XXX_DIR="/home/djnitehawk/Ready/MEDIA/STORAGE" TVS_DIR="/home/djnitehawk/Ready/MEDIA/TV-SHOWS" ELS_DIR="/home/djnitehawk/Ready/Completed" LOG_FILE="/home/djnitehawk/tex/tex.log" PB_KEY="PUSHBULLET_API_ACCESS_TOKEN" SRC_DIR="$TR_TORRENT_DIR/$TR_TORRENT_NAME" TMP_DIR="$SRC_DIR/tmp" DST_DIR="$ELS_DIR/$TR_TORRENT_NAME" if [[ "$TR_TORRENT_DIR" == *RATIO* ]] ; then #echo " " >> "$LOG_FILE" #echo "Skiped: $TR_TORRENT_NAME" >> "$LOG_FILE" exit 0 fi if [[ "$TR_TORRENT_DIR" == *MOVIES* ]] ; then DST_DIR="$MOV_DIR/$TR_TORRENT_NAME" fi if [[ "$TR_TORRENT_DIR" == *STORAGE* ]] ; then DST_DIR="$XXX_DIR/$TR_TORRENT_NAME" fi if [[ "$TR_TORRENT_DIR" == *TV-SHOWS* ]] ; then DST_DIR="$TVS_DIR/$TR_TORRENT_NAME" fi cd "$TR_TORRENT_DIR" if [ -d "$SRC_DIR" ]; then unset RAR_FILES i for RAR in $(find "$SRC_DIR" -type f -iname "*.rar"); do if [[ "$RAR" == *.part*.rar ]]; then if [[ "$RAR" =~ .*part0*1.rar ]] || [[ "$RAR" =~ .*part1.rar ]]; then RAR_FILES[i++]="$RAR" fi else RAR_FILES[i++]="$RAR" fi done rm -f -R "$DST_DIR" mkdir "$DST_DIR" if [ ${#RAR_FILES[@]} -gt 0 ]; then rm -f -R "$TMP_DIR" mkdir "$TMP_DIR" find "$SRC_DIR" -type f ! -name "*.r??" -execdir cp {} "$TMP_DIR" \; for RAR_FILE in "${RAR_FILES[@]}"; do unrar x -o+ "$RAR_FILE" "$TMP_DIR" if [ $? -gt 0 ]; then rm -f -R "$TMP_DIR" echo " " >> "$LOG_FILE" echo "Error : $TR_TORRENT_NAME failed to unrar..." >> "$LOG_FILE" curl --header 'Access-Token: $PB_KEY' --header 'Content-Type: application/json' --data-binary '{"body":"Failed to unrar:\n\n $TR_TORRENT_NAME","title":"[TEX] Unrar Failed","type":"note"}' --request POST https://api.pushbullet.com/v2/pushes IFS="$OLD_IFS" rm -f -R "$DST_DIR" exit 0 fi done sleep 10s mv --target-directory="$DST_DIR" "$TMP_DIR"/* rm -f -R "$TMP_DIR" chmod 777 -R "$DST_DIR" #echo " " >> "$LOG_FILE" #echo "Unrard: $TR_TORRENT_NAME" >> "$LOG_FILE" else cp -r --target-directory="$DST_DIR" "$SRC_DIR"/* chmod 777 -R "$DST_DIR" #echo " " >> "$LOG_FILE" #echo "Copied: $TR_TORRENT_NAME" >> "$LOG_FILE" fi find "$DST_DIR" -type f \( -name "*sample*.avi" -o -name "*sample*.mp4" -o -name "*sample*.mkv" \) -delete fi if [ -f "$SRC_DIR" ]; then cp --remove-destination "$SRC_DIR" "$DST_DIR" chmod 777 "$DST_DIR" #echo " " >> "$LOG_FILE" #echo "Copied: $TR_TORRENT_NAME" >> "$LOG_FILE" fi IFS="$OLD_IFS" exit 0
Flexget Setup
run the following commands to install and configure flexget. cd ~/ sudo –H pip install --upgrade pip sudo -H pip install flexget sudo mkdir .flexget; sudo chown -R djnitehawk:djnitehawk .flexget; sudo chmod -R 777 .flexget; cd .flexget echo "" > config.yml; sudo chmod 777 config.yml; nano config.yml
schedules: - tasks: [TV-SHOWS,MOVIES] interval: minutes: 15 - tasks: [IMPORT-MOVIES] interval: minutes: 120 templates: global: retry_failed: retry_time: 5 minutes retry_time_multiplier: 1 max_retries: 12 tv: deluge: host: localhost port: 54321 username: djnitehawk password: DELUGE_PASSWORD path: /home/djnitehawk/Downloads/TV-SHOWS configure_series: settings: quality: webdl|hdtv|webrip h264 720p propers: no from: trakt_list: username: TRAKT_USERNAME list: watchlist type: shows strip_dates: yes regexp: from: title reject: - msd - afg - line content_size: min: 300 max: 4000 strict: no notify: entries: title: "[F] {{series_name}} {{series_id}}" message: "{{title}}\n\nSize: {{content_size}}MB" what: accepted via: - pushbullet: api_key: PUSHBULLET_API_ACCESS_TOKEN inputs: - rss: url: AN_RSS_FEED_OF_TORRENTS all_entries: no - rss: url: A_BACKUP_RSS_FEED_OF_TORRENTS all_entries: no movie: deluge: host: localhost port: 54321 username: djnitehawk password: DELUGE_PASSWORD path: /home/djnitehawk/Downloads/MOVIES quality: bluray h264 720p|1080p imdb_lookup: yes list_match: from: - movie_list: mymovies regexp: from: title reject: - msd - afg - line - hc - korsub content_size: min: 3000 max: 10000 strict: no notify: entries: title: "[F] {{imdb_name}}" message: "{{title}}\n\n{{imdb_url}}\n\nSize: {{content_size}}MB" what: accepted via: - pushbullet: api_key: PUSHBULLET_API_ACCESS_TOKEN inputs: - rss: url: AN_RSS_FEED_OF_TORRENTS all_entries: no - rss: url: A_BACKUP_RSS_FEED_OF_TORRENTS all_entries: no tasks: TV-SHOWS: template: tv priority: 1
IMPORT-MOVIES: imdb_watchlist: user_id: IMDB_USER_ID #will be
in the form of ur12345678 list: watchlist accept_all: yes list_add: - movie_list: mymovies priority: 2 MOVIES: template: movie priority: 3
now, check the validity of your flexget config file by running the following command: flexget check
then run the following commands to setup the flexget
service so that flexget will run as a
service/daemon, even across system restarts. sudo nano /etc/systemd/system/flexget.service
[Unit] Description=Flexget Daemon After=network-online.target [Service] Type=simple User=djnitehawk Group=djnitehawk UMask=000 WorkingDirectory=/home/djnitehawk/.flexget ExecStart=/usr/local/bin/flexget daemon start ExecStop=/usr/local/bin/flexget daemon stop ExecReload=/usr/local/bin/flexget daemon reload Restart=always RestartSec=3 [Install] WantedBy=multi-user.target
sudo systemctl start flexget sudo systemctl enable flexget sudo systemctl status flexget
you can check what flexget has been doing
in the background by looking at the log file with the following command: cat ~/.flexget/flexget.log | more Automated Download Manager Setup
if you have a linux machine on your
local/home network, you can use the following procedure to setup an automated
download manager that will download what has been extracted/copied out to /home/djnitehawk/Ready/
folder. when you get a pushbullet notification, you
can simply turn on your local linux computer and
let the download manager download all the files/folders inside your server’s “Ready”
folder and delete the respective files/folders automatically from the “Ready”
folder once they have been successfully downloaded to your local computer.
the original content inside /home/djnitehawk/Downloads/ will never be automatically
deleted which enables you to keep seeding them for as long as you like. once
you’re done seeding, simply right click on the torrent name(s) using the
deluge thin client and select “REMOVE TORRENT” > “REMOVE WITH DATA” in
order to reclaim the disk space taken up by the downladed
original content. Setup the seedbox/vps/remote server
enter the
following commands on the remote server to enable it to serve files from the “Ready”
folder. sudo apt-get install lighttpd php7.0-cgi sudo lighty-enable-mod fastcgi-php sudo lighty-enable-mod auth sudo nano /etc/lighttpd/conf-enabled/05-auth.conf
server.modules += ( "mod_auth" ) auth.debug = 0 auth.backend = "plain" auth.backend.plain.userfile = "/etc/lighttpd/pass.txt" auth.require = ( "/" => ( "method" => "basic", "realm" => "/", "require" => "user=djnitehawk"))
sudo rm /etc/lighttpd/lighttpd.conf sudo nano /etc/lighttpd/lighttpd.conf
server.document-root = "/home/djnitehawk/Ready" server.dir-listing = "disable" server.errorlog = "/var/log/lighttpd/error.log" server.pid-file = "/var/run/lighttpd.pid" server.username = "www-data" server.groupname = "www-data" server.port = 80 index-file.names = ("index.php") include_shell "/usr/share/lighttpd/create-mime.assign.pl" include_shell "/usr/share/lighttpd/include-conf-enabled.pl"
sudo nano /etc/lighttpd/pass.txt
djnitehawk:WEB_SERVER_PASSWORD
sudo chmod 777 /etc/lighttpd/pass.txt sudo openssl req -new -x509 -keyout server.pem -out server.pem -days 36500 -nodes
sudo chmod 777 server.pem sudo mv server.pem /etc/lighttpd/ sudo lighty-enable-mod ssl
<?php $src = "/home/djnitehawk/Ready"; $del = $_GET['delete']; $clean = $_GET['clean']; if (!empty($del)){ $file = "$src$del"; unlink($file); echo "File Deleted: $file"; exit; } if (!empty($clean)){ if ($clean == 'yes') { RemoveEmptySubFolders($src); echo "Empty folders have been cleaned..."; } exit; } $res = ListIn($src, "$src/"); echo implode('|',$res); function RemoveEmptySubFolders($path) { $empty=true; foreach (glob($path.DIRECTORY_SEPARATOR."*") as $file) { $empty &= is_dir($file) && RemoveEmptySubFolders($file); } return $empty && rmdir($path); } function ListIn($dir, $prefix) { $dir = rtrim($dir, '\\/'); $result = array(); foreach (scandir($dir) as $f) { if ($f !== '.' and $f !== '..' and $f !== '.lock' and $f !== 'index.php') { if (is_dir("$dir/$f")) { $result = array_merge($result, ListIn("$dir/$f", "$prefix$f/")); } else { $result[] = $prefix.$f; } } } return $result; } ?>
chmod 777 ~/Ready/index.php sudo systemctl restart lighttpd
|