Repository: pymedusa/Medusa

Issue:
[APP SUBMITTED]: IndexError: unknown group name: u'pre_sep'

### INFO
**Python Version**: `2.7.13 (default, Nov 24 2017, 17:33:09) [GCC 6.3.0 20170516]`
**Operating System**: `Linux-3.4.113-bananian-armv7l-with-debian-9.3`
**Locale**: `UTF-8`
**Branch**: [master](../tree/master)
**Database**: `44.9`
**Commit**: pymedusa/Medusa@d6eb72d4e1019e5d1286ae6ac1d7e4b318229ebe
**Link to Log**: https://gist.github.com/9e9fb4b020874ea836ef96e02cee192b
### ERROR
<pre>
2018-03-02 09:34:57 ERROR    Thread-17 :: [d6eb72d] Exception generated: unknown group name: u'pre_sep'
Traceback (most recent call last):
  File "/opt/medusa/<a href="../blob/d6eb72d4e1019e5d1286ae6ac1d7e4b318229ebe/medusa/server/web/core/base.py#L283">medusa/server/web/core/base.py</a>", line 283, in async_call
    result = function(**kwargs)
  File "/opt/medusa/<a href="../blob/d6eb72d4e1019e5d1286ae6ac1d7e4b318229ebe/medusa/server/web/home/post_process.py#L49">medusa/server/web/home/post_process.py</a>", line 49, in processEpisode
    ignore_subs=argToBool(ignore_subs)
  File "/opt/medusa/<a href="../blob/d6eb72d4e1019e5d1286ae6ac1d7e4b318229ebe/medusa/process_tv.py#L146">medusa/process_tv.py</a>", line 146, in process
    ignore_subs=ignore_subs)
  File "/opt/medusa/<a href="../blob/d6eb72d4e1019e5d1286ae6ac1d7e4b318229ebe/medusa/process_tv.py#L335">medusa/process_tv.py</a>", line 335, in process_files
    self.process_media(path, self.video_files, force, is_priority, ignore_subs)
  File "/opt/medusa/<a href="../blob/d6eb72d4e1019e5d1286ae6ac1d7e4b318229ebe/medusa/process_tv.py#L536">medusa/process_tv.py</a>", line 536, in process_media
    self.result = processor.process()
  File "/opt/medusa/<a href="../blob/d6eb72d4e1019e5d1286ae6ac1d7e4b318229ebe/medusa/post_processor.py#L1182">medusa/post_processor.py</a>", line 1182, in process
    proper_path = ep_obj.proper_path()
  File "/opt/medusa/<a href="../blob/d6eb72d4e1019e5d1286ae6ac1d7e4b318229ebe/medusa/tv/episode.py#L1735">medusa/tv/episode.py</a>", line 1735, in proper_path
    result = self.formatted_filename(anime_type=anime_type)
  File "/opt/medusa/<a href="../blob/d6eb72d4e1019e5d1286ae6ac1d7e4b318229ebe/medusa/tv/episode.py#L1802">medusa/tv/episode.py</a>", line 1802, in formatted_filename
    return sanitize_filename(self._format_pattern(name_groups[-1], multi, anime_type))
  File "/opt/medusa/<a href="../blob/d6eb72d4e1019e5d1286ae6ac1d7e4b318229ebe/medusa/tv/episode.py#L1701">medusa/tv/episode.py</a>", line 1701, in _format_pattern
    cur_name_group_result = re.sub('(?i)(?x)' + regex_used, regex_replacement, cur_name_group)
  File "/usr/lib/python2.7/re.py", line 155, in sub
    return _compile(pattern, flags).sub(repl, string, count)
  File "/usr/lib/python2.7/re.py", line 286, in _subx
    template = _compile_repl(template, pattern)
  File "/usr/lib/python2.7/re.py", line 271, in _compile_repl
    p = sre_parse.parse_template(repl, pattern)
  File "/usr/lib/python2.7/sre_parse.py", line 781, in parse_template
    raise IndexError(msg)
IndexError: unknown group name: u'pre_sep'
</pre>
---
_STAFF NOTIFIED_: @pymedusa/support @pymedusa/moderators

[APP SUBMITTED]: IndexError: unknown group name: u'pre_sep'

### INFO
**Python Version**: `2.7.13 (default, Nov 24 2017, 17:33:09) [GCC 6.3.0 20170516]`
**Operating System**: `Linux-3.4.113-bananian-armv7l-with-debian-9.3`
**Locale**: `UTF-8`
**Branch**: [master](../tree/master)
**Database**: `44.9`
**Commit**: pymedusa/Medusa@d6eb72d4e1019e5d1286ae6ac1d7e4b318229ebe
**Link to Log**: https://gist.github.com/9e9fb4b020874ea836ef96e02cee192b
### ERROR
<pre>
2018-03-02 09:34:57 ERROR    Thread-17 :: [d6eb72d] Exception generated: unknown group name: u'pre_sep'
Traceback (most recent call last):
  File "/opt/medusa/<a href="../blob/d6eb72d4e1019e5d1286ae6ac1d7e4b318229ebe/medusa/server/web/core/base.py#L283">medusa/server/web/core/base.py</a>", line 283, in async_call
    result = function(**kwargs)
  File "/opt/medusa/<a href="../blob/d6eb72d4e1019e5d1286ae6ac1d7e4b318229ebe/medusa/server/web/home/post_process.py#L49">medusa/server/web/home/post_process.py</a>", line 49, in processEpisode
    ignore_subs=argToBool(ignore_subs)
  File "/opt/medusa/<a href="../blob/d6eb72d4e1019e5d1286ae6ac1d7e4b318229ebe/medusa/process_tv.py#L146">medusa/process_tv.py</a>", line 146, in process
    ignore_subs=ignore_subs)
  File "/opt/medusa/<a href="../blob/d6eb72d4e1019e5d1286ae6ac1d7e4b318229ebe/medusa/process_tv.py#L335">medusa/process_tv.py</a>", line 335, in process_files
    self.process_media(path, self.video_files, force, is_priority, ignore_subs)
  File "/opt/medusa/<a href="../blob/d6eb72d4e1019e5d1286ae6ac1d7e4b318229ebe/medusa/process_tv.py#L536">medusa/process_tv.py</a>", line 536, in process_media
    self.result = processor.process()
  File "/opt/medusa/<a href="../blob/d6eb72d4e1019e5d1286ae6ac1d7e4b318229ebe/medusa/post_processor.py#L1182">medusa/post_processor.py</a>", line 1182, in process
    proper_path = ep_obj.proper_path()
  File "/opt/medusa/<a href="../blob/d6eb72d4e1019e5d1286ae6ac1d7e4b318229ebe/medusa/tv/episode.py#L1735">medusa/tv/episode.py</a>", line 1735, in proper_path
    result = self.formatted_filename(anime_type=anime_type)
  File "/opt/medusa/<a href="../blob/d6eb72d4e1019e5d1286ae6ac1d7e4b318229ebe/medusa/tv/episode.py#L1802">medusa/tv/episode.py</a>", line 1802, in formatted_filename
    return sanitize_filename(self._format_pattern(name_groups[-1], multi, anime_type))
  File "/opt/medusa/<a href="../blob/d6eb72d4e1019e5d1286ae6ac1d7e4b318229ebe/medusa/tv/episode.py#L1701">medusa/tv/episode.py</a>", line 1701, in _format_pattern
    cur_name_group_result = re.sub('(?i)(?x)' + regex_used, regex_replacement, cur_name_group)
  File "/usr/lib/python2.7/re.py", line 155, in sub
    return _compile(pattern, flags).sub(repl, string, count)
  File "/usr/lib/python2.7/re.py", line 286, in _subx
    template = _compile_repl(template, pattern)
  File "/usr/lib/python2.7/re.py", line 271, in _compile_repl
    p = sre_parse.parse_template(repl, pattern)
  File "/usr/lib/python2.7/sre_parse.py", line 781, in parse_template
    raise IndexError(msg)
IndexError: unknown group name: u'pre_sep'
</pre>
---
_STAFF NOTIFIED_: @pymedusa/support @pymedusa/moderators



Discussion:
Additional information:
This has been happening for about a month now and it keeps happening when trying to post-process any episode from two anime series, Dragon Ball Super and One Piece. I didn't test it with any other anime series.

Post-processing for all other (non-anime) series works just fine.
Does anybody have some more info on this as to what might be causing this error?

I'm still getting this error message, so anime post-processing is still broken to me.
What is your custom anime naming pattern?
I've set it to custom: ```%S.N.%0E.%SQ.N.%RT.%RG```

Oh, but I just noticed the non-custom option ```Show.Name.003.Ep.Name```works!

**Rambling/debugging below this point.**

```%S.N.S%0SE%0E.``` produces Show.Name.003.ext. This is what I want, but I have no idea why there's ```S%0S``` for season number in there, or why there's two zeroes, or why the ```S``` and ```E``` don't show up in the result. Maybe I'm misreading the naming legend..?

So I remove the season part

```%S.N.E%0E``` Doesn't work
@noodle- 
> %S.N.S%0SE%0E. produces Show.Name.003.ext. This is what I want, but I have no idea why there's S%0S for season number in there, or why there's two zeroes, or why the S and E don't show up in the result. Maybe I'm misreading the naming legend..?

I don't use the anime feature at all, but I know you have an option below to choose the episode numbering type:
- **Add Absolute Number**
		Add the absolute number to the season/episode format?
		Only applies to animes. (eg. S15E45 - 310 vs S15E45)
- **Only Absolute Number**
	Replace season/episode format with absolute number
	Only applies to animes.
- **No Absolute Number**
	Don't include the absolute number
	Only applies to animes.

> I've set it to custom: %S.N.%0E.%SQ.N.%RT.%RG
> %S.N.E%0E Doesn't work

I can get the error with the following configurations:
 - Pattern [Custom]: `%S.N.%0E.%SQ.N.%RT.%RG`
   Episode Numbering: Only Absolute Number
 - Pattern [Custom]: `%S.N.E%0E`
    Episode Numbering: Only Absolute Number

So the bug is related to the "Only Absolute Number" option.
I'll try to find out what the issue is, but I don't know anything about that part of the code,
so no promises :wink: 
Additional information:
This has been happening for about a month now and it keeps happening when trying to post-process any episode from two anime series, Dragon Ball Super and One Piece. I didn't test it with any other anime series.

Post-processing for all other (non-anime) series works just fine.
Does anybody have some more info on this as to what might be causing this error?

I'm still getting this error message, so anime post-processing is still broken to me.
What is your custom anime naming pattern?
I've set it to custom: ```%S.N.%0E.%SQ.N.%RT.%RG```

Oh, but I just noticed the non-custom option ```Show.Name.003.Ep.Name```works!

**Rambling/debugging below this point.**

```%S.N.S%0SE%0E.``` produces Show.Name.003.ext. This is what I want, but I have no idea why there's ```S%0S``` for season number in there, or why there's two zeroes, or why the ```S``` and ```E``` don't show up in the result. Maybe I'm misreading the naming legend..?

So I remove the season part

```%S.N.E%0E``` Doesn't work
@noodle- 
> %S.N.S%0SE%0E. produces Show.Name.003.ext. This is what I want, but I have no idea why there's S%0S for season number in there, or why there's two zeroes, or why the S and E don't show up in the result. Maybe I'm misreading the naming legend..?

I don't use the anime feature at all, but I know you have an option below to choose the episode numbering type:
- **Add Absolute Number**
		Add the absolute number to the season/episode format?
		Only applies to animes. (eg. S15E45 - 310 vs S15E45)
- **Only Absolute Number**
	Replace season/episode format with absolute number
	Only applies to animes.
- **No Absolute Number**
	Don't include the absolute number
	Only applies to animes.

> I've set it to custom: %S.N.%0E.%SQ.N.%RT.%RG
> %S.N.E%0E Doesn't work

I can get the error with the following configurations:
 - Pattern [Custom]: `%S.N.%0E.%SQ.N.%RT.%RG`
   Episode Numbering: Only Absolute Number
 - Pattern [Custom]: `%S.N.E%0E`
    Episode Numbering: Only Absolute Number

So the bug is related to the "Only Absolute Number" option.
I'll try to find out what the issue is, but I don't know anything about that part of the code,
so no promises :wink: 

Resolving patch:
diff --git a/medusa/tv/episode.py b/medusa/tv/episode.py
--- a/medusa/tv/episode.py
+++ b/medusa/tv/episode.py
@@ -1740,7 +1740,7 @@ def _format_pattern(self, pattern=None, multi=None, anime_type=None):
                             ep_string += '-' + '%(#)03d' % {'#': rel_ep.episode}
 
             regex_replacement = None
-            if anime_type == 2:
+            if anime_type == 2 and not ep_only_match:
                 regex_replacement = r'\g<pre_sep>' + ep_string + r'\g<post_sep>'
             elif season_ep_match:
                 regex_replacement = r'\g<pre_sep>\g<2>\g<3>' + ep_string + r'\g<post_sep>'


Test patch: