Skip to content

Commit

Permalink
Merge branch 'develop' into cfscrape-issue
Browse files Browse the repository at this point in the history
  • Loading branch information
miigotu committed May 8, 2019
2 parents f866f28 + 5fdbed9 commit a3380ce
Show file tree
Hide file tree
Showing 13 changed files with 106 additions and 17 deletions.
19 changes: 19 additions & 0 deletions gui/slick/views/config_notifications.mako
Original file line number Diff line number Diff line change
Expand Up @@ -2809,6 +2809,16 @@
</div>
</div>
<div class="field-pair row">
<div class="col-lg-3 col-md-4 col-sm-5 col-xs-12">
<label class="component-title">${_('Notify on postprocess')}</label>
</div>
<div class="col-lg-9 col-md-8 col-sm-7 col-xs-12 component-desc">
<input type="checkbox" name="email_notify_onpostprocess" id="email_notify_onpostprocess" ${('', 'checked="checked"')[bool(sickbeard.EMAIL_NOTIFY_ONPOSTPROCESS)]}/>
<label for="email_notify_onpostprocess">${_('send a notification when a postprocessing finishes?')}</label>
</div>
</div>
<div class="field-pair row">
<div class="col-lg-3 col-md-4 col-sm-5 col-xs-12">
<label class="component-title">${_('Notify on subtitle download')}</label>
Expand Down Expand Up @@ -3082,6 +3092,15 @@
</div>
</div>
<div class="field-pair row">
<div class="col-lg-3 col-md-4 col-sm-5 col-xs-12">
<label for="slack_icon_emoji" class="component-title">${_('Slack Icon Emoji')}</label>
</div>
<div class="col-lg-9 col-md-8 col-sm-7 col-xs-12 component-desc">
<input type="text" name="slack_icon_emoji" id="slack_icon_emoji" value="${sickbeard.SLACK_ICON_EMOJI}" class="form-control input-sm input350" autocapitalize="off" />
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="testNotification" id="testSlack-result">${_('Click below to test.')}</div>
Expand Down
13 changes: 10 additions & 3 deletions sickbeard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@
USE_LIBNOTIFY = False
LIBNOTIFY_NOTIFY_ONSNATCH = False
LIBNOTIFY_NOTIFY_ONDOWNLOAD = False
LIBNOTIFY_NOTIFY_ONPOSTPROCESS = False
LIBNOTIFY_NOTIFY_ONSUBTITLEDOWNLOAD = False

USE_NMJ = False
Expand Down Expand Up @@ -497,6 +498,7 @@
SLACK_NOTIFY_DOWNLOAD = None
SLACK_NOTIFY_SUBTITLEDOWNLOAD = None
SLACK_WEBHOOK = None
SLACK_ICON_EMOJI = None

USE_DISCORD = False
DISCORD_NOTIFY_SNATCH = None
Expand Down Expand Up @@ -557,6 +559,7 @@
USE_EMAIL = False
EMAIL_NOTIFY_ONSNATCH = False
EMAIL_NOTIFY_ONDOWNLOAD = False
EMAIL_NOTIFY_ONPOSTPROCESS = False
EMAIL_NOTIFY_ONSUBTITLEDOWNLOAD = False
EMAIL_HOST = None
EMAIL_PORT = 25
Expand Down Expand Up @@ -703,7 +706,7 @@ def initialize(consoleLogging=True): # pylint: disable=too-many-locals, too-man
USE_LIBNOTIFY, LIBNOTIFY_NOTIFY_ONSNATCH, LIBNOTIFY_NOTIFY_ONDOWNLOAD, LIBNOTIFY_NOTIFY_ONSUBTITLEDOWNLOAD, USE_NMJ, NMJ_HOST, NMJ_DATABASE, \
NMJ_MOUNT, USE_NMJv2, NMJv2_HOST, NMJv2_DATABASE, NMJv2_DBLOC, USE_SYNOINDEX, USE_SYNOLOGYNOTIFIER, SYNOLOGYNOTIFIER_NOTIFY_ONSNATCH, \
SYNOLOGYNOTIFIER_NOTIFY_ONDOWNLOAD, SYNOLOGYNOTIFIER_NOTIFY_ONSUBTITLEDOWNLOAD, USE_EMAIL, EMAIL_HOST, EMAIL_PORT, EMAIL_TLS, EMAIL_USER, \
EMAIL_PASSWORD, EMAIL_FROM, EMAIL_NOTIFY_ONSNATCH, EMAIL_NOTIFY_ONDOWNLOAD, EMAIL_NOTIFY_ONSUBTITLEDOWNLOAD, EMAIL_LIST, EMAIL_SUBJECT, \
EMAIL_PASSWORD, EMAIL_FROM, EMAIL_NOTIFY_ONSNATCH, EMAIL_NOTIFY_ONDOWNLOAD, EMAIL_NOTIFY_ONPOSTPROCESS, EMAIL_NOTIFY_ONSUBTITLEDOWNLOAD, EMAIL_LIST, EMAIL_SUBJECT, \
USE_LISTVIEW, METADATA_KODI, METADATA_KODI_12PLUS, METADATA_MEDIABROWSER, METADATA_PS3, metadata_provider_dict, NEWZBIN, NEWZBIN_USERNAME, \
NEWZBIN_PASSWORD, GIT_PATH, MOVE_ASSOCIATED_FILES, DELETE_NON_ASSOCIATED_FILES, SYNC_FILES, POSTPONE_IF_SYNC_FILES, dailySearchScheduler, \
NFO_RENAME, GUI_NAME, HOME_LAYOUT, HISTORY_LAYOUT, DISPLAY_SHOW_SPECIALS, COMING_EPS_LAYOUT, COMING_EPS_SORT, COMING_EPS_DISPLAY_PAUSED, \
Expand All @@ -719,7 +722,7 @@ def initialize(consoleLogging=True): # pylint: disable=too-many-locals, too-man
DOWNLOAD_URL, BACKLOG_DAYS, GIT_AUTH_TYPE, GIT_USERNAME, GIT_PASSWORD, GIT_TOKEN, DEVELOPER, DISPLAY_ALL_SEASONS, SSL_VERIFY, NEWS_LAST_READ, \
NEWS_LATEST, SOCKET_TIMEOUT, SYNOLOGY_DSM_HOST, SYNOLOGY_DSM_USERNAME, SYNOLOGY_DSM_PASSWORD, SYNOLOGY_DSM_PATH, GUI_LANG, SICKCHILL_BACKGROUND, \
SICKCHILL_BACKGROUND_PATH, FANART_BACKGROUND, FANART_BACKGROUND_OPACITY, CUSTOM_CSS, CUSTOM_CSS_PATH, USE_SLACK, SLACK_NOTIFY_SNATCH, \
SLACK_NOTIFY_DOWNLOAD, SLACK_NOTIFY_SUBTITLEDOWNLOAD, SLACK_WEBHOOK, USE_DISCORD, DISCORD_NOTIFY_SNATCH, DISCORD_NOTIFY_DOWNLOAD, DISCORD_WEBHOOK
SLACK_NOTIFY_DOWNLOAD, SLACK_NOTIFY_SUBTITLEDOWNLOAD, SLACK_WEBHOOK, SLACK_ICON_EMOJI, USE_DISCORD, DISCORD_NOTIFY_SNATCH, DISCORD_NOTIFY_DOWNLOAD, DISCORD_WEBHOOK

if __INITIALIZED__:
return False
Expand Down Expand Up @@ -1236,6 +1239,7 @@ def path_leaf(path):
SLACK_NOTIFY_DOWNLOAD = check_setting_bool(CFG, 'Slack', 'slack_notify_download')
SLACK_NOTIFY_SUBTITLEDOWNLOAD = check_setting_bool(CFG, 'Slack', 'slack_notify_subtitledownload')
SLACK_WEBHOOK = check_setting_str(CFG, 'Slack', 'slack_webhook')
SLACK_ICON_EMOJI = check_setting_str(CFG, 'Slack', 'slack_icon_emoji')

USE_DISCORD = check_setting_bool(CFG, 'Discord', 'use_discord')
DISCORD_NOTIFY_SNATCH = check_setting_bool(CFG, 'Discord', 'discord_notify_snatch')
Expand Down Expand Up @@ -1294,6 +1298,7 @@ def path_leaf(path):
USE_EMAIL = check_setting_bool(CFG, 'Email', 'use_email')
EMAIL_NOTIFY_ONSNATCH = check_setting_bool(CFG, 'Email', 'email_notify_onsnatch')
EMAIL_NOTIFY_ONDOWNLOAD = check_setting_bool(CFG, 'Email', 'email_notify_ondownload')
EMAIL_NOTIFY_ONPOSTPROCESS = check_setting_bool(CFG, 'Email', 'email_notify_onpostprocess')
EMAIL_NOTIFY_ONSUBTITLEDOWNLOAD = check_setting_bool(CFG, 'Email', 'email_notify_onsubtitledownload')
EMAIL_HOST = check_setting_str(CFG, 'Email', 'email_host')
EMAIL_PORT = check_setting_int(CFG, 'Email', 'email_port', 25, min_val=21, max_val=65535)
Expand Down Expand Up @@ -2146,7 +2151,8 @@ def save_config(): # pylint: disable=too-many-statements, too-many-branches
'slack_notify_snatch': int(SLACK_NOTIFY_SNATCH),
'slack_notify_download': int(SLACK_NOTIFY_DOWNLOAD),
'slack_notify_subtitledownload': int(SLACK_NOTIFY_SUBTITLEDOWNLOAD),
'slack_webhook': SLACK_WEBHOOK
'slack_webhook': SLACK_WEBHOOK,
'slack_icon_emoji': SLACK_ICON_EMOJI
},

'Discord': {
Expand Down Expand Up @@ -2217,6 +2223,7 @@ def save_config(): # pylint: disable=too-many-statements, too-many-branches
'use_email': int(USE_EMAIL),
'email_notify_onsnatch': int(EMAIL_NOTIFY_ONSNATCH),
'email_notify_ondownload': int(EMAIL_NOTIFY_ONDOWNLOAD),
'email_notify_onpostprocess': int(EMAIL_NOTIFY_ONPOSTPROCESS),
'email_notify_onsubtitledownload': int(EMAIL_NOTIFY_ONSUBTITLEDOWNLOAD),
'email_host': EMAIL_HOST,
'email_port': int(EMAIL_PORT),
Expand Down
4 changes: 3 additions & 1 deletion sickbeard/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
NOTIFY_GIT_UPDATE_TEXT = 5
NOTIFY_LOGIN = 6
NOTIFY_LOGIN_TEXT = 7
NOTIFY_POSTPROCESS = 8

notifyStrings = NumDict({
# pylint: disable=undefined-variable
Expand All @@ -82,7 +83,8 @@
NOTIFY_GIT_UPDATE: _("SickChill Updated"),
NOTIFY_GIT_UPDATE_TEXT: _("SickChill Updated To Commit#: "),
NOTIFY_LOGIN: _("SickChill new login"),
NOTIFY_LOGIN_TEXT: _("New login from IP: {0}. http://geomaplookup.net/?ip={0}")
NOTIFY_LOGIN_TEXT: _("New login from IP: {0}. http://geomaplookup.net/?ip={0}"),
NOTIFY_POSTPROCESS: _("Finished Post Processing")
})

# Episode statuses
Expand Down
2 changes: 1 addition & 1 deletion sickbeard/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def change_unrar_tool(unrar_tool, alt_unrar_tool):
sickbeard.ALT_UNRAR_TOOL = rarfile.ALT_TOOL = alt_unrar_tool

try:
rarfile.custom_check([rarfile.UNRAR_TOOL])
rarfile.custom_check([rarfile.UNRAR_TOOL], True)
return True
except (rarfile.RarCannotExec, rarfile.RarExecError, OSError, IOError):
if sickbeard.UNPACK == 1:
Expand Down
5 changes: 5 additions & 0 deletions sickbeard/notifiers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ def notify_download(ep_name):
n.notify_download(ep_name)


def notify_postprocess(ep_name):
for n in notifiers:
n.notify_postprocess(ep_name)


def notify_subtitle_download(ep_name, lang):
for n in notifiers:
n.notify_subtitle_download(ep_name, lang)
Expand Down
45 changes: 45 additions & 0 deletions sickbeard/notifiers/emailnotify.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,51 @@ def notify_download(self, ep_name, title='Completed:'): # pylint: disable=unuse
else:
logger.log('Download notification error: {0}'.format(self.last_err), logger.WARNING)

def notify_postprocess(self, ep_name, title='Postprocessed:'): # pylint: disable=unused-argument
'''
Send a notification that an episode was postprocessed
ep_name: The name of the episode that was postprocessed
title: The title of the notification (optional)
'''
ep_name = ss(ep_name)

if sickbeard.USE_EMAIL and sickbeard.EMAIL_NOTIFY_ONPOSTPROCESS:
show = self._parseEp(ep_name)
to = self._generate_recipients(show)
if not to:
logger.log('Skipping email notify because there are no configured recipients', logger.DEBUG)
else:
try:
msg = MIMEMultipart('alternative')
msg.attach(MIMEText(
'<body style="font-family:Helvetica, Arial, sans-serif;">'
'<h3>SickChill Notification - Postprocessed</h3>'
'<p>Show: <b>{0}</b></p><p>Episode Number: <b>{1}</b></p><p>Episode: <b>{2}</b></p><p>Quality: <b>{3}</b></p>'
'<h5 style="margin-top: 2.5em; padding: .7em 0; '
'color: #777; border-top: #BBB solid 1px;">'
'Powered by SickChill.</h5></body>'.format(show[0], show[1], show[2], show[3]),
'html'))

except Exception:
try:
msg = MIMEText(ep_name)
except Exception:
msg = MIMEText('Episode Postprocessed')

if sickbeard.EMAIL_SUBJECT:
msg[b'Subject'] = '[PP] ' + sickbeard.EMAIL_SUBJECT
else:
msg[b'Subject'] = 'Postprocessed: ' + ep_name
msg[b'From'] = sickbeard.EMAIL_FROM
msg[b'To'] = ','.join(to)
msg[b'Date'] = formatdate(localtime=True)
if self._sendmail(sickbeard.EMAIL_HOST, sickbeard.EMAIL_PORT, sickbeard.EMAIL_FROM, sickbeard.EMAIL_TLS,
sickbeard.EMAIL_USER, sickbeard.EMAIL_PASSWORD, to, msg):
logger.log('Postprocess notification sent to [{0}] for "{1}"'.format(to, ep_name), logger.DEBUG)
else:
logger.log('Postprocess notification error: {0}'.format(self.last_err), logger.WARNING)

def notify_subtitle_download(self, ep_name, lang, title='Downloaded subtitle:'): # pylint: disable=unused-argument
'''
Send a notification that an subtitle was downloaded
Expand Down
4 changes: 3 additions & 1 deletion sickbeard/notifiers/slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
class Notifier(object):

SLACK_WEBHOOK_URL = 'https://hooks.slack.com/services/'
SLACK_ICON_URL = 'https://github.com/SickChill/SickChill/raw/master/gui/slick/images/sickchill-sc.png'

def notify_snatch(self, ep_name):
if sickbeard.SLACK_NOTIFY_SNATCH:
Expand Down Expand Up @@ -61,6 +62,7 @@ def test_notify(self):

def _send_slack(self, message=None):
slack_webhook = self.SLACK_WEBHOOK_URL + sickbeard.SLACK_WEBHOOK.replace(self.SLACK_WEBHOOK_URL, '')
slack_icon_emoji = sickbeard.SLACK_ICON_EMOJI

logger.log("Sending slack message: " + message, logger.INFO)
logger.log("Sending slack message to url: " + slack_webhook, logger.INFO)
Expand All @@ -70,7 +72,7 @@ def _send_slack(self, message=None):

headers = {b"Content-Type": b"application/json"}
try:
r = requests.post(slack_webhook, data=json.dumps(dict(text=message, username="SickChillBot")), headers=headers)
r = requests.post(slack_webhook, data=json.dumps(dict(text=message, username="SickChillBot", icon_emoji=slack_icon_emoji, icon_url=self.SLACK_ICON_URL)), headers=headers)
r.raise_for_status()
except Exception as e:
logger.log("Error Sending Slack message: " + ex(e), logger.ERROR)
Expand Down
7 changes: 7 additions & 0 deletions sickbeard/postProcessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1243,4 +1243,11 @@ def process(self): # pylint: disable=too-many-return-statements, too-many-local

self._run_extra_scripts(ep_obj)

# If any notification fails, don't stop postProcessor
try:
# send notifications
notifiers.email_notifier.notify_postprocess(ep_obj._format_pattern('%SN - %Sx%0E - %EN - %QN')) # pylint: disable=protected-access
except Exception:
logger.log("Some notifications could not be sent. Finishing postProcessing...")

return True
2 changes: 1 addition & 1 deletion sickbeard/providers/newznab.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def _get_default_providers():
'NZBFinder.ws|https://nzbfinder.ws/||5030,5040,5010,5045|0|eponly|1|1|1!!!' + \
'NZBGeek|https://api.nzbgeek.info/||5030,5040|0|eponly|0|0|0!!!' + \
'NZBs.org|https://nzbs.org/||5030,5040|0|eponly|0|0|0!!!' + \
'Usenet-Crawler|https://api.usenet-crawler.com/||5030,5040|0|eponly|0|0|0!!!' + \
'Usenet-Crawler|https://www.usenet-crawler.com/||5030,5040|0|eponly|0|0|0!!!' + \
'DOGnzb|https://api.dognzb.cr/||5030,5040,5060,5070|0|eponly|0|1|1'

def _check_auth(self):
Expand Down
10 changes: 5 additions & 5 deletions sickbeard/providers/thepiratebay.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ def search(self, search_strings, age=0, ep_obj=None): # pylint: disable=too-man
205 = SD, 208 = HD, 200 = All Videos
https://pirateproxy.pl/s/?q=Game of Thrones&type=search&orderby=7&page=0&category=200
"""
# oder_by is 7 in browse for seeders, but 8 in search!

search_params = {
"q": "",
"type": "search",
"orderby": 8,
"page": 0,
"category": 200
"orderby": 7, # order by seeders: most first
"page": 0, # first page of results
"category": 200 # All videos
}

# Units
Expand Down Expand Up @@ -190,4 +190,4 @@ def process_column_header(th):
return results


provider = ThePirateBayProvider()
provider = ThePirateBayProvider()
4 changes: 2 additions & 2 deletions sickbeard/providers/torrent9.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ def __init__(self):
self.public = True
self.minseed = None
self.minleech = None
# self._original_url = "https://www.torrent9.uno"
self._original_url = "https://www.torrents9.pw"
self._original_url = "https://www.torrent9.uno"
# self._original_url = "https://www.torrents9.pw"
self._custom_url = None
self._used_url = None
self._recheck_url = True
Expand Down
6 changes: 4 additions & 2 deletions sickbeard/webserve.py
Original file line number Diff line number Diff line change
Expand Up @@ -4896,10 +4896,10 @@ def saveNotifications( # pylint: disable=unused-argument
use_pushbullet=None, pushbullet_notify_onsnatch=None, pushbullet_notify_ondownload=None,
pushbullet_notify_onsubtitledownload=None, pushbullet_api=None, pushbullet_device=None,
pushbullet_device_list=None, pushbullet_channel_list=None, pushbullet_channel=None,
use_email=None, email_notify_onsnatch=None, email_notify_ondownload=None,
use_email=None, email_notify_onsnatch=None, email_notify_ondownload=None, email_notify_onpostprocess=None,
email_notify_onsubtitledownload=None, email_host=None, email_port=25, email_from=None,
email_tls=None, email_user=None, email_password=None, email_list=None, email_subject=None, email_show_list=None,
email_show=None, use_slack=False, slack_notify_snatch=None, slack_notify_download=None, slack_notify_subtitledownload=None, slack_webhook=None,
email_show=None, use_slack=False, slack_notify_snatch=None, slack_notify_download=None, slack_notify_subtitledownload=None, slack_webhook=None, slack_icon_emoji=None,
use_discord=False, discord_notify_snatch=None, discord_notify_download=None, discord_webhook=None, discord_name=None,
discord_avatar_url=None, discord_tts=False):

Expand Down Expand Up @@ -4994,6 +4994,7 @@ def saveNotifications( # pylint: disable=unused-argument
sickbeard.SLACK_NOTIFY_DOWNLOAD = config.checkbox_to_value(slack_notify_download)
sickbeard.SLACK_NOTIFY_SUBTITLEDOWNLOAD = config.checkbox_to_value(slack_notify_subtitledownload)
sickbeard.SLACK_WEBHOOK = slack_webhook
sickbeard.SLACK_ICON_EMOJI = slack_icon_emoji

sickbeard.USE_DISCORD = config.checkbox_to_value(use_discord)
sickbeard.DISCORD_NOTIFY_SNATCH = config.checkbox_to_value(discord_notify_snatch)
Expand Down Expand Up @@ -5060,6 +5061,7 @@ def saveNotifications( # pylint: disable=unused-argument
sickbeard.USE_EMAIL = config.checkbox_to_value(use_email)
sickbeard.EMAIL_NOTIFY_ONSNATCH = config.checkbox_to_value(email_notify_onsnatch)
sickbeard.EMAIL_NOTIFY_ONDOWNLOAD = config.checkbox_to_value(email_notify_ondownload)
sickbeard.EMAIL_NOTIFY_ONPOSTPROCESS = config.checkbox_to_value(email_notify_onpostprocess)
sickbeard.EMAIL_NOTIFY_ONSUBTITLEDOWNLOAD = config.checkbox_to_value(email_notify_onsubtitledownload)
sickbeard.EMAIL_HOST = config.clean_host(email_host)
sickbeard.EMAIL_PORT = try_int(email_port, 25)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def create_test_cache_folder():
sickbeard.TV_DOWNLOAD_DIR = PROCESSING_DIR

sickbeard.PROVIDER_ORDER = ["sick_beard_index"]
sickbeard.newznabProviderList = NewznabProvider.providers_list("'Sick Beard Index|http://lolo.sickbeard.com/|0|5030,5040|0|eponly|0|0|0!!!NZBs.org|https://nzbs.org/||5030,5040,5060,5070,5090|0|eponly|0|0|0!!!Usenet-Crawler|https://api.usenet-crawler.com/||5030,5040,5060|0|eponly|0|0|0'")
sickbeard.newznabProviderList = NewznabProvider.providers_list("'Sick Beard Index|http://lolo.sickbeard.com/|0|5030,5040|0|eponly|0|0|0!!!NZBs.org|https://nzbs.org/||5030,5040,5060,5070,5090|0|eponly|0|0|0!!!Usenet-Crawler|https://www.usenet-crawler.com/||5030,5040,5060|0|eponly|0|0|0'")
sickbeard.providerList = providers.makeProviderList()

sickbeard.PROG_DIR = os.path.abspath(os.path.join(TEST_DIR, '..'))
Expand Down

0 comments on commit a3380ce

Please sign in to comment.