Repository: pymedusa/Medusa

Issue:
[APP SUBMITTED]: 'list' object has no attribute 'lower'
### INFO

Python Version: **2.7.9 (default, Mar  1 2015, 13:48:22) [GCC 4.9.2]**
Operating System: **Linux-4.4.13-5-osmc-armv7l-with-debian-8.5**
Locale: UTF-8
Branch: **optimized**
Commit: PyMedusa/SickRage@42fd472b258a4c621f98c1c9a4d5d5196338f3ee
Link to Log: https://gist.github.com/de4a9f1120b19ce01abaea0e3b64846a
### ERROR

```
FINDSUBTITLES :: [42fd472] Traceback (most recent call last):
  File "/home/osmc/SickRage/sickbeard/subtitles.py", line 326, in download_best_subs
    for s in subtitles_list], key=operator.itemgetter(1), reverse=True)
  File "/home/osmc/SickRage/lib/subliminal/score.py", line 88, in compute_score
    matches = subtitle.get_matches(video)
  File "/home/osmc/SickRage/lib/subliminal/providers/legendastv.py", line 147, in get_matches
    matches |= guess_matches(video, guessit(self.archive.name, {'type': self.type}))
  File "/home/osmc/SickRage/lib/subliminal/subtitle.py", line 233, in guess_matches
    if video.format and 'format' in guess and guess['format'].lower() == video.format.lower():
AttributeError: 'list' object has no attribute 'lower'
Traceback (most recent call last):
  File "/home/osmc/SickRage/sickbeard/subtitles.py", line 326, in download_best_subs
    for s in subtitles_list], key=operator.itemgetter(1), reverse=True)
  File "/home/osmc/SickRage/lib/subliminal/score.py", line 88, in compute_score
    matches = subtitle.get_matches(video)
  File "/home/osmc/SickRage/lib/subliminal/providers/legendastv.py", line 147, in get_matches
    matches |= guess_matches(video, guessit(self.archive.name, {'type': self.type}))
  File "/home/osmc/SickRage/lib/subliminal/subtitle.py", line 233, in guess_matches
    if video.format and 'format' in guess and guess['format'].lower() == video.format.lower():
AttributeError: 'list' object has no attribute 'lower'
```

---

_STAFF NOTIFIED_: @pymedusa/support @pymedusa/moderators



Discussion:
@ratoaq2 subliminal issue?

```
2016-07-16 09:42:50 ERROR    FINDSUBTITLES :: [42fd472] Traceback (most recent call last):
2016-07-16 09:42:50 INFO     FINDSUBTITLES :: [42fd472] Error occurred when downloading subtitles for: /media/SAMSUNG/media/downloaded/series/Mr.Robot.S02E01.eps2.0.unm4sk-pt1.tc.1080p.WEB-DL.DD5.1.H264-NTb[rarbg]/Mr.Robot.S02E01.eps2.0_unm4sk-pt1.tc.1080p.WEB-DL.DD5.1.H.264-NTb.mkv
2016-07-16 09:42:50 DEBUG    FINDSUBTITLES :: [42fd472] Exception: 'list' object has no attribute 'lower'
2016-07-16 09:42:47 DEBUG    FINDSUBTITLES :: [42fd472] Found cached video information under key sickbeard.subtitles:video|/media/SAMSUNG/media/downloaded/series/Mr.Robot.S02E01.eps2.0.unm4sk-pt1.tc.1080p.WEB-DL.DD5.1.H264-NTb[rarbg]/Mr.Robot.S02E01.eps2.0_unm4sk-pt1.tc.1080p.WEB-DL.DD5.1.H.264-NTb.mkv
2016-07-16 09:42:47 DEBUG    FINDSUBTITLES :: [42fd472] Using cached parse result for: /media/SAMSUNG/media/downloaded/series/Mr.Robot.S02E01.eps2.0.unm4sk-pt1.tc.1080p.WEB-DL.DD5.1.H264-NTb[rarbg]/Mr.Robot.S02E01.eps2.0_unm4sk-pt1.tc.1080p.WEB-DL.DD5.1.H.264-NTb.mkv
```

@ratoaq2 some how error is happening again. I had 100% sure I tested and it worked


Resolving patch:
diff --git a/sickbeard/name_parser/rules/rules.py b/sickbeard/name_parser/rules/rules.py
--- a/sickbeard/name_parser/rules/rules.py
+++ b/sickbeard/name_parser/rules/rules.py
@@ -1793,7 +1793,6 @@ def when(self, matches, context):
         :type context: dict
         :return:
         """
-        to_remove = []
         fileparts = matches.markers.named('path')
         for filepart in marker_sorted(fileparts, matches):
             formats = matches.range(filepart.start, filepart.end, predicate=lambda match: match.name == 'format')
@@ -1806,9 +1805,9 @@ def when(self, matches, context):
                                        lambda match: match.name in ('video_codec', 'release_group'))
             # If we have at least 3 matches near by, then discard the other formats
             if len(previous) + len(next_range) > 2:
-                to_remove.extend(formats[0:-1])
-
-        return to_remove
+                invalid_formats = {f.value for f in formats[0:-1]}
+                to_remove = matches.named('format', predicate=lambda m: m.value in invalid_formats)
+                return to_remove
 
 
 class EnhanceReleaseGroupDetection(Rule):


Test patch:
diff --git a/tests/datasets/tvshows.yml b/tests/datasets/tvshows.yml
--- a/tests/datasets/tvshows.yml
+++ b/tests/datasets/tvshows.yml
@@ -2706,7 +2706,8 @@
   type: episode
 
 # FixMultipleFormats
-? Show.Name.S02E01.eps2.0.unm4sk-pt1.tc.1080p.WEB-DL.DD5.1.H264-GROUP
+? - Show.Name.S02E01.eps2.0.unm4sk-pt1.tc.1080p.WEB-DL.DD5.1.H264-GROUP.mkv
+  - /folder/Show.Name.S02E01.eps2.0.unm4sk-pt1.tc.1080p.WEB-DL.DD5.1.H264-GROUP[something]/Show.Name.S02E01.eps2.0.unm4sk-pt1.tc.1080p.WEB-DL.DD5.1.H264-GROUP.mkv
 : title: Show Name
   season: 2
   episode: 1
@@ -2719,6 +2720,8 @@
   audio_channels: '5.1'
   video_codec: h264
   release_group: GROUP
+  container: mkv
+  mimetype: video/x-matroska
   type: episode
 
 # Size detection separated with .