From 2f182860e55d3c54b6b039ef9a08b1b65911e0c3 Mon Sep 17 00:00:00 2001 From: Prinz23 Date: Wed, 17 Jan 2018 07:37:27 +0000 Subject: [PATCH] Fix setting episode status when testing for if it should be deleted. Restrict setting newly added old episodes to WANTED to the last 90 days, older are set to SKIPPED. --- CHANGES.md | 8 +++++++- sickbeard/helpers.py | 2 +- sickbeard/tv.py | 7 +++++-- tests/helpers_tests.py | 18 ++++++++++++++++++ 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 18194611..98b534d9 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,4 +1,10 @@ -### 0.13.12 (2018-01-16 01:10:00 UTC) +### 0.13.13 (2018-01-19 00:45:00 UTC) + +* Fix setting episode status when testing for if it should be deleted +* Restrict setting newly added old episodes to WANTED to the last 90 days, older are set to SKIPPED + + +### 0.13.12 (2018-01-16 01:10:00 UTC) * Remove provider TorrentVault diff --git a/sickbeard/helpers.py b/sickbeard/helpers.py index d24bbd26..0926c912 100644 --- a/sickbeard/helpers.py +++ b/sickbeard/helpers.py @@ -1520,7 +1520,7 @@ def set_file_timestamp(filename, min_age=3, new_time=None): def should_delete_episode(status): - s = Quality.splitCompositeStatus(status) + s = Quality.splitCompositeStatus(status)[0] if s not in SNATCHED_ANY + [DOWNLOADED, ARCHIVED, IGNORED]: return True logger.log('not safe to delete episode from db because of status: %s' % statusStrings[s], logger.DEBUG) diff --git a/sickbeard/tv.py b/sickbeard/tv.py index a99011d7..5ec4a8bb 100644 --- a/sickbeard/tv.py +++ b/sickbeard/tv.py @@ -2005,11 +2005,13 @@ class TVEpisode(object): if self.status in [SKIPPED, UNAIRED, UNKNOWN, WANTED]: today = datetime.date.today() delta = datetime.timedelta(days=1) + very_old_delta = datetime.timedelta(days=90) show_time = network_timezones.parse_date_time(self.airdate.toordinal(), self.show.airs, self.show.network) show_length = datetime.timedelta(minutes=helpers.tryInt(self.show.runtime, 60)) tz_now = datetime.datetime.now(network_timezones.sb_timezone) future_airtime = (self.airdate > (today + delta) or (not self.airdate < (today - delta) and ((show_time + show_length) > tz_now))) + very_old_airdate = datetime.date.fromordinal(1) < self.airdate < (today - very_old_delta) # if this episode hasn't aired yet set the status to UNAIRED if future_airtime: @@ -2029,7 +2031,7 @@ class TVEpisode(object): msg = ('Episode status %s%s, with air date in the past, marking it ' % ( statusStrings[self.status], ','.join([(' is a special', '')[0 < self.season], ('', ' is paused')[self.show.paused]])) + '%s') - self.status = (SKIPPED, WANTED)[0 < self.season and not self.show.paused] + self.status = (SKIPPED, WANTED)[0 < self.season and not self.show.paused and not very_old_airdate] # if still UNKNOWN or SKIPPED with the deprecated future airdate method elif UNKNOWN == self.status or (SKIPPED == self.status and old_airdate_future): @@ -2037,7 +2039,8 @@ class TVEpisode(object): statusStrings[self.status], ','.join([ ('', ' has old future date format')[SKIPPED == self.status and old_airdate_future], ('', ' is being updated')[bool(update)], (' is a special', '')[0 < self.season]])) + '%s') - self.status = (SKIPPED, WANTED)[update and not self.show.paused and 0 < self.season] + self.status = (SKIPPED, WANTED)[update and not self.show.paused and 0 < self.season + and not very_old_airdate] else: msg = 'Not touching episode status %s, with air date in the past, because there is no file' diff --git a/tests/helpers_tests.py b/tests/helpers_tests.py index 1acd9bc1..5771de03 100644 --- a/tests/helpers_tests.py +++ b/tests/helpers_tests.py @@ -3,6 +3,7 @@ import sys import os.path from sickbeard import helpers +from sickbeard.common import ARCHIVED, SNATCHED, SNATCHED_BEST, SNATCHED_PROPER, DOWNLOADED, SKIPPED, IGNORED, UNAIRED, UNKNOWN, WANTED, Quality sys.path.insert(1, os.path.abspath('..')) @@ -37,6 +38,23 @@ class HelpersTests(unittest.TestCase): for test_name, test_result in test_names.items(): self.assertEqual(test_result, helpers.remove_non_release_groups(test_name[0], test_name[1])) + def test_should_delete_episode(self): + test_cases = [ + ((SNATCHED, Quality.HDTV), False), + ((SNATCHED_PROPER, Quality.HDTV), False), + ((SNATCHED_BEST, Quality.HDTV), False), + ((DOWNLOADED, Quality.HDTV), False), + ((ARCHIVED, Quality.HDTV), False), + ((ARCHIVED, Quality.NONE), False), + ((SKIPPED, Quality.NONE), True), + ((IGNORED, Quality.NONE), False), + ((UNAIRED, Quality.NONE), True), + ((UNKNOWN, Quality.NONE), True), + ((WANTED, Quality.NONE), True), + ] + for c, b in test_cases: + self.assertEqual(helpers.should_delete_episode(Quality.compositeStatus(*c)), b) + if __name__ == '__main__': suite = unittest.TestLoader().loadTestsFromTestCase(HelpersTests)