Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Matrix support * UI Fix: Matrix logo CSS was wrong * Wierd debugging * Bugs squashed * Bugs squashed * Fixed whitespace issue * Fix isort
- Loading branch information
Showing
10 changed files
with
317 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
# coding=utf-8 | ||
|
||
# Author: Joao Santos <jmigueltsantos@riseup.net> | ||
# | ||
# This file is part of SickChill. | ||
# | ||
# SickChill is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# SickChill is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with SickChill. If not, see <http://www.gnu.org/licenses/>. | ||
from __future__ import unicode_literals | ||
|
||
import json | ||
import time | ||
|
||
import requests | ||
import six | ||
|
||
import sickbeard | ||
from sickbeard import common, logger | ||
from sickchill.helper.encoding import ss | ||
from sickchill.helper.exceptions import ex | ||
|
||
|
||
class Notifier(object): | ||
|
||
def notify_snatch(self, ep_name): | ||
if sickbeard.MATRIX_NOTIFY_SNATCH: | ||
show = self._parseEp(ep_name) | ||
message = '''<body> | ||
<h3>SickChill Notification - Snatched</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>Powered by SickChill.</h5></body>'''.format(show[0], show[1], show[2], show[3]) | ||
self._notify_matrix(message) | ||
|
||
def notify_download(self, ep_name): | ||
if sickbeard.MATRIX_NOTIFY_DOWNLOAD: | ||
show = self._parseEp(ep_name) | ||
message = '''<body> | ||
<h3>SickChill Notification - Downloaded</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]) | ||
self._notify_matrix(message) | ||
|
||
def notify_subtitle_download(self, ep_name, lang): | ||
if sickbeard.MATRIX_NOTIFY_SUBTITLEDOWNLOAD: | ||
show = self._parseEp(ep_name) | ||
message = '''<body> | ||
<h3>SickChill Notification - Subtitle Downloaded</h3> | ||
<p>Show: <b>{0}</b></p><p>Episode Number: <b>{1}</b></p><p>Episode: <b>{2}</b></p></p> | ||
<p>Language: <b>{3}</b></p> | ||
<h5>Powered by SickChill.</h5></body>'''.format(show[0], show[1], show[2], lang) | ||
self._notify_matrix(message) | ||
|
||
def notify_git_update(self, new_version="??"): | ||
if sickbeard.USE_MATRIX: | ||
update_text = common.notifyStrings[common.NOTIFY_GIT_UPDATE_TEXT] | ||
title = common.notifyStrings[common.NOTIFY_GIT_UPDATE] | ||
self._notify_matrix(title + " - " + update_text + new_version) | ||
|
||
def notify_login(self, ipaddress=""): | ||
if sickbeard.USE_MATRIX: | ||
update_text = common.notifyStrings[common.NOTIFY_LOGIN_TEXT] | ||
title = common.notifyStrings[common.NOTIFY_LOGIN] | ||
self._notify_matrix(title + " - " + update_text.format(ipaddress)) | ||
|
||
def test_notify(self): | ||
return self._notify_matrix("This is a test notification from SickChill", force=True) | ||
|
||
def _send_matrix(self, message=None): | ||
url = 'https://{0}/_matrix/client/r0/rooms/{1}/send/m.room.message/{2}?access_token={3}'.format(sickbeard.MATRIX_SERVER, sickbeard.MATRIX_ROOM, time.time(), sickbeard.MATRIX_API_TOKEN) | ||
|
||
logger.log("Sending matrix message: " + message, logger.INFO) | ||
logger.log("Sending matrix message to url: " + url, logger.INFO) | ||
|
||
if isinstance(message, six.text_type): | ||
message = message.encode('utf-8') | ||
|
||
jsonMessage={ | ||
"msgtype": "m.text", | ||
"format": "org.matrix.custom.html", | ||
"body": message, | ||
"formatted_body": message, | ||
} | ||
|
||
headers = {b"Content-Type": b"application/json"} | ||
try: | ||
r = requests.put(url , data=json.dumps(jsonMessage), headers=headers) | ||
r.raise_for_status() | ||
|
||
except Exception as e: | ||
logger.log("Error Sending Matrix message: " + ex(e), logger.ERROR) | ||
return False | ||
|
||
return True | ||
|
||
def _notify_matrix(self, message='', force=False): | ||
if not sickbeard.USE_MATRIX and not force: | ||
return False | ||
|
||
return self._send_matrix(message) | ||
|
||
@staticmethod | ||
def _parseEp(ep_name): | ||
ep_name = ss(ep_name) | ||
|
||
sep = ' - ' | ||
titles = ep_name.split(sep) | ||
logger.log('TITLES: {0}'.format(titles), logger.DEBUG) | ||
return titles |
Oops, something went wrong.