diff --git a/maraschino/__init__.py b/maraschino/__init__.py index 83f3f9f6..dc2e1d59 100644 --- a/maraschino/__init__.py +++ b/maraschino/__init__.py @@ -44,7 +44,7 @@ COMMITS_BEHIND = 0 COMMITS_COMPARE_URL = '' FIRST_RUN = 0 - +SABNZB_STATE = 'downloading' def initialize(): """Init function for this module""" @@ -52,7 +52,7 @@ def initialize(): 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 diff --git a/modules/sabnzbd.py b/modules/sabnzbd.py index 63f81499..d9d716f2 100644 --- a/modules/sabnzbd.py +++ b/modules/sabnzbd.py @@ -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 @@ -75,9 +71,14 @@ def sabnzbd_api(method='', params='', use_json=True, dev=False): @app.route('/xhr/sabnzbd/') -@app.route('/xhr/sabnzbd/') +@app.route('/xhr/sabnzbd//') @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'): @@ -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' @@ -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 ) diff --git a/static/js/index.js b/static/js/index.js index fa712206..6780f9ff 100644 --- a/static/js/index.js +++ b/static/js/index.js @@ -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) @@ -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 **********/ diff --git a/static/less/module-sabnzbd.less b/static/less/module-sabnzbd.less index a14831f7..17bf2d46 100644 --- a/static/less/module-sabnzbd.less +++ b/static/less/module-sabnzbd.less @@ -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; @@ -108,7 +137,7 @@ } } - .queue { + .results { max-height: 190px; margin-top: 20px; padding-right: 0.5%; @@ -148,7 +177,8 @@ } .delete, - .pause { + .pause, + .retry { width: 15px; cursor: pointer; background: url('/@{webroot}/images/alpha/fff_20.png') !important; diff --git a/templates/sabnzbd/base.html b/templates/sabnzbd/base.html index dcc4bec8..ce5f5fb5 100644 --- a/templates/sabnzbd/base.html +++ b/templates/sabnzbd/base.html @@ -10,7 +10,55 @@

{% if sabnzbd %} - {% block sabnzbd_content %}{% endblock %} +
+ {{ sabnzbd.status }} + +
    +
  • Pause for:
  • +
  • 5 minutes
  • +
  • 15 minutes
  • +
  • 30 minutes
  • +
  • 1 hour
  • +
  • 3 hours
  • +
  • 6 hours
  • +
  • Other...
  • +
+
+
{{ download_speed[-4:] }}
+ + {% if item %} +

{{ item.filename }}

+ +
+
+
+ +
+

Remaining: {{ item.timeleft }} / {{ item.mbleft }} MB

+

{{ item.percentage }}% complete

+
+

Total Remaining: {{sabnzbd.timeleft}} / {{sabnzbd.sizeleft}}

+
+ {% endif %} + +
+
+ +
+ +
+ +
+
+ + {% if sab_state == 'queue' %} + {% include 'sabnzbd/queue.html' %} + {% endif %} + + {% if sab_state == 'history' %} + {% include 'sabnzbd/history.html' %} + {% endif %} + {% elif message %} {{ message }} {% endif %} diff --git a/templates/sabnzbd/history.html b/templates/sabnzbd/history.html new file mode 100644 index 00000000..ea2a9d2f --- /dev/null +++ b/templates/sabnzbd/history.html @@ -0,0 +1,26 @@ +
+ + {% for x in history.slots %} + + {% if x.status == 'Completed' %} + + {% elif x.status == 'Failed' %} + + {% else %} + + {% endif %} + + + + + {% endfor %} +
+ + + + + + {{x.nzb_name|truncate(48, 'false')}}{{x.size}} + +
+
\ No newline at end of file diff --git a/templates/sabnzbd/queue.html b/templates/sabnzbd/queue.html index 4529f7dc..07c60c87 100644 --- a/templates/sabnzbd/queue.html +++ b/templates/sabnzbd/queue.html @@ -1,50 +1,5 @@ -{% extends "sabnzbd/base.html" %} - -{% block sabnzbd_content %} -
- {{ sabnzbd.status }} - -
    -
  • Pause for:
  • -
  • 5 minutes
  • -
  • 15 minutes
  • -
  • 30 minutes
  • -
  • 1 hour
  • -
  • 3 hours
  • -
  • 6 hours
  • -
  • Other...
  • -
-
-
{{ download_speed[-4:] }}
- - {% if item %} -

{{ item.filename }}

- -
-
-
- -
-

Remaining: {{ item.timeleft }} / {{ item.mbleft }} MB

-

{{ item.percentage }}% complete

-
-{% endif %} - -
- - - - - -
Total Remaining: {{sabnzbd.timeleft}} / {{sabnzbd.sizeleft}} - {% if queue_status == 'hide' %} More - {% else %} Less - {% endif %} -
-
- -
- +
+
{% for x in sabnzbd.slots %} @@ -53,6 +8,5 @@ {% endfor %} -
-
-{% endblock %} + +
\ No newline at end of file