[GUIDE] Headphones for MBL

This guide assumes you have already installed SABnzb or Transmission following my guides

 

For more info, see https://github.com/rembo10/headphones

 

To Do:

Still need to get the headphones init.d script working 100%

It throws some errors on start and stop but it’s working

Install python2.7

ipkg install python27

 Change dir

cd /opt/share/

 Download HeadPhones

wget http://github.com/rembo10/headphones/tarball/master

 Rename

mv master headphones.tar.gz

 Extract

tar -xzvf headphones.tar.gz

 Remove download

rm -f headphones.tar.gz

 Rename directory

mv rembo10* headphones

 Start HeadPhones

/opt/bin/python2.7 /opt/share/headphones/Headphones.py

A menu will come up… Select update then hit q to quit

Then hit control and c to get back to command line

 Create a startup script

nano /etc/init.d/headphones

  Paste

#!/bin/sh
#
## Don't edit this file
## Edit user configuation in /etc/default/headphones to change
##
## Make sure init script is executable
## sudo chmod +x /opt/headphones/init.ubuntu
##
## Install the init script
## sudo ln -s /opt/headphones/init.ubuntu /etc/init.d/headphones
##
## Create the headphones daemon user:
## sudo adduser --system --no-create-home headphones
##
## Make sure /opt/headphones is owned by the headphones user
## sudo chown headphones:nogroup -R /opt/headphones
##
## Touch the default file to stop the warning message when starting
## sudo touch /etc/default/headphones
##
## To start Headphones automatically
## sudo update-rc.d headphones defaults
##
## To start/stop/restart Headphones
## sudo service headphones start
## sudo service headphones stop
## sudo service headphones restart
##
## HP_USER= #$RUN_AS, username to run headphones under, the default is headphones
## HP_HOME= #$APP_PATH, the location of Headphones.py, the default is /opt/headphones
## HP_DATA= #$DATA_DIR, the location of headphones.db, cache, logs, the default is /opt/headphones
## HP_PIDFILE= #$PID_FILE, the location of headphones.pid, the default is /var/run/headphones/headphones.pid
## PYTHON_BIN= #$DAEMON, the location of the python binary, the default is /usr/bin/python
## HP_OPTS= #$EXTRA_DAEMON_OPTS, extra cli option for headphones, i.e. " --config=/home/headphones/config.ini"
## SSD_OPTS= #$EXTRA_SSD_OPTS, extra start-stop-daemon option like " --group=users"
## HP_PORT= #$PORT_OPTS, hardcoded port for the webserver, overrides value in config.ini
##
## EXAMPLE if want to run as different user
## add HP_USER=username to /etc/default/headphones
## otherwise default headphones is used
#
### BEGIN INIT INFO
# Provides: headphones
# Required-Start: $local_fs $network $remote_fs
# Required-Stop: $local_fs $network $remote_fs
# Should-Start: $NetworkManager
# Should-Stop: $NetworkManager
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts instance of Headphones
# Description: starts instance of Headphones using start-stop-daemon
### END INIT INFO

# Script name
NAME=headphones

# App name
DESC=Headphones

SETTINGS_LOADED=FALSE

. /lib/lsb/init-functions

# Source Headphones configuration
if [-f /etc/default/headphones]; then
    SETTINGS=/etc/default/headphones
else
    log_warning_msg "/etc/default/headphones not found using default settings.";
fi

check_retval() {
    if [$? -eq 0]; then
        log_end_msg 0
        return 0
    else
        log_end_msg 1
        exit 1
    fi
}

load_settings() {
    if [$SETTINGS_LOADED != "TRUE"]; then
        . $SETTINGS

        ## The defaults
        # Run as username
        RUN_AS=${HP_USER-root}

        # Path to app HP_HOME=path_to_app_Headphones.py
        APP_PATH=${HP_HOME-/opt/share/headphones}

        # Data directory where headphones.db, cache and logs are stored
        DATA_DIR=${HP_DATA-/opt/share/headphones}

        # Path to store PID file
        PID_FILE=${HP_PIDFILE-/var/run/headphones/headphones.pid}

        # Path to python bin
        DAEMON=${PYTHON_BIN-/opt/bin/python2.7}

        # Extra daemon option like: HP_OPTS=" --config=/home/headphones/config.ini"
        EXTRA_DAEMON_OPTS=${HP_OPTS-}

        # Extra start-stop-daemon option like START_OPTS=" --group=users"
        EXTRA_SSD_OPTS=${SSD_OPTS-}

        # Hardcoded port to run on, overrides config.ini settings
        [-n "$HP_PORT"] && {
            PORT_OPTS=" --port=${HP_PORT} "
        }

        DAEMON_OPTS=" Headphones.py --quiet --daemon --nolaunch --pidfile=${PID_FILE} --datadir=${DATA_DIR} ${PORT_OPTS}${EXTRA_DAEMON_OPTS}"

        SETTINGS_LOADED=TRUE
    fi

    [-x $DAEMON] || {
        log_warning_msg "$DESC: Can't execute daemon, aborting. See $DAEMON";
        return 1;}

    return 0
}

load_settings || exit 0

is_running () {
    # returns 1 when running, else 0.
    if [-e $PID_FILE]; then
      PID=`cat $PID_FILE`

      RET=$?
      [$RET -gt 1] && exit 1 || return $RET
    else
      return 1
    fi
}

handle_pid () {
    PID_PATH=`dirname $PID_FILE`
    [-d $PID_PATH] || mkdir -p $PID_PATH && chown -R $RUN_AS $PID_PATH > /dev/null || {
        log_warning_msg "$DESC: Could not create $PID_FILE, See $SETTINGS, aborting.";
        return 1;}

    if [-e $PID_FILE]; then
        PID=`cat $PID_FILE`
        if ! kill -0 $PID > /dev/null 2>&1; then
            log_warning_msg "Removing stale $PID_FILE"
            rm $PID_FILE
        fi
    fi
}

handle_datadir () {
    [-d $DATA_DIR] || mkdir -p $DATA_DIR && chown -R $RUN_AS $DATA_DIR > /dev/null || {
        log_warning_msg "$DESC: Could not create $DATA_DIR, See $SETTINGS, aborting.";
        return 1;}
}

handle_updates () {
    chown -R $RUN_AS $APP_PATH > /dev/null || {
        log_warning_msg "$DESC: $APP_PATH not writable by $RUN_AS for web-updates";
        return 0; }
}

start_headphones () {
    handle_pid
    handle_datadir
    handle_updates
    if ! is_running; then
        log_daemon_msg "Starting $DESC"
        start-stop-daemon -o -d $APP_PATH -c $RUN_AS --start $EXTRA_SSD_OPTS --pidfile $PID_FILE --exec $DAEMON -- $DAEMON_OPTS
        check_retval
    else
        log_success_msg "$DESC: already running (pid $PID)"
    fi
}

stop_headphones () {
    if is_running; then
        log_daemon_msg "Stopping $DESC"
        start-stop-daemon -o --stop --pidfile $PID_FILE --retry 15
        check_retval
    else
        log_success_msg "$DESC: not running"
    fi
}

case "$1" in
    start)
        start_headphones
        ;;
    stop)
        stop_headphones
        ;;
    restart|force-reload)
        stop_headphones
        start_headphones
        ;;
    *)
        N=/etc/init.d/$NAME
        echo "Usage: $N {start|stop|restart|force-reload}" >&2
        exit 1
        ;;
esac

exit 0

Hit control and o

Hit enter

Hit control and x

This will save the edited file

 Now let’s set HeadPhones to start on a MBL reboot

chmod 755 /etc/init.d/headphones
update-rc.d headphones defaults

 Now start the server

/etc/init.d/headphones start

Now open a web browser and login to your mbl name or ip:8181

Setup and enjoy!

Again I don’t use HeadPhones but there were some requests so I put this guide together

Please feel free to share any setup information you may have for incorporating this with SABnzb or Transmission

2 Likes

Thanks for your contribution to the community and the MBL forums.

Hopefully some of the users that try this will chime in and report any issues and/or occurrences while trying this guide.

whats the function of the ‘headphone’ in regards to the MBL pls?

@sunky See here for more info

https://github.com/rembo10/headphones

Hi, it is me again :cry:

i also followed this guide (let me say thank you for the time and effort you are putting in these guides)

I cannot go further after step:

/opt/share# /opt/bin/python2.7 /opt/share/headphones/Headphones.py

I get this:
28-Sep-2013 21:15:55 - INFO :: MainThread : Checking to see if the database has all tables…
28-Sep-2013 21:15:57 - INFO :: MainThread : Retrieving latest version information from github
28-Sep-2013 21:15:58 - INFO :: MainThread : You are running an unknown version of Headphones. Run the updater to identify your version
28-Sep-2013 21:15:58 - INFO :: MainThread : Starting Headphones on http://0.0.0.0:8181/

And then nothing… could it because i have an different version of MBL? Because my previous was dead last week i get a new under warranty. But maybe it is newer software what won’t support this anymore?

Hope to help, i was pretty pleased with the configs…

It seems to work, i thought that i must see a screen in putty, but when i opened a browser hteadphones is working, also automatic start works after a restart of my MBL. this problem is solved!