Skip to content

Commit

Permalink
Generic Provide + Notifications (#8691)
Browse files Browse the repository at this point in the history
* episode_object removal

* poe clean

* nonfunctional discord tts removal

* subtitles.com not org

* Keys

* Revert "nonfunctional discord tts removal"

This reverts commit 330bb97.

* Discord TTS big change

* Poe with black 24.1.1

* chore: cleanup discord webhook test JavaScript

* TTS typo and 1:0

* TTS typo and 1:0

* TTS yarn

---------

Co-authored-by: miigotu <[email protected]>
  • Loading branch information
BKSteve and miigotu authored Feb 1, 2024
1 parent a8f829c commit 42670d9
Show file tree
Hide file tree
Showing 22 changed files with 48 additions and 49 deletions.
1 change: 0 additions & 1 deletion SickChill.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@


class SickChill:

"""
Main SickChill module
"""
Expand Down
21 changes: 8 additions & 13 deletions sickchill/gui/slick/js/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -705,27 +705,22 @@ const SICKCHILL = {
});

$('#testDiscord').on('click', () => {
const discord = {};
const discordWebhook = $('#discord_webhook');
discord.webhook = discordWebhook.val();
if (!discord.webhook) {
if (!discordWebhook.val()) {
discordWebhook.focus();
notifyModal('Please fill in the webhook address');
return;
}

discord.name = $('#discord_name').val();
discord.avatar = $('#discord_avatar_url').val();
discord.tts = $('#discord_tts').val();

const discord = {
webhook: discordWebhook.val(),
name: $('#discord_name').val(),
avatar: $('#discord_avatar_url').val(),
tts: $('#discord_tts').is(':checked') ? 1 : 0,
};
$('#testDiscord').prop('disabled', true);
$('#testDiscord-result').html(loading);
$.get(scRoot + '/home/testDiscord', {
webhook: discord.webhook,
name: discord.name,
avatar: discord.avatar,
tts: discord.tts,
}).done(data => {
$.post(scRoot + '/home/testDiscord', discord).done(data => {
$('#testDiscord-result').html(data);
$('#testDiscord').prop('disabled', false);
});
Expand Down
6 changes: 3 additions & 3 deletions sickchill/gui/slick/views/config_notifications.mako
Original file line number Diff line number Diff line change
Expand Up @@ -3742,7 +3742,7 @@
<input type="text" name="discord_name" id="discord_name" value="${settings.DISCORD_NAME}" class="form-control input-sm input350" autocapitalize="off" />
</div>
<div class="col-md-12">
<label for="discord_name">${_('Must use Bot Name. Blank no longer valid and will fail. Click Save before Test.')}</label>
<label for="discord_name">${_('Blank and Save will default to SickChill.')}</label>
</div>
</div>
</div>
Expand All @@ -3766,11 +3766,11 @@
<div class="field-pair row">
<div class="col-lg-3 col-md-4 col-sm-5 col-xs-12">
<label class="component-title">${_('Discord TTS')}</label>
<label class="component-title">${_('TTS')}</label>
</div>
<div class="col-lg-9 col-md-8 col-sm-7 col-xs-12 component-desc">
<input type="checkbox" name="discord_tts" id="discord_tts" ${checked(settings.DISCORD_TTS)}/>
<label for="discord_tts">${_('Send notifications using text-to-speech')}</label>
<label for="discord_tts">${_('Send full notification message using text-to-speech else Bot Name only')}</label>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion sickchill/oldbeard/clients/qbittorrent.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def __torrent_args(result: "TorrentSearchResult") -> dict:
download_path=settings.TORRENT_PATH_INCOMPLETE or None,
category=(settings.TORRENT_LABEL, settings.TORRENT_LABEL_ANIME)[result.show.is_anime] or settings.TORRENT_LABEL,
is_paused=settings.TORRENT_PAUSED,
ratio_limit = (None, ratio_limit_float)[ratio_limit_float > 0],
ratio_limit=(None, ratio_limit_float)[ratio_limit_float > 0],
seeding_time_limit=(None, 60 * int(settings.TORRENT_SEED_TIME))[int(settings.TORRENT_SEED_TIME) > 0],
tags=("sickchill", "sickchill-anime")[result.show.is_anime],
)
Expand Down
25 changes: 14 additions & 11 deletions sickchill/oldbeard/notifications_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,24 +134,29 @@ def _send_discord(self, webhook: str = None, name: str = None, avatar: str = Non
discord_webhook = webhook or settings.DISCORD_WEBHOOK
discord_name = name or settings.DISCORD_NAME
avatar_icon = avatar or settings.DISCORD_AVATAR_URL
discord_tts = bool(settings.DISCORD_TTS if tts is None else tts)
discord_tts = int(settings.DISCORD_TTS if tts is None else tts)

if not settings.USE_DISCORD:
logger.debug("Notification for Discord not enabled, skipping this notification")
return False

if not discord_name:
logger.warning("Discord Bot Name is Blank. Please enter Webhook dedicated Bot Name.")
return False
logger.debug("Discord Bot name blank, forcing to SickChill")
discord_name = "SickChill"
settings.DISCORD_NAME = discord_name

if discord_tts == 1:
discord_content = "" + ", ".join(f["value"] for f in self.embed["fields"])
else:
discord_content = ""

logger.info("Sending discord message: " + ", ".join(f["value"] for f in self.embed["fields"]))
logger.info("Sending discord message to url: " + discord_webhook)
logger.info(f"Sending discord message: {discord_content}")
logger.info(f"Sending discord message to url: {discord_webhook}")

headers = CaseInsensitiveDict({"Content-Type": "application/json"})
message_data = json.dumps(dict(embeds=[self.embed], username=discord_name, avatar_url=avatar_icon, content=discord_content))
try:
r = requests.post(
discord_webhook, data=json.dumps(dict(embeds=[self.embed], username=discord_name, avatar_url=avatar_icon, tts=discord_tts)), headers=headers
)
r = requests.post(discord_webhook, data=message_data, headers=headers)
r.raise_for_status()
except requests.exceptions.ConnectionError as error:
logger.info("Could not reach the webhook url")
Expand All @@ -163,9 +168,7 @@ def _send_discord(self, webhook: str = None, name: str = None, avatar: str = Non

logger.info("Discord rate limiting, retrying after {} seconds".format(error.response.headers.get("X-RateLimit-Reset-After")))
time.sleep(int(error.response.headers.get("X-RateLimit-Reset-After")) + 1)
r = requests.post(
discord_webhook, data=json.dumps(dict(embeds=[self.embed], username=discord_name, avatar_url=avatar_icon, tts=discord_tts)), headers=headers
)
r = requests.post(discord_webhook, data=message_data, headers=headers)
r.raise_for_status()
except Exception as error:
logger.exception(f"Error Sending Discord message: {error}")
Expand Down
2 changes: 1 addition & 1 deletion sickchill/oldbeard/subtitles.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"itasa": "http://www.italiansubs.net/",
"legendastv": "http://www.legendas.tv",
"napiprojekt": "http://www.napiprojekt.pl",
"opensubtitles": "http://www.opensubtitles.org",
"opensubtitles": "https://www.opensubtitles.com",
"podnapisi": "http://www.podnapisi.net",
"subscenter": "http://www.subscenter.info",
"subtitulamos": "https://www.subtitulamos.tv",
Expand Down
2 changes: 1 addition & 1 deletion sickchill/providers/GenericProvider.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def find_search_results(self, show, episodes, search_mode, manual_search=False,
search_strings = self.get_episode_search_strings(episode)

for search_string in search_strings:
items_list += self.search(search_string, episode_object=episode)
items_list += self.search(search_string)

if len(results) == len(episodes):
return results
Expand Down
1 change: 1 addition & 0 deletions sickchill/providers/subtitle/bsplayer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Created by Nyaran, based on https://github.com/realgam3/service.subtitles.bsplayer
"""

import logging
import os
import random
Expand Down
2 changes: 1 addition & 1 deletion sickchill/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
DISCORD_NOTIFY_DOWNLOAD = None
DISCORD_NOTIFY_SNATCH = None
DISCORD_NOTIFY_SUBTITLEDOWNLOAD = None
DISCORD_TTS = False
DISCORD_TTS = None
DISCORD_WEBHOOK = None
DISPLAY_ALL_SEASONS = True
DISPLAY_SHOW_SPECIALS = False
Expand Down
2 changes: 0 additions & 2 deletions sickchill/show/ComingEpisodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,6 @@ def get_coming_episodes(categories, sort, group, paused=settings.COMING_EPS_DISP
result["localtime"] = result["localtime"].toordinal()

grouped_results[category].append(result)
else:
return []

return grouped_results

Expand Down
1 change: 1 addition & 0 deletions sickchill/show/recommendations/recommended.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Recommend shows based on lists from indexers
"""

import os
import posixpath

Expand Down
4 changes: 2 additions & 2 deletions sickchill/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ def path_leaf(path):
settings.DISCORD_WEBHOOK = check_setting_str(settings.CFG, "Discord", "discord_webhook")
settings.DISCORD_NAME = check_setting_str(settings.CFG, "Discord", "discord_name")
settings.DISCORD_AVATAR_URL = check_setting_str(settings.CFG, "Discord", "discord_avatar_url")
settings.DISCORD_TTS = check_setting_str(settings.CFG, "Discord", "discord_tts")
settings.DISCORD_TTS = check_setting_bool(settings.CFG, "Discord", "discord_tts")

settings.USE_TRAKT = check_setting_bool(settings.CFG, "Trakt", "use_trakt")
settings.TRAKT_USERNAME = check_setting_str(settings.CFG, "Trakt", "trakt_username", censor_log=True)
Expand Down Expand Up @@ -1535,7 +1535,7 @@ def save_config():
"discord_webhook": settings.DISCORD_WEBHOOK,
"discord_name": settings.DISCORD_NAME,
"discord_avatar_url": settings.DISCORD_AVATAR_URL,
"discord_tts": settings.DISCORD_TTS,
"discord_tts": int(settings.DISCORD_TTS),
},
"Trakt": {
"use_trakt": int(settings.USE_TRAKT),
Expand Down
1 change: 1 addition & 0 deletions sickchill/tagger/episode.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Episode tagger to extract information from episodes
"""

import re

from sickchill.helper.common import try_int
Expand Down
4 changes: 2 additions & 2 deletions sickchill/views/config/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def saveNotifications(
discord_webhook=None,
discord_name=None,
discord_avatar_url=None,
discord_tts=False,
discord_tts=None,
):
results = []

Expand Down Expand Up @@ -368,7 +368,7 @@ def saveNotifications(
settings.DISCORD_WEBHOOK = discord_webhook
settings.DISCORD_NAME = discord_name
settings.DISCORD_AVATAR_URL = discord_avatar_url
settings.DISCORD_TTS = discord_tts
settings.DISCORD_TTS = config.checkbox_to_value(discord_tts)

settings.USE_BOXCAR2 = config.checkbox_to_value(use_boxcar2)
settings.BOXCAR2_NOTIFY_ONSNATCH = config.checkbox_to_value(boxcar2_notify_onsnatch)
Expand Down
8 changes: 4 additions & 4 deletions sickchill/views/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,10 +411,10 @@ def testMatrix():
return _("Matrix message failed")

def testDiscord(self):
webhook = self.get_query_argument("webhook")
name = self.get_query_argument("name")
avatar = self.get_query_argument("avatar")
tts = self.get_query_argument("tts")
webhook = self.get_body_argument("webhook")
name = self.get_body_argument("name")
avatar = self.get_body_argument("avatar")
tts = self.get_body_argument("tts")

if GenericProvider.invalid_url(webhook):
return _("Invalid URL for webhook")
Expand Down
5 changes: 4 additions & 1 deletion sickchill/views/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,10 @@ async def get(self, route, *args, **kwargs):

results = await self.async_call(method, len(sig.parameters))

await self.finish(results)
try:
await self.finish(results)
except Exception as e:
logger.debug(f"self.finish exception {e}, result {results}")

except AttributeError:
logger.debug('Failed doing webui request "{0}": {1}'.format(route, traceback.format_exc()))
Expand Down
5 changes: 2 additions & 3 deletions sickchill/views/server_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,7 @@ def __init__(self, options=None):
login_url=f'{self.options["web_root"]}/login/',
static_path=self.options["data_root"],
static_url_prefix=f'{self.options["web_root"]}/',
static_handler_class=SickChillStaticFileHandler
# default_handler_class=Custom404Handler
static_handler_class=SickChillStaticFileHandler,
)

# Static File Handlers
Expand Down Expand Up @@ -168,7 +167,7 @@ def __init__(self, options=None):
SickChillStaticFileHandler,
{"path": os.path.join(self.options["data_root"], "fonts")},
name="fonts",
)
),
# TODO: WTF is this?
# url(rf'{self.options["web_root"]}/videos/(.*)', SickChillStaticFileHandler,
# {"path": self.video_root}, name='videos')
Expand Down
1 change: 0 additions & 1 deletion tests/sickchill_tests/show/test_coming_episodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Test coming episodes
"""


import unittest

from sickchill.show.ComingEpisodes import ComingEpisodes
Expand Down
1 change: 0 additions & 1 deletion tests/sickchill_tests/show/test_show.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Test shows
"""


import unittest

from sickchill import settings
Expand Down
1 change: 1 addition & 0 deletions tests/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
DBBasicTests
DBMultiTests
"""

import threading
import time
import unittest
Expand Down
1 change: 0 additions & 1 deletion tests/test_notifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Test notifiers
"""


import unittest

from sickchill.oldbeard import db
Expand Down
1 change: 1 addition & 0 deletions tests/test_post_processor_queue.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Test the post processor queue
"""

import datetime
import os.path
import time
Expand Down

0 comments on commit 42670d9

Please sign in to comment.