From eef4a7ce5e573dd2d4b2d60d2887d995ef42199e Mon Sep 17 00:00:00 2001
From: medariox <dariovizz@hotmail.it>
Date: Fri, 11 Dec 2015 23:39:51 +0100
Subject: [PATCH] Add back needed subs check

fix indent

more small subs improvements

less noodles!

more checks
---
 gui/slick/views/displayShow.mako |  6 ++----
 sickbeard/subtitles.py           | 18 +++++++++++++-----
 2 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/gui/slick/views/displayShow.mako b/gui/slick/views/displayShow.mako
index f53a65488..c071de732 100644
--- a/gui/slick/views/displayShow.mako
+++ b/gui/slick/views/displayShow.mako
@@ -521,10 +521,8 @@
                         <a class="epSearch" id="${str(show.indexerid)}x${str(epResult["season"])}x${str(epResult["episode"])}" name="${str(show.indexerid)}x${str(epResult["season"])}x${str(epResult["episode"])}" href="searchEpisode?show=${show.indexerid}&amp;season=${epResult["season"]}&amp;episode=${epResult["episode"]}"><img src="${srRoot}/images/search16.png" width="16" height="16" alt="search" title="Manual Search" /></a>
                     % endif
                 % endif
-                % if sickbeard.USE_SUBTITLES and show.subtitles and epResult["location"]:
-                    % if (sickbeard.SUBTITLES_MULTI and subtitles.needs_subtitles(epResult["subtitles"])) or (not sickbeard.SUBTITLES_MULTI and len(subtitles.wanted_languages()) > 0 and "und" not in epResult["subtitles"] and list(subtitles.wanted_languages())[0] not in epResult["subtitles"]):
-                        <a class="epSubtitlesSearch" href="searchEpisodeSubtitles?show=${show.indexerid}&amp;season=${epResult["season"]}&amp;episode=${epResult["episode"]}"><img src="${srRoot}/images/closed_captioning.png" height="16" alt="search subtitles" title="Search Subtitles" /></a>
-                    % endif
+                % if sickbeard.USE_SUBTITLES and show.subtitles and epResult["location"] and subtitles.needs_subtitles(epResult['subtitles']):
+                    <a class="epSubtitlesSearch" href="searchEpisodeSubtitles?show=${show.indexerid}&amp;season=${epResult["season"]}&amp;episode=${epResult["episode"]}"><img src="${srRoot}/images/closed_captioning.png" height="16" alt="search subtitles" title="Search Subtitles" /></a>
                 % endif
             </td>
         </tr>
diff --git a/sickbeard/subtitles.py b/sickbeard/subtitles.py
index 6bb68761e..932caded5 100644
--- a/sickbeard/subtitles.py
+++ b/sickbeard/subtitles.py
@@ -122,13 +122,16 @@ def subtitle_code_filter():
 
 
 def needs_subtitles(subtitles):
-    if isinstance(subtitles, basestring) and sickbeard.SUBTITLES_MULTI:
-        subtitles = {subtitle.strip() for subtitle in subtitles.split(',')}
+    if not wanted_languages():
+        return False
+
+    if isinstance(subtitles, basestring):
+        subtitles = {subtitle.strip() for subtitle in subtitles.split(',') if subtitle.strip()}
 
     if sickbeard.SUBTITLES_MULTI:
-        return len(wanted_languages().difference(subtitles)) > 0
-    elif 'und' not in subtitles:
-        return True
+        return wanted_languages().difference(subtitles)
+
+    return 'und' not in subtitles
 
 
 # Hack around this for now.
@@ -456,6 +459,11 @@ class SubtitlesFinder(object):
                            % (ep_to_sub['show_name'], ep_to_sub['season'], ep_to_sub['episode']), logger.DEBUG)
                 continue
 
+            if not needs_subtitles(ep_to_sub['subtitles']):
+                logger.log(u'Episode already has all needed subtitles, skipping %s S%02dE%02d'
+                           % (ep_to_sub['show_name'], ep_to_sub['season'], ep_to_sub['episode']), logger.DEBUG)
+                continue
+
             logger.log(u"%s S%02dE%02d doesn't have all needed subtitles"
                        % (ep_to_sub['show_name'], ep_to_sub['season'], ep_to_sub['episode']), logger.DEBUG)
 
-- 
GitLab