Skip to content

Commit

Permalink
Add seeders and leechers to notifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
fernandog committed Mar 23, 2016
1 parent a56f560 commit 1591431
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 20 deletions.
5 changes: 4 additions & 1 deletion sickbeard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@
DBDEBUG = False
DISPLAY_ALL_SEASONS = True
DEFAULT_PAGE = 'home'
SEEDERS_LEECHERS_IN_NOTIFY = True


USE_LISTVIEW = False
Expand Down Expand Up @@ -642,7 +643,7 @@ def initialize(consoleLogging=True): # pylint: disable=too-many-locals, too-man
METADATA_WDTV, METADATA_TIVO, METADATA_MEDE8ER, IGNORE_WORDS, PREFERRED_WORDS, UNDESIRED_WORDS, TRACKERS_LIST, IGNORED_SUBS_LIST, REQUIRE_WORDS, CALENDAR_UNPROTECTED, CALENDAR_ICONS, NO_RESTART, \
USE_SUBTITLES, SUBTITLES_LANGUAGES, SUBTITLES_DIR, SUBTITLES_SERVICES_LIST, SUBTITLES_SERVICES_ENABLED, SUBTITLES_HISTORY, SUBTITLES_FINDER_FREQUENCY, SUBTITLES_MULTI, SUBTITLES_DOWNLOAD_IN_PP, SUBTITLES_KEEP_ONLY_WANTED, EMBEDDED_SUBTITLES_ALL, SUBTITLES_EXTRA_SCRIPTS, SUBTITLES_PRE_SCRIPTS, SUBTITLES_PERFECT_MATCH, subtitlesFinderScheduler, \
SUBTITLES_HEARING_IMPAIRED, ADDIC7ED_USER, ADDIC7ED_PASS, ITASA_USER, ITASA_PASS, LEGENDASTV_USER, LEGENDASTV_PASS, OPENSUBTITLES_USER, OPENSUBTITLES_PASS, \
USE_FAILED_DOWNLOADS, DELETE_FAILED, ANON_REDIRECT, LOCALHOST_IP, DEBUG, DBDEBUG, DEFAULT_PAGE, PROXY_SETTING, PROXY_INDEXERS, \
USE_FAILED_DOWNLOADS, DELETE_FAILED, ANON_REDIRECT, LOCALHOST_IP, DEBUG, DBDEBUG, DEFAULT_PAGE, SEEDERS_LEECHERS_IN_NOTIFY, PROXY_SETTING, PROXY_INDEXERS, \
AUTOPOSTPROCESSER_FREQUENCY, SHOWUPDATE_HOUR, \
ANIME_DEFAULT, NAMING_ANIME, ANIMESUPPORT, USE_ANIDB, ANIDB_USERNAME, ANIDB_PASSWORD, ANIDB_USE_MYLIST, \
ANIME_SPLIT_HOME, SCENE_DEFAULT, DOWNLOAD_URL, BACKLOG_DAYS, GIT_USERNAME, GIT_PASSWORD, \
Expand Down Expand Up @@ -691,6 +692,7 @@ def initialize(consoleLogging=True): # pylint: disable=too-many-locals, too-man
if DEFAULT_PAGE not in ('home', 'schedule', 'history', 'news', 'IRC'):
DEFAULT_PAGE = 'home'

SEEDERS_LEECHERS_IN_NOTIFY = check_setting_int(CFG, 'General', 'seeders_leechers_in_notify', 1)
ACTUAL_LOG_DIR = check_setting_str(CFG, 'General', 'log_dir', 'Logs')
LOG_DIR = ek(os.path.normpath, ek(os.path.join, DATA_DIR, ACTUAL_LOG_DIR))
LOG_NR = check_setting_int(CFG, 'General', 'log_nr', 5) # Default to 5 backup file (sickrage.log.x)
Expand Down Expand Up @@ -1680,6 +1682,7 @@ def save_config(): # pylint: disable=too-many-statements, too-many-branches
new_config['General']['debug'] = int(DEBUG)
new_config['General']['dbdebug'] = int(DBDEBUG)
new_config['General']['default_page'] = DEFAULT_PAGE
new_config['General']['seeders_leechers_in_notify'] = int(SEEDERS_LEECHERS_IN_NOTIFY)
new_config['General']['enable_https'] = int(ENABLE_HTTPS)
new_config['General']['notify_on_login'] = int(NOTIFY_ON_LOGIN)
new_config['General']['https_cert'] = HTTPS_CERT
Expand Down
11 changes: 8 additions & 3 deletions sickbeard/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,15 @@ def snatchEpisode(result, endStatus=SNATCHED): # pylint: disable=too-many-branc

if curEpObj.status not in Quality.DOWNLOADED:
try:
notifiers.notify_snatch("{} from {}".format(curEpObj._format_pattern('%SN - %Sx%0E - %EN - %QN'),
result.provider.name)) # pylint: disable=protected-access
notify_message = curEpObj.formatted_filename('%SN - %Sx%0E - %EN - %QN')
if all([sickbeard.SEEDERS_LEECHERS_IN_NOTIFY, result.seeders not in (-1, None), result.leechers not in (-1, None)]):
notifiers.notify_snatch(
"{0} with {1} seeders and {2} leechers from {3}".format(notify_message, result.seeders,
result.leechers, result.provider.name))
else:
notifiers.notify_snatch("{0} from {1}".format(notify_message, result.provider.name))
except Exception:
# Without this, when notification fail, it crashes the snatch thread and SR will
# Without this, when notification fail, it crashes the snatch thread and Medusa will
# keep snatching until notification is sent
logger.log(u"Failed to send snatch notification", logger.DEBUG)

Expand Down
43 changes: 28 additions & 15 deletions sickbeard/search_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
DAILY_SEARCH = 20
FAILED_SEARCH = 30
MANUAL_SEARCH = 40
MANUAL_SNATCH = 50

MANUAL_SEARCH_HISTORY = []
MANUAL_SEARCH_HISTORY_SIZE = 100
Expand Down Expand Up @@ -150,10 +151,11 @@ def run(self):
else:
for result in foundResults:
# just use the first result for now
if result.seeders is not -1 and result.leechers is not -1:
logger.log(u"Downloading " + result.name + " with " + str(result.seeders) + " seeders and " + str(result.leechers) + " leechers from " + result.provider.name)
if result.seeders not in (-1, None) and result.leechers not in (-1, None):
logger.log(u"Downloading {0} with {1} seeders and {2} leechers from {3}".format(result.name,
result.seeders, result.leechers, result.provider.name))
else:
logger.log(u"Downloading " + result.name + " from " + result.provider.name)
logger.log(u"Downloading {0} from {1}".format(result.name, result.provider.name))
self.success = search.snatchEpisode(result)

# give the CPU a break
Expand Down Expand Up @@ -198,10 +200,11 @@ def run(self):

if not self.manual_snatch and searchResult:
# just use the first result for now
if searchResult[0].seeders is not -1 and searchResult[0].leechers is not -1:
logger.log(u"Downloading " + searchResult[0].name + " with " + str(searchResult[0].seeders) + " seeders and " + str(searchResult[0].leechers) + " leechers from " + searchResult[0].provider.name)
if searchResult[0].seeders not in (-1, None) and searchResult[0].leechers not in (-1, None):
logger.log(u"Downloading {0} with {1} seeders and {2} leechers from {3}".format(searchResult[0].name,
searchResult[0].seeders, searchResult[0].leechers, searchResult[0].provider.name))
else:
logger.log(u"Downloading " + searchResult[0].name + " from " + searchResult[0].provider.name)
logger.log(u"Downloading {0} from {1}".format(searchResult[0].name, searchResult[0].provider.name))
self.success = search.snatchEpisode(searchResult[0])

# give the CPU a break
Expand All @@ -228,8 +231,8 @@ def run(self):
self.finish()

class ManualSnatchQueueItem(generic_queue.QueueItem):
def __init__(self, show, segment, season, episode, url, quality, provider, search_name):
generic_queue.QueueItem.__init__(self, u'Manual Search', MANUAL_SEARCH)
def __init__(self, show, segment, season, episode, url, quality, provider, search_name, seeders, leechers):
generic_queue.QueueItem.__init__(self, u'Manual Snatch', MANUAL_SNATCH)
self.priority = generic_queue.QueuePriorities.HIGH

self.success = None
Expand All @@ -244,6 +247,8 @@ def __init__(self, show, segment, season, episode, url, quality, provider, searc
self.quality = int(quality)
self.provider = providers.getProviderClass(GenericProvider.make_id(provider))
self.search_name = search_name
self.seeders = seeders
self.leechers = leechers


def run(self):
Expand All @@ -263,10 +268,16 @@ def run(self):
result.url = self.url
result.name = self.search_name
result.quality = self.quality
result.seeders = self.seeders
result.leechers = self.leechers
result.content = None

if result:
logger.log(u"Downloading " + result.name + " from " + result.provider.name)
if result.seeders not in (-1, None) and result.leechers not in (-1, None):
logger.log(u"Downloading {0} with {1} seeders and {2} leechers from {3}".format(result.name,
result.seeders, result.leechers, result.provider.name))
else:
logger.log(u"Downloading {0} from {1}".format(result.name, result.provider.name))
self.success = search.snatchEpisode(result)
else:
logger.log(u"Unable to find a download for: [" + self.segment.prettyName() + "]")
Expand Down Expand Up @@ -312,10 +323,11 @@ def run(self):
if searchResult:
for result in searchResult:
# just use the first result for now
if result.seeders is not -1 and result.leechers is not -1:
logger.log(u"Downloading " + result.name + " with " + str(result.seeders) + " seeders and " + str(result.leechers) + " leechers from " + result.provider.name)
if result.seeders not in (-1, None) and result.leechers not in (-1, None):
logger.log(u"Downloading {0} with {1} seeders and {2} leechers from {3}".format(result.name,
result.seeders, result.leechers, result.provider.name))
else:
logger.log(u"Downloading " + result.name + " from " + result.provider.name)
logger.log(u"Downloading {0} from {1}".format(result.name, result.provider.name))
self.success = search.snatchEpisode(result)

# give the CPU a break
Expand Down Expand Up @@ -372,10 +384,11 @@ def run(self):
if searchResult:
for result in searchResult:
# just use the first result for now
if result.seeders is not -1 and result.leechers is not -1:
logger.log(u"Downloading " + result.name + " with " + str(result.seeders) + " seeders and " + str(result.leechers) + " leechers from " + result.provider.name)
if result.seeders not in (-1, None) and result.leechers not in (-1, None):
logger.log(u"Downloading {0} with {1} seeders and {2} leechers from {3}".format(result.name,
result.seeders, result.leechers, result.provider.name))
else:
logger.log(u"Downloading " + result.name + " from " + result.provider.name)
logger.log(u"Downloading {0} from {1}".format(result.name, result.provider.name))
self.success = search.snatchEpisode(result)

# give the CPU a break
Expand Down
2 changes: 1 addition & 1 deletion sickbeard/webserve.py
Original file line number Diff line number Diff line change
Expand Up @@ -1416,7 +1416,7 @@ def pickManualSnatch(self, show=None, season=None, episode=None, provider=None,
# make a queue item for it and put it on the queue
ep_queue_item = search_queue.ManualSnatchQueueItem(ep_obj.show, ep_obj, season, episode,
sql_return['url'], sql_return['quality'],
provider, sql_return['name'])
provider, sql_return['name'], sql_return['seeders'], sql_return['leechers'])

sickbeard.searchQueueScheduler.action.add_item(ep_queue_item)

Expand Down

0 comments on commit 1591431

Please sign in to comment.