Browse Source

Notifications selection based on Categories

Closes #716
tags/2.2.0Alpha3
Safihre 8 years ago
parent
commit
7333d19e1c
  1. 106
      interfaces/Config/templates/config_notify.tmpl
  2. 3
      interfaces/Config/templates/staticcfg/css/style.css
  3. 11
      sabnzbd/cfg.py
  4. 4
      sabnzbd/emailer.py
  5. 19
      sabnzbd/interface.py
  6. 35
      sabnzbd/notifier.py
  7. 2
      sabnzbd/nzbqueue.py
  8. 8
      sabnzbd/postproc.py
  9. 2
      sabnzbd/urlgrabber.py

106
interfaces/Config/templates/config_notify.tmpl

@ -13,6 +13,18 @@
<!--#end for#--> <!--#end for#-->
<!--#end def#--> <!--#end def#-->
<!--#def show_cat_box($section_label)#-->
<div class="col2-cats" <!--#if int($getVar($section_label + '_enable')) > 0 then '' else 'style="display:none"'#-->>
<hr>
<b>$T('affectedCat')</b><br/>
<select name="${section_label}_cats" multiple="multiple" class="multiple_cats">
<!--#for $ct in $categories#-->
<option value="$ct" <!--#if $ct in $getVar($section_label + '_cats') then 'selected="selected"' else ""#-->>$Tspec($ct)</option>
<!--#end for#-->
</select>
</div>
<!--#end def#-->
<div class="colmask"> <div class="colmask">
<form action="saveEmail" method="post" name="fullform" class="fullform" autocomplete="off" novalidate> <form action="saveEmail" method="post" name="fullform" class="fullform" autocomplete="off" novalidate>
<input type="hidden" id="session" name="session" value="$session" /> <input type="hidden" id="session" name="session" value="$session" />
@ -20,7 +32,15 @@
<div class="section" id="email"> <div class="section" id="email">
<div class="col2"> <div class="col2">
<h3>$T('cmenu-email') <a href="$helpuri$help_uri#toc0" target="_blank"><span class="glyphicon glyphicon-question-sign"></span></a></h3> <h3>$T('cmenu-email') <a href="$helpuri$help_uri#toc0" target="_blank"><span class="glyphicon glyphicon-question-sign"></span></a></h3>
</div><!-- /col2 --> <div class="col2-cats" <!--#if int($email_endjob) > 0 then '' else 'style="display:none"'#-->>
<b>$T('affectedCat')</b><br/>
<select name="email_cats" multiple="multiple" class="multiple_cats">
<!--#for $ct in $categories#-->
<option value="$ct" <!--#if $ct in $email_cats then 'selected="selected"' else ""#-->>$Tspec($ct)</option>
<!--#end for#-->
</select>
</div>
</div>
<div class="col1"> <div class="col1">
<fieldset> <fieldset>
<div class="field-pair"> <div class="field-pair">
@ -79,8 +99,8 @@
<div class="alert"></div> <div class="alert"></div>
</div> </div>
</fieldset> </fieldset>
</div><!-- /col1 --> </div>
</div><!-- /section --> </div>
<!--#if $have_ncenter#--> <!--#if $have_ncenter#-->
<div class="section"> <div class="section">
<div class="col2"> <div class="col2">
@ -91,7 +111,7 @@
<td><label for="ncenter_enable"> $T('opt-ncenter_enable')</label></td> <td><label for="ncenter_enable"> $T('opt-ncenter_enable')</label></td>
</tr> </tr>
</table> </table>
</div><!-- /col2 --> </div>
<div class="col1" <!--#if int($ncenter_enable) > 0 then '' else 'style="display:none"'#-->> <div class="col1" <!--#if int($ncenter_enable) > 0 then '' else 'style="display:none"'#-->>
<fieldset> <fieldset>
$show_notify_checkboxes('ncenter') $show_notify_checkboxes('ncenter')
@ -103,8 +123,8 @@
<div class="alert"></div> <div class="alert"></div>
</div> </div>
</fieldset> </fieldset>
</div><!-- /col1 --> </div>
</div><!-- /section --> </div>
<!--#end if#--> <!--#end if#-->
<!--#if $nt#--> <!--#if $nt#-->
<div class="section"> <div class="section">
@ -116,7 +136,8 @@
<td><label for="acenter_enable"> $T('opt-acenter_enable')</label></td> <td><label for="acenter_enable"> $T('opt-acenter_enable')</label></td>
</tr> </tr>
</table> </table>
</div><!-- /col2 --> $show_cat_box('acenter')
</div>
<div class="col1" <!--#if int($acenter_enable) > 0 then '' else 'style="display:none"'#-->> <div class="col1" <!--#if int($acenter_enable) > 0 then '' else 'style="display:none"'#-->>
<fieldset> <fieldset>
$show_notify_checkboxes('acenter') $show_notify_checkboxes('acenter')
@ -128,8 +149,8 @@
<div class="alert"></div> <div class="alert"></div>
</div> </div>
</fieldset> </fieldset>
</div><!-- /col1 --> </div>
</div><!-- /section --> </div>
<!--#end if#--> <!--#end if#-->
<!--#if $have_ntfosd#--> <!--#if $have_ntfosd#-->
<div class="section"> <div class="section">
@ -141,7 +162,8 @@
<td><label for="ntfosd_enable"> $T('opt-ntfosd_enable')</label></td> <td><label for="ntfosd_enable"> $T('opt-ntfosd_enable')</label></td>
</tr> </tr>
</table> </table>
</div><!-- /col2 --> $show_cat_box('ntfosd')
</div>
<div class="col1" <!--#if int($ntfosd_enable) > 0 then '' else 'style="display:none"'#-->> <div class="col1" <!--#if int($ntfosd_enable) > 0 then '' else 'style="display:none"'#-->>
<fieldset> <fieldset>
$show_notify_checkboxes('ntfosd') $show_notify_checkboxes('ntfosd')
@ -153,8 +175,8 @@
<div class="alert"></div> <div class="alert"></div>
</div> </div>
</fieldset> </fieldset>
</div><!-- /col1 --> </div>
</div><!-- /section --> </div>
<!--#end if#--> <!--#end if#-->
<div class="section" id="growl"> <div class="section" id="growl">
<div class="col2"> <div class="col2">
@ -165,7 +187,8 @@
<td><label for="growl_enable"> $T('opt-growl_enable')</label></td> <td><label for="growl_enable"> $T('opt-growl_enable')</label></td>
</tr> </tr>
</table> </table>
</div><!-- /col2 --> $show_cat_box('growl')
</div>
<div class="col1" <!--#if int($growl_enable) > 0 then '' else 'style="display:none"'#-->> <div class="col1" <!--#if int($growl_enable) > 0 then '' else 'style="display:none"'#-->>
<fieldset> <fieldset>
<div class="field-pair"> <div class="field-pair">
@ -187,8 +210,8 @@
<div class="alert"></div> <div class="alert"></div>
</div> </div>
</fieldset> </fieldset>
</div><!-- /col1 --> </div>
</div><!-- /section --> </div>
<div class="section" id="prowl"> <div class="section" id="prowl">
<div class="col2"> <div class="col2">
<h3>$T('section-Prowl')</h3> <h3>$T('section-Prowl')</h3>
@ -199,7 +222,8 @@
</tr> </tr>
</table> </table>
<em>$T('explain-prowl_enable')</em> <em>$T('explain-prowl_enable')</em>
</div><!-- /col2 --> $show_cat_box('prowl')
</div>
<div class="col1" <!--#if int($prowl_enable) > 0 then '' else 'style="display:none"'#-->> <div class="col1" <!--#if int($prowl_enable) > 0 then '' else 'style="display:none"'#-->>
<fieldset> <fieldset>
<div class="field-pair"> <div class="field-pair">
@ -231,8 +255,8 @@
<div class="alert"></div> <div class="alert"></div>
</div> </div>
</fieldset> </fieldset>
</div><!-- /col1 --> </div>
</div><!-- /section --> </div>
<div class="section" id="pushover"> <div class="section" id="pushover">
<div class="col2"> <div class="col2">
@ -244,7 +268,8 @@
</tr> </tr>
</table> </table>
<em>$T('explain-pushover_enable')</em> <em>$T('explain-pushover_enable')</em>
</div><!-- /col2 --> $show_cat_box('pushover')
</div>
<div class="col1" <!--#if int($pushover_enable) > 0 then '' else 'style="display:none"'#-->> <div class="col1" <!--#if int($pushover_enable) > 0 then '' else 'style="display:none"'#-->>
<fieldset> <fieldset>
<div class="field-pair"> <div class="field-pair">
@ -286,8 +311,8 @@
<div class="alert"></div> <div class="alert"></div>
</div> </div>
</fieldset> </fieldset>
</div><!-- /col1 --> </div>
</div><!-- /section --> </div>
<div class="section" id="pushbullet"> <div class="section" id="pushbullet">
<div class="col2"> <div class="col2">
<h3>$T('section-Pushbullet')</h3> <h3>$T('section-Pushbullet')</h3>
@ -298,7 +323,8 @@
</tr> </tr>
</table> </table>
<em>$T('explain-pushbullet_enable')</em> <em>$T('explain-pushbullet_enable')</em>
</div><!-- /col2 --> $show_cat_box('pushbullet')
</div>
<div class="col1" <!--#if int($pushbullet_enable) > 0 then '' else 'style="display:none"'#-->> <div class="col1" <!--#if int($pushbullet_enable) > 0 then '' else 'style="display:none"'#-->>
<fieldset> <fieldset>
<div class="field-pair"> <div class="field-pair">
@ -322,19 +348,20 @@
<div class="alert"></div> <div class="alert"></div>
</div> </div>
</fieldset> </fieldset>
</div><!-- /col1 --> </div>
</div><!-- /section --> </div>
<div class="section" id="nscript"> <div class="section" id="nscript">
<div class="col2"> <div class="col2">
<h3>$T('section-NScript')</h3> <h3>$T('section-NScript')</h3>
<table> <table>
<tr> <tr>
<td><input type="checkbox" name="nscript_enable" id="nscript_enable" value="1" <!--#if int($nscript_enable) > 0 then 'checked="checked"' else ""#--> /></td> <td><input type="checkbox" name="nscript_enable" id="nscript_enable" value="1" <!--#if int($nscript_enable) > 0 then 'checked="checked"' else ""#--> /></td>
<td><label for="nscript_enable"> $T('opt-nscript_enable')</label></td> <td><label for="nscript_enable"> $T('opt-nscript_enable')</label></td>
</tr> </tr>
</table> </table>
<em>$T('explain-nscript_enable')</em> <em>$T('explain-nscript_enable')</em>
</div><!-- /col2 --> $show_cat_box('nscript')
</div>
<div class="col1" <!--#if int($nscript_enable) > 0 then '' else 'style="display:none"'#-->> <div class="col1" <!--#if int($nscript_enable) > 0 then '' else 'style="display:none"'#-->>
<fieldset> <fieldset>
<div class="field-pair"> <div class="field-pair">
@ -360,8 +387,8 @@
<div class="alert"></div> <div class="alert"></div>
</div> </div>
</fieldset> </fieldset>
</div><!-- /col1 --> </div>
</div><!-- /section --> </div>
</form> </form>
</div><!-- /colmask --> </div><!-- /colmask -->
@ -374,11 +401,20 @@
\$('.col2 input[name$="enable"]').change(function() { \$('.col2 input[name$="enable"]').change(function() {
if(this.checked) { if(this.checked) {
\$(this).parents('.section').find('.col1').show() \$(this).parents('.section').find('.col1').show()
\$(this).parents('.col2').find('.col2-cats').show()
} else { } else {
\$(this).parents('.section').find('.col1').hide() \$(this).parents('.section').find('.col1').hide()
\$(this).parents('.col2').find('.col2-cats').hide()
} }
\$('form').submit() \$('form').submit()
}) })
\$('#email_endjob').change(function() {
if(\$(this).val() > 0) {
\$(this).parents('.section').find('.col2-cats').show()
} else {
\$(this).parents('.section').find('.col2-cats').hide()
}
})
/** /**
Testing functions Testing functions

3
interfaces/Config/templates/staticcfg/css/style.css

@ -137,7 +137,8 @@ input[type="checkbox"]+.desc {
font-style: italic; font-style: italic;
padding: 0 1px; padding: 0 1px;
} }
.col2 p { .col2 p,
.col2-cats {
font-size: 12px; font-size: 12px;
color: #666; color: #666;
margin: 1em 0; margin: 1em 0;

11
sabnzbd/cfg.py

@ -74,6 +74,7 @@ email_endjob = OptionNumber('misc', 'email_endjob', 0, 0, 2)
email_full = OptionBool('misc', 'email_full', False) email_full = OptionBool('misc', 'email_full', False)
email_dir = OptionDir('misc', 'email_dir', create=True) email_dir = OptionDir('misc', 'email_dir', create=True)
email_rss = OptionBool('misc', 'email_rss', False) email_rss = OptionBool('misc', 'email_rss', False)
email_cats = OptionList('misc', 'email_cats', ['*'])
version_check = OptionNumber('misc', 'check_new_rel', 1) version_check = OptionNumber('misc', 'check_new_rel', 1)
autobrowser = OptionBool('misc', 'auto_browser', True) autobrowser = OptionBool('misc', 'auto_browser', True)
@ -172,7 +173,7 @@ movie_categories = OptionList('misc', 'movie_categories', ['movies'])
enable_date_sorting = OptionBool('misc', 'enable_date_sorting', False) enable_date_sorting = OptionBool('misc', 'enable_date_sorting', False)
date_sort_string = OptionStr('misc', 'date_sort_string') date_sort_string = OptionStr('misc', 'date_sort_string')
date_categories = OptionStr('misc', 'date_categories', ['tv']) date_categories = OptionList('misc', 'date_categories', ['tv'])
configlock = OptionBool('misc', 'config_lock', 0) configlock = OptionBool('misc', 'config_lock', 0)
@ -245,6 +246,7 @@ fixed_ports = OptionBool('misc', 'fixed_ports', False)
# [ncenter] # [ncenter]
ncenter_enable = OptionBool('ncenter', 'ncenter_enable', sabnzbd.DARWIN) ncenter_enable = OptionBool('ncenter', 'ncenter_enable', sabnzbd.DARWIN)
ncenter_cats = OptionList('ncenter', 'ncenter_cats', ['*'])
ncenter_prio_startup = OptionBool('ncenter', 'ncenter_prio_startup', True) ncenter_prio_startup = OptionBool('ncenter', 'ncenter_prio_startup', True)
ncenter_prio_download = OptionBool('ncenter', 'ncenter_prio_download', False) ncenter_prio_download = OptionBool('ncenter', 'ncenter_prio_download', False)
ncenter_prio_pp = OptionBool('ncenter', 'ncenter_prio_pp', False) ncenter_prio_pp = OptionBool('ncenter', 'ncenter_prio_pp', False)
@ -259,6 +261,7 @@ ncenter_prio_other = OptionBool('ncenter', 'ncenter_prio_other', False)
# [acenter] # [acenter]
acenter_enable = OptionBool('acenter', 'acenter_enable', sabnzbd.WIN32) acenter_enable = OptionBool('acenter', 'acenter_enable', sabnzbd.WIN32)
acenter_cats = OptionList('acenter', 'acenter_cats', ['*'])
acenter_prio_startup = OptionBool('acenter', 'acenter_prio_startup', False) acenter_prio_startup = OptionBool('acenter', 'acenter_prio_startup', False)
acenter_prio_download = OptionBool('acenter', 'acenter_prio_download', False) acenter_prio_download = OptionBool('acenter', 'acenter_prio_download', False)
acenter_prio_pp = OptionBool('acenter', 'acenter_prio_pp', False) acenter_prio_pp = OptionBool('acenter', 'acenter_prio_pp', False)
@ -273,6 +276,7 @@ acenter_prio_other = OptionBool('acenter', 'acenter_prio_other', False)
# [ntfosd] # [ntfosd]
ntfosd_enable = OptionBool('ntfosd', 'ntfosd_enable', not sabnzbd.WIN32 and not sabnzbd.DARWIN) ntfosd_enable = OptionBool('ntfosd', 'ntfosd_enable', not sabnzbd.WIN32 and not sabnzbd.DARWIN)
ntfosd_cats = OptionList('ntfosd', 'ntfosd_cats', ['*'])
ntfosd_prio_startup = OptionBool('ntfosd', 'ntfosd_prio_startup', True) ntfosd_prio_startup = OptionBool('ntfosd', 'ntfosd_prio_startup', True)
ntfosd_prio_download = OptionBool('ntfosd', 'ntfosd_prio_download', False) ntfosd_prio_download = OptionBool('ntfosd', 'ntfosd_prio_download', False)
ntfosd_prio_pp = OptionBool('ntfosd', 'ntfosd_prio_pp', False) ntfosd_prio_pp = OptionBool('ntfosd', 'ntfosd_prio_pp', False)
@ -287,6 +291,7 @@ ntfosd_prio_other = OptionBool('ntfosd', 'ntfosd_prio_other', False)
# [growl] # [growl]
growl_enable = OptionBool('growl', 'growl_enable', False) growl_enable = OptionBool('growl', 'growl_enable', False)
growl_cats = OptionList('growl', 'growl_cats', ['*'])
growl_server = OptionStr('growl', 'growl_server') growl_server = OptionStr('growl', 'growl_server')
growl_password = OptionPassword('growl', 'growl_password') growl_password = OptionPassword('growl', 'growl_password')
growl_prio_startup = OptionBool('growl', 'growl_prio_startup', True) growl_prio_startup = OptionBool('growl', 'growl_prio_startup', True)
@ -303,6 +308,7 @@ growl_prio_other = OptionBool('growl', 'growl_prio_other', False)
# [prowl] # [prowl]
prowl_enable = OptionBool('prowl', 'prowl_enable', False) prowl_enable = OptionBool('prowl', 'prowl_enable', False)
prowl_cats = OptionList('prowl', 'prowl_cats', ['*'])
prowl_apikey = OptionStr('prowl', 'prowl_apikey') prowl_apikey = OptionStr('prowl', 'prowl_apikey')
prowl_prio_startup = OptionNumber('prowl', 'prowl_prio_startup', -3) prowl_prio_startup = OptionNumber('prowl', 'prowl_prio_startup', -3)
prowl_prio_download = OptionNumber('prowl', 'prowl_prio_download', -3) prowl_prio_download = OptionNumber('prowl', 'prowl_prio_download', -3)
@ -321,6 +327,7 @@ pushover_token = OptionStr('pushover', 'pushover_token')
pushover_userkey = OptionStr('pushover', 'pushover_userkey') pushover_userkey = OptionStr('pushover', 'pushover_userkey')
pushover_device = OptionStr('pushover', 'pushover_device') pushover_device = OptionStr('pushover', 'pushover_device')
pushover_enable = OptionBool('pushover', 'pushover_enable') pushover_enable = OptionBool('pushover', 'pushover_enable')
pushover_cats = OptionList('pushover', 'pushover_cats', ['*'])
pushover_prio_startup = OptionNumber('pushover', 'pushover_prio_startup', -3) pushover_prio_startup = OptionNumber('pushover', 'pushover_prio_startup', -3)
pushover_prio_download = OptionNumber('pushover', 'pushover_prio_download', -2) pushover_prio_download = OptionNumber('pushover', 'pushover_prio_download', -2)
pushover_prio_pp = OptionNumber('pushover', 'pushover_prio_pp', -3) pushover_prio_pp = OptionNumber('pushover', 'pushover_prio_pp', -3)
@ -335,6 +342,7 @@ pushover_prio_other = OptionNumber('pushover', 'pushover_prio_other', -3)
# [pushbullet] # [pushbullet]
pushbullet_enable = OptionBool('pushbullet', 'pushbullet_enable') pushbullet_enable = OptionBool('pushbullet', 'pushbullet_enable')
pushbullet_cats = OptionList('pushbullet', 'pushbullet_cats', ['*'])
pushbullet_apikey = OptionStr('pushbullet', 'pushbullet_apikey') pushbullet_apikey = OptionStr('pushbullet', 'pushbullet_apikey')
pushbullet_device = OptionStr('pushbullet', 'pushbullet_device') pushbullet_device = OptionStr('pushbullet', 'pushbullet_device')
pushbullet_prio_startup = OptionNumber('pushbullet', 'pushbullet_prio_startup', 0) pushbullet_prio_startup = OptionNumber('pushbullet', 'pushbullet_prio_startup', 0)
@ -351,6 +359,7 @@ pushbullet_prio_other = OptionNumber('pushbullet', 'pushbullet_prio_other', 0)
# [nscript] # [nscript]
nscript_enable = OptionBool('nscript', 'nscript_enable') nscript_enable = OptionBool('nscript', 'nscript_enable')
nscript_cats = OptionList('nscript', 'nscript_cats', ['*'])
nscript_script = OptionStr('nscript', 'nscript_script') nscript_script = OptionStr('nscript', 'nscript_script')
nscript_parameters = OptionStr('nscript', 'nscript_parameters') nscript_parameters = OptionStr('nscript', 'nscript_parameters')
nscript_prio_startup = OptionBool('nscript', 'nscript_prio_startup', True) nscript_prio_startup = OptionBool('nscript', 'nscript_prio_startup', True)

4
sabnzbd/emailer.py

@ -29,6 +29,7 @@ from sabnzbd.constants import *
import sabnzbd import sabnzbd
from sabnzbd.misc import to_units, split_host, time_format from sabnzbd.misc import to_units, split_host, time_format
from sabnzbd.encoding import EmailFilter from sabnzbd.encoding import EmailFilter
from sabnzbd.notifier import check_cat
import sabnzbd.cfg as cfg import sabnzbd.cfg as cfg
@ -216,6 +217,9 @@ def send_with_template(prefix, parm, test=None):
def endjob(filename, cat, status, path, bytes, fail_msg, stages, script, script_output, script_ret, test=None): def endjob(filename, cat, status, path, bytes, fail_msg, stages, script, script_output, script_ret, test=None):
""" Send end-of-job email """ """ Send end-of-job email """
# Is it allowed?
if not check_cat('email', cat):
return None
# Translate the stage names # Translate the stage names
tr = sabnzbd.api.Ttemplate tr = sabnzbd.api.Ttemplate

19
sabnzbd/interface.py

@ -2695,39 +2695,39 @@ def GetRssLog(feed):
############################################################################## ##############################################################################
LIST_EMAIL = ( LIST_EMAIL = (
'email_endjob', 'email_full', 'email_endjob', 'email_cats', 'email_full',
'email_server', 'email_to', 'email_from', 'email_server', 'email_to', 'email_from',
'email_account', 'email_pwd', 'email_dir', 'email_rss' 'email_account', 'email_pwd', 'email_dir', 'email_rss'
) )
LIST_GROWL = ('growl_enable', 'growl_server', 'growl_password', LIST_GROWL = ('growl_enable', 'growl_cats', 'growl_server', 'growl_password',
'growl_prio_startup', 'growl_prio_download', 'growl_prio_pp', 'growl_prio_complete', 'growl_prio_failed', 'growl_prio_startup', 'growl_prio_download', 'growl_prio_pp', 'growl_prio_complete', 'growl_prio_failed',
'growl_prio_disk_full', 'growl_prio_warning', 'growl_prio_error', 'growl_prio_queue_done', 'growl_prio_other', 'growl_prio_disk_full', 'growl_prio_warning', 'growl_prio_error', 'growl_prio_queue_done', 'growl_prio_other',
'growl_prio_new_login') 'growl_prio_new_login')
LIST_NCENTER = ('ncenter_enable', LIST_NCENTER = ('ncenter_enable', 'ncenter_cats',
'ncenter_prio_startup', 'ncenter_prio_download', 'ncenter_prio_pp', 'ncenter_prio_complete', 'ncenter_prio_failed', 'ncenter_prio_startup', 'ncenter_prio_download', 'ncenter_prio_pp', 'ncenter_prio_complete', 'ncenter_prio_failed',
'ncenter_prio_disk_full', 'ncenter_prio_warning', 'ncenter_prio_error', 'ncenter_prio_queue_done', 'ncenter_prio_other', 'ncenter_prio_disk_full', 'ncenter_prio_warning', 'ncenter_prio_error', 'ncenter_prio_queue_done', 'ncenter_prio_other',
'ncenter_prio_new_login') 'ncenter_prio_new_login')
LIST_ACENTER = ('acenter_enable', LIST_ACENTER = ('acenter_enable', 'acenter_cats',
'acenter_prio_startup', 'acenter_prio_download', 'acenter_prio_pp', 'acenter_prio_complete', 'acenter_prio_failed', 'acenter_prio_startup', 'acenter_prio_download', 'acenter_prio_pp', 'acenter_prio_complete', 'acenter_prio_failed',
'acenter_prio_disk_full', 'acenter_prio_warning', 'acenter_prio_error', 'acenter_prio_queue_done', 'acenter_prio_other', 'acenter_prio_disk_full', 'acenter_prio_warning', 'acenter_prio_error', 'acenter_prio_queue_done', 'acenter_prio_other',
'acenter_prio_new_login') 'acenter_prio_new_login')
LIST_NTFOSD = ('ntfosd_enable', LIST_NTFOSD = ('ntfosd_enable', 'ntfosd_cats',
'ntfosd_prio_startup', 'ntfosd_prio_download', 'ntfosd_prio_pp', 'ntfosd_prio_complete', 'ntfosd_prio_failed', 'ntfosd_prio_startup', 'ntfosd_prio_download', 'ntfosd_prio_pp', 'ntfosd_prio_complete', 'ntfosd_prio_failed',
'ntfosd_prio_disk_full', 'ntfosd_prio_warning', 'ntfosd_prio_error', 'ntfosd_prio_queue_done', 'ntfosd_prio_other', 'ntfosd_prio_disk_full', 'ntfosd_prio_warning', 'ntfosd_prio_error', 'ntfosd_prio_queue_done', 'ntfosd_prio_other',
'ntfosd_prio_new_login') 'ntfosd_prio_new_login')
LIST_PROWL = ('prowl_enable', 'prowl_apikey', LIST_PROWL = ('prowl_enable', 'prowl_cats', 'prowl_apikey',
'prowl_prio_startup', 'prowl_prio_download', 'prowl_prio_pp', 'prowl_prio_complete', 'prowl_prio_failed', 'prowl_prio_startup', 'prowl_prio_download', 'prowl_prio_pp', 'prowl_prio_complete', 'prowl_prio_failed',
'prowl_prio_disk_full', 'prowl_prio_warning', 'prowl_prio_error', 'prowl_prio_queue_done', 'prowl_prio_other', 'prowl_prio_disk_full', 'prowl_prio_warning', 'prowl_prio_error', 'prowl_prio_queue_done', 'prowl_prio_other',
'prowl_prio_new_login') 'prowl_prio_new_login')
LIST_PUSHOVER = ('pushover_enable', 'pushover_token', 'pushover_userkey', 'pushover_device', LIST_PUSHOVER = ('pushover_enable', 'pushover_cats', 'pushover_token', 'pushover_userkey', 'pushover_device',
'pushover_prio_startup', 'pushover_prio_download', 'pushover_prio_pp', 'pushover_prio_complete', 'pushover_prio_failed', 'pushover_prio_startup', 'pushover_prio_download', 'pushover_prio_pp', 'pushover_prio_complete', 'pushover_prio_failed',
'pushover_prio_disk_full', 'pushover_prio_warning', 'pushover_prio_error', 'pushover_prio_queue_done', 'pushover_prio_other', 'pushover_prio_disk_full', 'pushover_prio_warning', 'pushover_prio_error', 'pushover_prio_queue_done', 'pushover_prio_other',
'pushover_prio_new_login') 'pushover_prio_new_login')
LIST_PUSHBULLET = ('pushbullet_enable', 'pushbullet_apikey', 'pushbullet_device', LIST_PUSHBULLET = ('pushbullet_enable', 'pushbullet_cats', 'pushbullet_apikey', 'pushbullet_device',
'pushbullet_prio_startup', 'pushbullet_prio_download', 'pushbullet_prio_pp', 'pushbullet_prio_complete', 'pushbullet_prio_failed', 'pushbullet_prio_startup', 'pushbullet_prio_download', 'pushbullet_prio_pp', 'pushbullet_prio_complete', 'pushbullet_prio_failed',
'pushbullet_prio_disk_full', 'pushbullet_prio_warning', 'pushbullet_prio_error', 'pushbullet_prio_queue_done', 'pushbullet_prio_other', 'pushbullet_prio_disk_full', 'pushbullet_prio_warning', 'pushbullet_prio_error', 'pushbullet_prio_queue_done', 'pushbullet_prio_other',
'pushbullet_prio_new_login') 'pushbullet_prio_new_login')
LIST_NSCRIPT = ('nscript_enable', 'nscript_script', 'nscript_parameters', LIST_NSCRIPT = ('nscript_enable', 'nscript_cats', 'nscript_script', 'nscript_parameters',
'nscript_prio_startup', 'nscript_prio_download', 'nscript_prio_pp', 'nscript_prio_complete', 'nscript_prio_failed', 'nscript_prio_startup', 'nscript_prio_download', 'nscript_prio_pp', 'nscript_prio_complete', 'nscript_prio_failed',
'nscript_prio_disk_full', 'nscript_prio_warning', 'nscript_prio_error', 'nscript_prio_queue_done', 'nscript_prio_other', 'nscript_prio_disk_full', 'nscript_prio_warning', 'nscript_prio_error', 'nscript_prio_queue_done', 'nscript_prio_other',
'nscript_prio_new_login') 'nscript_prio_new_login')
@ -2749,6 +2749,7 @@ class ConfigNotify(object):
conf = build_header(sabnzbd.WEB_DIR_CONFIG) conf = build_header(sabnzbd.WEB_DIR_CONFIG)
conf['my_home'] = sabnzbd.DIR_HOME conf['my_home'] = sabnzbd.DIR_HOME
conf['categories'] = list_cats(False)
conf['lastmail'] = self.__lastmail conf['lastmail'] = self.__lastmail
conf['have_growl'] = True conf['have_growl'] = True
conf['have_ntfosd'] = sabnzbd.notifier.have_ntfosd() conf['have_ntfosd'] = sabnzbd.notifier.have_ntfosd()

35
sabnzbd/notifier.py

@ -120,7 +120,7 @@ def check_classes(gtype, section):
def get_prio(gtype, section): def get_prio(gtype, section):
""" Check if `gtype` is enabled in `section` """ """ Check prio of `gtype` in `section` """
try: try:
return sabnzbd.config.get_config(section, '%s_prio_%s' % (section, gtype))() return sabnzbd.config.get_config(section, '%s_prio_%s' % (section, gtype))()
except TypeError: except TypeError:
@ -128,20 +128,32 @@ def get_prio(gtype, section):
return -1000 return -1000
def send_notification(title, msg, gtype): def check_cat(section, job_cat):
""" Check if `job_cat` is enabled in `section`. * = All """
if not job_cat:
return True
try:
section_cats = sabnzbd.config.get_config(section, '%s_cats' % section)()
return ('*' in section_cats or job_cat in section_cats)
except TypeError:
logging.debug('Incorrect Notify option %s:%s_prio_%s', section, section, gtype)
return False
def send_notification(title, msg, gtype, job_cat=None):
""" Send Notification message """ """ Send Notification message """
# Notification Center # Notification Center
if sabnzbd.DARWIN and sabnzbd.cfg.ncenter_enable(): if sabnzbd.DARWIN and sabnzbd.cfg.ncenter_enable():
if check_classes(gtype, 'ncenter'): if check_classes(gtype, 'ncenter') and check_cat('ncenter', job_cat):
send_notification_center(title, msg, gtype) send_notification_center(title, msg, gtype)
# Windows # Windows
if sabnzbd.WIN32 and sabnzbd.cfg.acenter_enable(): if sabnzbd.WIN32 and sabnzbd.cfg.acenter_enable():
if check_classes(gtype, 'acenter'): if check_classes(gtype, 'acenter') and check_cat('acenter', job_cat):
send_windows(title, msg, gtype) send_windows(title, msg, gtype)
# Growl # Growl
if sabnzbd.cfg.growl_enable() and check_classes(gtype, 'growl'): if sabnzbd.cfg.growl_enable() and check_classes(gtype, 'growl') and check_cat('growl', job_cat):
if _HAVE_CLASSIC_GROWL and not sabnzbd.cfg.growl_server(): if _HAVE_CLASSIC_GROWL and not sabnzbd.cfg.growl_server():
return send_local_growl(title, msg, gtype) return send_local_growl(title, msg, gtype)
else: else:
@ -149,32 +161,33 @@ def send_notification(title, msg, gtype):
time.sleep(0.5) time.sleep(0.5)
# Prowl # Prowl
if sabnzbd.cfg.prowl_enable(): if sabnzbd.cfg.prowl_enable() and check_cat('prowl', job_cat):
if sabnzbd.cfg.prowl_apikey(): if sabnzbd.cfg.prowl_apikey():
Thread(target=send_prowl, args=(title, msg, gtype)).start() Thread(target=send_prowl, args=(title, msg, gtype)).start()
time.sleep(0.5) time.sleep(0.5)
# Pushover # Pushover
if sabnzbd.cfg.pushover_enable(): if sabnzbd.cfg.pushover_enable() and check_cat('pushover', job_cat):
if sabnzbd.cfg.pushover_token(): if sabnzbd.cfg.pushover_token():
Thread(target=send_pushover, args=(title, msg, gtype)).start() Thread(target=send_pushover, args=(title, msg, gtype)).start()
time.sleep(0.5) time.sleep(0.5)
# Pushbullet # Pushbullet
if sabnzbd.cfg.pushbullet_enable(): if sabnzbd.cfg.pushbullet_enable() and check_cat('pushbullet', job_cat):
if sabnzbd.cfg.pushbullet_apikey() and check_classes(gtype, 'pushbullet'): if sabnzbd.cfg.pushbullet_apikey() and check_classes(gtype, 'pushbullet'):
Thread(target=send_pushbullet, args=(title, msg, gtype)).start() Thread(target=send_pushbullet, args=(title, msg, gtype)).start()
time.sleep(0.5) time.sleep(0.5)
# Notification script. # Notification script.
if sabnzbd.cfg.nscript_enable(): if sabnzbd.cfg.nscript_enable() and check_cat('nscript', job_cat):
if sabnzbd.cfg.nscript_script(): if sabnzbd.cfg.nscript_script():
Thread(target=send_nscript, args=(title, msg, gtype)).start() Thread(target=send_nscript, args=(title, msg, gtype)).start()
time.sleep(0.5) time.sleep(0.5)
# NTFOSD # NTFOSD
if have_ntfosd() and sabnzbd.cfg.ntfosd_enable() and check_classes(gtype, 'ntfosd'): if have_ntfosd() and sabnzbd.cfg.ntfosd_enable():
send_notify_osd(title, msg) if check_classes(gtype, 'ntfosd') and check_cat('ntfosd', job_cat):
send_notify_osd(title, msg)
def reset_growl(): def reset_growl():

2
sabnzbd/nzbqueue.py

@ -398,7 +398,7 @@ class NzbQueue(object):
self.save(nzo) self.save(nzo)
if not (quiet or nzo.status in ('Fetching',)): if not (quiet or nzo.status in ('Fetching',)):
notifier.send_notification(T('NZB added to queue'), nzo.filename, 'download') notifier.send_notification(T('NZB added to queue'), nzo.filename, 'download', nzo.cat)
if not quiet and cfg.auto_sort(): if not quiet and cfg.auto_sort():
self.sort_by_avg_age() self.sort_by_avg_age()

8
sabnzbd/postproc.py

@ -500,7 +500,7 @@ def process_job(nzo):
logging.info("Traceback: ", exc_info=True) logging.info("Traceback: ", exc_info=True)
crash_msg = T('see logfile') crash_msg = T('see logfile')
nzo.fail_msg = T('PostProcessing was aborted (%s)') % unicoder(crash_msg) nzo.fail_msg = T('PostProcessing was aborted (%s)') % unicoder(crash_msg)
notifier.send_notification(T('Download Failed'), filename, 'failed') notifier.send_notification(T('Download Failed'), filename, 'failed', nzo.cat)
nzo.status = Status.FAILED nzo.status = Status.FAILED
par_error = True par_error = True
all_ok = False all_ok = False
@ -538,10 +538,10 @@ def process_job(nzo):
# Show final status in history # Show final status in history
if all_ok: if all_ok:
notifier.send_notification(T('Download Completed'), filename, 'complete') notifier.send_notification(T('Download Completed'), filename, 'complete', nzo.cat)
nzo.status = Status.COMPLETED nzo.status = Status.COMPLETED
else: else:
notifier.send_notification(T('Download Failed'), filename, 'failed') notifier.send_notification(T('Download Failed'), filename, 'failed', nzo.cat)
nzo.status = Status.FAILED nzo.status = Status.FAILED
# Log the overall time taken for postprocessing # Log the overall time taken for postprocessing
@ -623,7 +623,7 @@ def is_parfile(fn):
def parring(nzo, workdir): def parring(nzo, workdir):
""" Perform par processing. Returns: (par_error, re_add) """ """ Perform par processing. Returns: (par_error, re_add) """
filename = nzo.final_name filename = nzo.final_name
notifier.send_notification(T('Post-processing'), filename, 'pp') notifier.send_notification(T('Post-processing'), filename, 'pp', nzo.cat)
logging.info('Starting verification and repair of %s', filename) logging.info('Starting verification and repair of %s', filename)
# Get verification status of sets # Get verification status of sets

2
sabnzbd/urlgrabber.py

@ -361,7 +361,7 @@ def bad_fetch(nzo, url, msg='', content=False):
nzo.fail_msg = msg nzo.fail_msg = msg
notifier.send_notification(T('URL Fetching failed; %s') % '', '%s\n%s' % (msg, url), 'other') notifier.send_notification(T('URL Fetching failed; %s') % '', '%s\n%s' % (msg, url), 'other', nzo.cat)
if cfg.email_endjob() > 0: if cfg.email_endjob() > 0:
emailer.badfetch_mail(msg, url) emailer.badfetch_mail(msg, url)

Loading…
Cancel
Save