From 16a8f063377f1f22666d6f1866d70fbc4210ccf5 Mon Sep 17 00:00:00 2001
From: Luca <l.dimarino@gmail.com>
Date: Wed, 8 May 2013 13:15:10 +0200
Subject: [PATCH] Support to force download subtitles when new episode was
 downloaded (Nyaran)

---
 sickbeard/postProcessor.py | 8 +++++++-
 sickbeard/tv.py            | 8 ++++----
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/sickbeard/postProcessor.py b/sickbeard/postProcessor.py
index 500c236e9..b9c48f8e3 100644
--- a/sickbeard/postProcessor.py
+++ b/sickbeard/postProcessor.py
@@ -835,6 +835,12 @@ class PostProcessor(object):
                     logger.log("good results: " + repr(self.good_results), logger.DEBUG)
 
                 cur_ep.status = common.Quality.compositeStatus(common.DOWNLOADED, new_ep_quality)
+
+                cur_ep.subtitles = []
+                
+                cur_ep.subtitles_searchcount = 0
+                
+                subtitles_lastsearch = '0001-01-01 00:00:00'
                 
                 cur_ep.is_proper = self.is_proper
                 
@@ -857,7 +863,7 @@ class PostProcessor(object):
         # download subtitles
         if sickbeard.USE_SUBTITLES and ep_obj.show.subtitles:
             cur_ep.location = self.file_path
-            cur_ep.downloadSubtitles()
+            cur_ep.downloadSubtitles(force=True)
 
         # figure out the base name of the resulting episode file
         if sickbeard.RENAME_EPISODES:
diff --git a/sickbeard/tv.py b/sickbeard/tv.py
index 8d8100887..2c4434042 100644
--- a/sickbeard/tv.py
+++ b/sickbeard/tv.py
@@ -912,7 +912,7 @@ class TVShow(object):
                     curEp.saveToDB()
 
 
-    def downloadSubtitles(self):
+    def downloadSubtitles(self, force=False):
         #TODO: Add support for force option
         if not ek.ek(os.path.isdir, self._location):
             logger.log(str(self.tvdbid) + ": Show dir doesn't exist, can't download subtitles", logger.DEBUG)
@@ -923,7 +923,7 @@ class TVShow(object):
             episodes = db.DBConnection().select("SELECT location FROM tv_episodes WHERE showid = ? AND location NOT LIKE '' ORDER BY season DESC, episode DESC", [self.tvdbid])
             for episodeLoc in episodes:
                 episode = self.makeEpFromFile(episodeLoc['location']);
-                subtitles = episode.downloadSubtitles()
+                subtitles = episode.downloadSubtitles(force=force)
         
                 if sickbeard.SUBTITLES_DIR:
                     for video in subtitles:
@@ -1155,7 +1155,7 @@ class TVEpisode(object):
         """Look for subtitles files and refresh the subtitles property"""
         self.subtitles = subtitles.subtitlesLanguages(self.location)
 
-    def downloadSubtitles(self):
+    def downloadSubtitles(self,force=False):
         #TODO: Add support for force option
         if not ek.ek(os.path.isfile, self.location):
             logger.log(str(self.show.tvdbid) + ": Episode file doesn't exist, can't download subtitles for episode " + str(self.season) + "x" + str(self.episode), logger.DEBUG)
@@ -1166,7 +1166,7 @@ class TVEpisode(object):
 
         try:
             need_languages = set(sickbeard.SUBTITLES_LANGUAGES) - set(self.subtitles)
-            subtitles = subliminal.download_subtitles([self.location], languages=need_languages, services=sickbeard.subtitles.getEnabledServiceList(), force=False, multi=True, cache_dir=sickbeard.CACHE_DIR)
+            subtitles = subliminal.download_subtitles([self.location], languages=need_languages, services=sickbeard.subtitles.getEnabledServiceList(), force=force, multi=True, cache_dir=sickbeard.CACHE_DIR)
             
         except Exception as e:
             logger.log("Error occurred when downloading subtitles: " + str(e), logger.DEBUG)
-- 
GitLab