Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add history/queue persistence to sabnzbd module #355

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions maraschino/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@
COMMITS_BEHIND = 0
COMMITS_COMPARE_URL = ''
FIRST_RUN = 0

SABNZB_STATE = 'downloading'

def initialize():
"""Init function for this module"""
with INIT_LOCK:

global __INITIALIZED__, app, FULL_PATH, RUNDIR, ARGS, DAEMON, PIDFILE, VERBOSE, LOG_FILE, LOG_DIR, logger, PORT, SERVER, DATABASE, AUTH, \
UPDATER, CURRENT_COMMIT, LATEST_COMMIT, COMMITS_BEHIND, COMMITS_COMPARE_URL, USE_GIT, WEBROOT, HOST, KIOSK, DATA_DIR, SCRIPT_DIR, \
THREADS, FIRST_RUN
THREADS, FIRST_RUN, SABNZB_STATE

if __INITIALIZED__:
return False
Expand Down
29 changes: 15 additions & 14 deletions modules/sabnzbd.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
try:
import json
except ImportError:
import simplejson as json

from flask import jsonify, render_template, request
from flask import jsonify, render_template, request, json
import urllib
import urllib2
from jinja2.filters import FILTERS

from Maraschino import app
from maraschino.tools import *
import maraschino
from maraschino import logger


Expand Down Expand Up @@ -75,9 +71,14 @@ def sabnzbd_api(method='', params='', use_json=True, dev=False):


@app.route('/xhr/sabnzbd/')
@app.route('/xhr/sabnzbd/<queue_status>')
@app.route('/xhr/sabnzbd/<sab_state>/')
@requires_auth
def xhr_sabnzbd(queue_status='hide'):
def xhr_sabnzbd(sab_state=None):
if sab_state:
maraschino.SABNZB_STATE = sab_state
else:
sab_state = maraschino.SABNZB_STATE

old_config = False

if not get_setting_value('sabnzbd_host'):
Expand All @@ -91,9 +92,8 @@ def xhr_sabnzbd(queue_status='hide'):
message = None

try:
result = urllib.urlopen(sabnzbd_url('queue')).read()
sabnzbd = json.JSONDecoder().decode(result)
sabnzbd = sabnzbd['queue']
sabnzbd = sabnzbd_api(method='queue')['queue']
history = sabnzbd_api(method='history', params='&limit=50')['history']

download_speed = format_number(int((sabnzbd['kbpersec'])[:-3]) * 1024) + '/s'

Expand All @@ -109,15 +109,16 @@ def xhr_sabnzbd(queue_status='hide'):
if not sabnzbd:
message = 'There was a problem reaching SabNZBd.'

return render_template('sabnzbd/queue.html',
return render_template('sabnzbd/base.html',
sabnzbd=sabnzbd,
app_link=sabnzbd_url_no_api(),
item=downloading,
download_speed=download_speed,
old_config=old_config,
queue_status=queue_status,
show_empty=get_setting_value('sabnzbd_show_empty') == '1',
message=message
message=message,
history=history,
sab_state=sab_state
)


Expand Down
25 changes: 24 additions & 1 deletion static/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1275,7 +1275,7 @@ $(document).ready(function() {
}
});

$(document).on('click', '#sabnzbd .inner .queue table tr td.pause', function(){
$(document).on('click', '#sabnzbd .inner #queue tr td.pause', function(){
var id = $(this).parent('tr').attr('id');
var state = $(this).parent('tr').data('action');
$.get(WEBROOT + '/xhr/sabnzbd/individual/'+state+'/'+id)
Expand Down Expand Up @@ -1352,6 +1352,29 @@ $(document).ready(function() {
}
});

$(document).on('click', '#sabnzbd #history .delete, #sabnzbd #history .retry', function(){
var btn = $(this);
$.get($(this).data('url'), function(data) {
if(data.status){
if (btn.attr('class') == 'remove') {
btn.parent().remove();
}
}
});
});

$(document).on('click', '#sabnzbd .button', function(){
var id = $(this).attr('id');
var active = $(this).hasClass('active');

if (active === true) {
get_module('sabnzbd', { poll:10, params: [ 'downloading' ] });
}
else {
get_module('sabnzbd', { poll:10, params: [ id ] });
};
});

/********* END SABNZBD ***********/

/********* CouchPotato **********/
Expand Down
34 changes: 32 additions & 2 deletions static/less/module-sabnzbd.less
Original file line number Diff line number Diff line change
@@ -1,6 +1,35 @@
#sabnzbd
{
position: relative;
.button_holder {
text-align: right;
}
.button {
background: url('/@{webroot}/images/alpha/fff_10.png');
border: 1px solid #222;
cursor: pointer;
display: inline-block;
line-height: 1.1em;
margin-top: 5px;
padding: 2px 8px;
right: 0px;
color: #ccc;
font-size: 1.5em;
.border-radius(4px);

&:hover {
background: url('/@{webroot}/images/alpha/fff_20.png');
}

&.active {
background: url('/@{webroot}/images/alpha/fff_20.png');
}

img {
width: 14px;
height: 14px;
}
}

> .inner {
line-height: 1.3em;
Expand Down Expand Up @@ -108,7 +137,7 @@
}
}

.queue {
.results {
max-height: 190px;
margin-top: 20px;
padding-right: 0.5%;
Expand Down Expand Up @@ -148,7 +177,8 @@
}

.delete,
.pause {
.pause,
.retry {
width: 15px;
cursor: pointer;
background: url('/@{webroot}/images/alpha/fff_20.png') !important;
Expand Down
50 changes: 49 additions & 1 deletion templates/sabnzbd/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,55 @@ <h2>

<div class="inner">
{% if sabnzbd %}
{% block sabnzbd_content %}{% endblock %}
<div class="status" id="status" status="{{ sabnzbd.paused }}" title="Toggle paused/downloading">
{{ sabnzbd.status }}
<img class="pause_arrow" src="{{ url_for('static', filename='images/arrow_down.png') }}">
<ul class="pause_list">
<li>Pause for: </li>
<li class="pause_time" data-time="5">5 minutes</li>
<li class="pause_time" data-time="15">15 minutes</li>
<li class="pause_time" data-time="30">30 minutes</li>
<li class="pause_time" data-time="60">1 hour</li>
<li class="pause_time" data-time="180">3 hours</li>
<li class="pause_time" data-time="360">6 hours</li>
<li class="pause_for">Other...</li>
</ul>
</div>
<div class="speed"><input type="text" value="{{ download_speed[:-4] }}" title="Adjust Speed" size="5"/>{{ download_speed[-4:] }}</div>

{% if item %}
<p>{{ item.filename }}</p>

<div class="bar">
<div class="inner" style="width: {{ item.percentage }}%;"></div>
</div>

<div class="clearfix">
<p class="remaining"><strong>Remaining:</strong> {{ item.timeleft }} / {{ item.mbleft }} MB</p>
<p class="percentage_complete">{{ item.percentage }}% complete</p>
<br>
<p class="remaining"><strong>Total Remaining:</strong> {{sabnzbd.timeleft}} / {{sabnzbd.sizeleft}}</p>
</div>
{% endif %}

<div class="button_holder">
<div id="queue" class="button {{ 'active' if sab_state == 'queue'}}" title="{{ 'View' if sab_state != 'queue' else 'Hide' }} Queue">
<img src="{{ url_for('static', filename='images/coming.png') }}"/>
</div>

<div id="history" class="button {{ 'active' if sab_state == 'history'}}" title="{{ 'View' if sab_state != 'history' else 'Hide' }} History">
<img src="{{ url_for('static', filename='images/history.png') }}"/>
</div>
</div>

{% if sab_state == 'queue' %}
{% include 'sabnzbd/queue.html' %}
{% endif %}

{% if sab_state == 'history' %}
{% include 'sabnzbd/history.html' %}
{% endif %}

{% elif message %}
{{ message }}
{% endif %}
Expand Down
26 changes: 26 additions & 0 deletions templates/sabnzbd/history.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<div class="results">
<table id="history">
{% for x in history.slots %}
<tr id="{{x.nzo_id}}">
{% if x.status == 'Completed' %}
<td class="pause">
<img src="{{ url_for('static', filename='images/tick.png') }}" >
</td>
{% elif x.status == 'Failed' %}
<td class="retry" data-url="{{ webroot_url('/xhr/sabnzbd/history/retry/' + x.nzo_id) }}">
<img src="{{url_for('static', filename='images/refresh.png')}}" >
</td>
{% else %}
<td class="pause">
<img src="{{url_for('static', filename='images/xhrloading.gif')}}" >
</td>
{% endif %}
<td class="name">{{x.nzb_name|truncate(48, 'false')}}</td>
<td class="size">{{x.size}}</td>
<td class="delete" data-url="{{ webroot_url('/xhr/sabnzbd/history/delete/' + x.nzo_id) }}">
<img src="{{ url_for('static', filename='images/remove_icon.png') }}" >
</td>
</tr>
{% endfor %}
</table>
</div>
54 changes: 4 additions & 50 deletions templates/sabnzbd/queue.html
Original file line number Diff line number Diff line change
@@ -1,50 +1,5 @@
{% extends "sabnzbd/base.html" %}

{% block sabnzbd_content %}
<div class="status" id="status" status="{{ sabnzbd.paused }}" title="Toggle paused/downloading">
{{ sabnzbd.status }}
<img class="pause_arrow" src="{{ url_for('static', filename='images/arrow_down.png') }}">
<ul class="pause_list">
<li>Pause for: </li>
<li class="pause_time" data-time="5">5 minutes</li>
<li class="pause_time" data-time="15">15 minutes</li>
<li class="pause_time" data-time="30">30 minutes</li>
<li class="pause_time" data-time="60">1 hour</li>
<li class="pause_time" data-time="180">3 hours</li>
<li class="pause_time" data-time="360">6 hours</li>
<li class="pause_for">Other...</li>
</ul>
</div>
<div class="speed"><input type="text" value="{{ download_speed[:-4] }}" title="Adjust Speed" size="5"/>{{ download_speed[-4:] }}</div>

{% if item %}
<p>{{ item.filename }}</p>

<div class="bar">
<div class="inner" style="width: {{ item.percentage }}%;"></div>
</div>

<div class="clearfix">
<p class="remaining"><strong>Remaining:</strong> {{ item.timeleft }} / {{ item.mbleft }} MB</p>
<p class="percentage_complete">{{ item.percentage }}% complete</p>
</div>
{% endif %}

<div class="queue-title {% if not item %}hide{% endif %}">
<table width=100%>
<tr>
<td align=left><b>Total Remaining:</b> {{sabnzbd.timeleft}} / {{sabnzbd.sizeleft}}</td>
<td align=right><span>
{% if queue_status == 'hide' %} <img src="{{ url_for('static', filename='images/arrow_down.png')}}">More
{% else %} <img src="{{ url_for('static', filename='images/arrow_up.png') }}">Less
{% endif %}
</span></td>
</tr>
</table>
</div>

<div class="queue {% if item %}{{ queue_status }}{% else %}show{% endif %}">
<table>
<div class="results">
<table id="queue">
{% for x in sabnzbd.slots %}
<tr id="{{x.nzo_id}}" data-action={% if x.status == 'Paused' %}resume{% else %}pause{% endif %}>
<td class="pause"><img src="{% if x.status == 'Paused' %}{{ url_for('static', filename='images/pause.png') }}{% else %}{{ url_for('static', filename='images/play.png') }}{% endif %}" ></td>
Expand All @@ -53,6 +8,5 @@
<td class="delete"><img src="{{ url_for('static', filename='images/remove_icon.png') }}" ></td>
</tr>
{% endfor %}
</table>
</div>
{% endblock %}
</table>
</div>