Repository: pymedusa/Medusa

Issue:
Mass Redownload with Duplicates
**Describe the bug**
Even though I've got all of my TV shows set as Skipped, Medusa just did a *massive* redownload of a ton of stuff. I chewed through terabytes last night. Even worse, it started grabbing duplicates of the exact same seasons. This is going to hurt my ratio pretty bad.

**To Reproduce**
???

**Expected behavior**
Medusa not to download anything while set to Skipped.

**Screenshots**
Here's an example of it grabbing three of the same season (I'm aware of the fourth not being the same).

![image](https://user-images.githubusercontent.com/28831302/45597799-6cffd400-b98e-11e8-8a45-e1d09c688fe0.png)


**Medusa (please complete the following information):**
 - OS: CentOS 7
 - Docker Image: docker.io/linuxserver/medusa de6454b8f283
 - Branch: master
 - Commit: 4614efc77151ded92ef458a09dec39f8bd5acfc6
 - Version: v0.2.10

**Logs:**
I apologize for not selecting the right snippet of logs, but I don't know where the issue is. I believe it started around line 102.

[medusa.log](https://github.com/pymedusa/Medusa/files/2386690/medusa.log)


**Additional context**
These were previously downloaded shows. If my storage had dropped off temporarily (which I expect may have occurred), I would expect that a show that changed from present to absent would revert back to the Skipped behavior.


Discussion:
Any chance you had the whole first season of `The Walking Dead` as `Wanted`?
This will be very hard to debug without debug logs.

Resolving patch:
diff --git a/medusa/common.py b/medusa/common.py
--- a/medusa/common.py
+++ b/medusa/common.py
@@ -559,7 +559,7 @@ def should_replace(ep_status, old_quality, new_quality, allowed_qualities, prefe
         :param search_type: The search type, that started this method
         :return: True if the old quality should be replaced with new quality
         """
-        if ep_status and ep_status not in (DOWNLOADED, SNATCHED, SNATCHED_PROPER):
+        if not ep_status or ep_status not in (DOWNLOADED, SNATCHED, SNATCHED_PROPER):
             if not force:
                 return False, 'Episode status is not Downloaded, Snatched or Snatched Proper. Ignoring new quality'
 
diff --git a/medusa/tv/series.py b/medusa/tv/series.py
--- a/medusa/tv/series.py
+++ b/medusa/tv/series.py
@@ -1411,7 +1411,7 @@ def _load_from_db(self):
             self.scene = int(sql_results[0]['scene'] or 0)
             self.subtitles = int(sql_results[0]['subtitles'] or 0)
             self.dvd_order = int(sql_results[0]['dvdorder'] or 0)
-            self.quality = int(sql_results[0]['quality'] or UNSET)
+            self.quality = int(sql_results[0]['quality'] or Quality.NA)
             self.season_folders = int(not (sql_results[0]['flatten_folders'] or 0))  # TODO: Rename this in the DB
             self.paused = int(sql_results[0]['paused'] or 0)
             self._location = sql_results[0]['location']  # skip location validation
@@ -2198,7 +2198,7 @@ def want_episode(self, season, episode, quality, forced_search=False,
             )
             return False
 
-        cur_status, cur_quality = int(sql_results[0]['status']), int(sql_results[0]['quality'])
+        cur_status, cur_quality = int(sql_results[0]['status'] or UNSET), int(sql_results[0]['quality'] or Quality.NA)
         ep_status_text = statusStrings[cur_status]
         manually_searched = sql_results[0]['manually_searched']
 


Test patch: