Repository: pymedusa/Medusa

Issue:
[APP SUBMITTED]: Guessed more than one 'format' for 'I'm.a.Celebrity....Extra.Camp.S16E05.(17.November.2016).Web.mp4.hdtv.x264': HDTV,WEB-DL
### INFO
**Python Version**: `2.7.6 (default, Jun 22 2015, 18:00:18) [GCC 4.8.2]`
**Operating System**: `Linux-4.2.0-42-generic-i686-with-Ubuntu-14.04-trusty`
**Locale**: `None`
**Branch**: [feature/indexer/tvmaze](../tree/feature/indexer/tvmaze)
**Database**: `44.2`
**Commit**: pymedusa/Medusa@921b9c75730a3a73c0155ecb51832b0494db7946
**Link to Log**: https://gist.github.com/4a17ad485d0c364d543cf3712dbbc6b5
### ERROR
<pre>
2016-11-18 01:40:10 ERROR    SEARCHQUEUE-DAILY-SEARCH :: [TvChaosUK] :: [921b9c7] Guessed more than one 'format' for 'I'm.a.Celebrity....Extra.Camp.S16E05.(17.November.2016).Web.mp4.hdtv.x264': HDTV,WEB-DL
</pre>
---
_STAFF NOTIFIED_: @pymedusa/support @pymedusa/moderators


Discussion:

Resolving patch:
diff --git a/medusa/name_parser/rules/rules.py b/medusa/name_parser/rules/rules.py
--- a/medusa/name_parser/rules/rules.py
+++ b/medusa/name_parser/rules/rules.py
@@ -1024,20 +1024,24 @@ def when(self, matches, context):
 
         fileparts = matches.markers.named('path')
         for filepart in marker_sorted(fileparts, matches):
-            video_codecs = matches.range(filepart.start, filepart.end, lambda match: match.name == 'video_codec')
-            formats = matches.range(filepart.start, filepart.end, predicate=lambda match: match.name == 'format')
-            if len(video_codecs) != 2 or len(formats) != 1:
+            m_x264 = matches.ending(filepart.end, predicate=lambda match: match.name == 'video_codec' and match.value == 'h264', index=0)
+            if not m_x264:
                 continue
 
-            m_x264 = video_codecs[-1]
-            m_hdtv = matches.previous(m_x264, index=0)
-
-            if m_x264.end != filepart.end or m_x264.value != 'h264' or m_hdtv.name != 'format' \
-                    or m_hdtv.value != 'HDTV':
+            m_hdtv = matches.previous(m_x264, predicate=lambda match: match.name == 'format' and match.value == 'HDTV', index=0)
+            if not m_hdtv:
                 continue
 
-            to_remove.append(m_x264)
-            m_hdtv.tags.append('tvchaosuk')
+            video_codecs = matches.range(filepart.start, filepart.end, lambda match: match.name == 'video_codec')
+            formats = matches.range(filepart.start, filepart.end, predicate=lambda match: match.name == 'format')
+            unique_codecs = {v.value for v in video_codecs}
+            unique_formats = {v.value for v in formats}
+            if len(unique_codecs) > 1:
+                to_remove.append(m_x264)
+                m_hdtv.tags.append('tvchaosuk')
+            if len(unique_formats) > 1:
+                to_remove.append(m_hdtv)
+                m_x264.tags.append('tvchaosuk')
 
         return to_remove
 


Test patch:
diff --git a/tests/test_guessit.yml b/tests/test_guessit.yml
--- a/tests/test_guessit.yml
+++ b/tests/test_guessit.yml
@@ -3537,3 +3537,15 @@
 : title: Show Name
   screen_size: 4320p
   type: episode
+
+# Removing TvChaosUK workaround
+? Show.Name.-.S012E01.(16.November.2016).[PDTV.mp4].hdtv.x264
+: title: Show Name
+  season: 12
+  episode: 1
+  date: 2016-11-16
+  format: PDTV
+  video_codec: h264
+  video_encoder: x264
+  container: MP4
+  type: episode