Search:  
Gentoo Wiki

HOWTO_NzbGet

Contents

Introduction

Warning: This document is out-of-date and applies to version 0.2.3 of nzbget. From version 0.3.0 the program has different command-line syntax and configuration-file. The described technique to run the program as a daemon and to monitor for incoming nzb-files are not necessary in newer program versions, since these features are now built-in.


This wiki will help install nzbget and set up a downloader for NZB files.

A NZB file is a list of files residing on a news server. When these NZB files are dropped into the nzb folder they will be automatically queued and downloading will begin.

Note: There are two ways to run nzbget. This page documents how to run nzbget as a server. You can also run it stand-alone if you just want to manually run nzbget for each nzb file. In that case, simply type nzbget -n somefile.nzb. You'll still need to create the configuration file as shown below. You may also need to create any directories referenced by your configuration file. You don't need to create the init and queue scripts, modify the crontab, or run rc-update if you don't want a server that automatically downloads nzb files.

Requirements

  1. Gentoo Linux, running
  2. nzbget package
  3. A cron daemon

This guide will walk through setting up nzbget with an automatic queue system.

Package Installation

Install nzbget

Login as root

su

To install nzbget emerge it with the command

emerge nzbget

You must also emerge a cron daemon. If you have followed the install guide correctly this will already be installed. Substitue vixie-cron with your favorite cron daemon.

emerge vixie-cron

Create Directories

We will now create the directories needed for the installation. You can change these to whatever you see fit but remember to modify the config file and autoqueue scripts aswell.

mkdir /root/.nzbget
mkdir /root/scripts
mkdir /data
mkdir /data/download
mkdir /data/download/nzb
mkdir /data/download/nzb/queued
mkdir /data/download/temp
mkdir /data/download/complete

Configuration File

After nzbget has been installed we must create the config file.

nano -w /root/.nzbget/nzbget.cfg

You should copy and paste the following code to the config file. After copying this file modify the server configuration for your setup.

File: /root/.nzbget/nzbget.cfg
<nzbget-config>
  <options>

    <!-- GLOBAL OPTIONS -->
    <option name="tempdir">/data/download/temp</option>        <!-- directory to store temporary files -->
    <option name="destinationdir">/data/download/complete</option> <!-- destination-directory to store the downloaded files -->
    <option name="appendpostnametodir">no</option>             <!-- Append post's name to destinationdir? -->
                                                               <!-- works only if nzbfile is named: msgid_123456_POSTNAME.nzb -->
    <option name="outputmode">logable</option>                  <!-- sets outputmode. May be "curses", "colored", or "logable" -->
    <option name="dupecheck">yes</option>                      <!-- enables/disables dupechecking -->
    <option name="downloadrate">0</option>                     <!-- Set the maximum download rate to 100 kB/s -->
    <option name="renamebroken">yes</option>                   <!-- Visibly rename broken files on download appending "_broken"? -->
    <option name="serverip">localhost</option>                 <!-- Set the IP which the client uses to contact the server -->
    <option name="serverport">6789</option>                    <!-- Set the port which the server & client use -->
    <option name="serverpassword">password</option>            <!-- Set the password needed to succesfully queue a request -->
    <option name="reloadqueue">yes</option>                    <!-- Possible values are yes, no and ask -->
    <option name="info">log</option>                        <!-- Possible values are screen, log, both, none -->
    <option name="warning">log</option>                     <!-- Possible values are screen, log, both, none -->
    <option name="error">log</option>                       <!-- Possible values are screen, log, both, none -->
    <option name="createbrokenfilelog">no</option>             <!-- Creates a log of all broken files, values yes/no -->
  </options>
  <servers>

    <!-- This section defines which servers nzbget should connect to. -->
    <!-- The servers will be ordered by their level, i.e. nzbget will at -->
    <!-- first try to download an article from the level-0-server. -->
    <!-- If that server fails, nzbget proceeds with the level-1-server, etc. -->
    <!-- A good idea is surely to put your major download-server at level 0 -->
    <!-- and your fill-servers at levels 1,2,... -->
    <!-- NOTE: Do not leave out a level in your server-list and start with level 0! -->

    <server level="0">
      <host>news.newsdemon.com</host>       <!-- host-name of newsserver -->
      <port>119</port>                      <!-- port to connect to (default 119 if not specified) -->
      <user>10014045</user>                 <!-- username to use for authentication -->
      <pass>PASSWORD</pass>                 <!-- password to use for authentication -->
      <connections>4</connections>          <!-- maximal number of simultaneous connections to this server -->
    </server>

    <server level="1">                      <!-- I have setup a SSH port forward so I can get more connections to my server -->
      <host>localhost</host>
      <port>10119</port>
      <user>10014091</user>
      <pass>PASSWORD</pass>
      <connections>4</connections>
    </server>

  </servers>
</nzbget-config>

Create Queue Script

Create the autoqueue script file

nano -w /root/scripts/nzbcue
File: /root/scripts/nzbcue

#!/bin/sh

QUEUE_DIR="/data/download/nzb/"
QUEUED_DIR="/data/download/nzb/queued/"

find $QUEUE_DIR -maxdepth 1 -regex ".*\.nzb" -type f | while read f; do
        nzbget "${f}" && \
        gzip "${f}" && \
        mv "${f}.gz" $QUEUED_DIR
done

Make Script Executable and accessable only by root

chmod 700 /root/scripts/nzbcue

Create Init.d script

Create the script for nzbget server.

nano -w /etc/init.d/nzbserver
File: /etc/init.d/nzbserver
#!/sbin/runscript
# Copyright 1999-2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header$

# This could possibly need some work.
#  The start-stop-daemon proably isn't the best method but...

depend() {
        need net
        use dns logger
}

start() {
        ebegin "Starting NZBGET Server"
        start-stop-daemon --start -m -b\
                --pidfile /var/run/nzbserver.pid \
                --startas /usr/bin/nzbget --\
                -s
        eend $?
}

stop() {
        ebegin "Stopping NZBGET Server"
        start-stop-daemon --stop --pidfile /var/run/nzbserver.pid
        eend $?
}

The permissions on the script must be made executable by root

chmod 755 /etc/init.d/nzbserver

Now we can add the script to start at boot time

rc-update add nzbserver default

Add AutoQueue Script to the crontab

crontab -e

Add the following line to the crontab. This will execute every minute.

* * * * * /root/scripts/nzbcue

Once complete you may logout of root

exit

To Do

./nzbcue: line 10: syntax error near unexpected token `done' <<<< WTF?


Modify the setup so details on speed and current file are accessable via webserver. Anyone want to finish??

NzbGet >=0.3.x

Although the configuration file for the newer versions of nzbget are not XML, they are still straight forward to setup. Other major changes include the addition of par2 checking/repair through app-arch/libpar2, a more power ncurses-powered GUI that allows the editting of your queue on a per-file and per-nzb basis, and also a PHP-powered web interface that can be installed but is a separate package. After the initial installation from source retrievable from the SF NZBGet Project Page I wrote two small bash scripts to make life easier.

File: /usr/local/bin/queueNZB
#!/bin/bash

#
# Settings
#
HISTDIR=~/download/hist
NZBGET=/usr/local/bin/nzbget
NOTIFY=/usr/bin/notify-send
SELF=/usr/local/bin/queueNZB

#
# First, verify if nzbget is running
#
if [[ -z $(pidof nzbget) ]]; then
	$NOTIFY -t 5000 "NZB Queue Error" "nzbget server is not running"
	exit 1
fi

#
# Second, create HISTDIR if it doesn't exist
#
if [ -d "$HISTDIR" ]; then
	# Do nothing, directory exists
else
	# Create this directory
	mkdir -p $HISTDIR
fi


#
# Handle different numbers of arguments
#
if [ $# -eq 0 ]; then
	# Error, no args submitted
	$NOTIFY -t 4000 "NZB Queue Error" "No arguments submitted"
	exit 1
elif [[ $# -gt 1 ]]; then
	# Handle all the arguments
	args=( "$@" )
	c=$#
	for((i=0;i<$c;i+=1)); do
		# Call the queue
		$SELF "${args[$i]}"
	done

	exit 0
fi


# Get just the filename, no path
FILENAME=`echo "${1}" | egrep -o "[^/]+$"`

# Trim the extension to get the postname
POSTNAME=${FILENAME:0:(${#FILENAME} - 4)}

if [ -f "$1" ]; then
	#
	# Continue w/ the queuing
	#

	# Queue the nzb
	$NZBGET -A "$1"

	# Compress the file
	gzip -9 "$1"

	# Move the file into the history folder
	mv "$1.gz" "$HISTDIR/$POSTNAME.gz"
	
	# Notify the user that the NZB has been queued
	/usr/bin/notify-send -t 1800 "NZB Queued" "$POSTNAME"
else
	#
	# Alert there is no such file
	#
	notify-send -t 3500 "No Such NZB" "There is no NZB at that path! $1"
fi

queueNZB requires libnotify and can take any number of arguments and queue up all of the files. It will also perform a pre-execution check to verify that nzbget is in fact running, though this script could be more robust with the addition of checking if the nzbget is running in server mode and if the queue command was successful or not. This is one of my first attempts at bash scripting and it's late so it'll do for a first revision. Remember to give permission to execute this file.

File: /usr/local/bin/nzbComplete
#!/bin/bash

NOTIFY=/usr/bin/notify-send
TIMEOUT=5000

DESTDIR=$1
#!/bin/bash

NOTIFY=/usr/bin/notify-send
TIMEOUT=5000

DESTDIR=$1
NZB=`echo "$2" | egrep -o "[^/]+$"`
PAR=`echo "$3" | egrep -o "[^/]+$"`
PARRESULT=$4
NZBSTATE=$5
PARSTATE=$6

if [[ $PARRESULT -eq 0 ]]; then
	$NOTIFY -t $TIMEOUT "NZB - Unchecked" "`echo -e "$NZB\n$PAR"`"
elif [[ $PARRESULT -eq 1 ]]; then
	$NOTIFY -t $TIMEOUT --urgency=critical "NZB - Unrepairable" "`echo -e "$NZB\n$PAR"`"
elif [[ $PARRESULT -eq 2 ]]; then
	$NOTIFY -t $TIMEOUT "NZB - Repaired" "`echo -e "$NZB\n$PAR"`"
elif [[ $PARRESULT -eq 3 ]]; then
	$NOTIFY -t $TIMEOUT --urgency=critical "NZB - Needs Repair" "$NZB needs to be repaired but you have nzbget's repair option disabled.  Check $DESTDIR"
fi

nzbComplete is even simpler script that just calls notify-send (from libnotify) to show me some results in my graphical environment. The utility of this script is further increased if you have your nzbget in daemon mode. The reason for the unused variables at the top is to facilitate additions to this script by other parties without requiring them to reference the config. To enable this script, edit your nzbget configuration file and set the PostProcess parameter to be the path of this script. Again, don't forget to set executable permissions for this file.

Retrieved from "http://www.gentoo-wiki.info/HOWTO_NzbGet"

Last modified: Fri, 05 Sep 2008 10:05:00 +0000 Hits: 12,851