Repository: pymedusa/Medusa

Issue:
wrong subtitles naming
Hi,

the whole was PPed and renamed by Medusa.
it dowloaded subs as well

here is what I got at the end in my folder:
![image](https://cloud.githubusercontent.com/assets/9487685/20465632/af47458e-af61-11e6-93d5-482839c4e29b.png)
there is one file with no extension

my naming partern is as such:
%S.N.S%0SE%0E.%RT.%SQ.N-%CRG

my logs:
https://gist.github.com/NicoLeOca/61893901a005ed34f4281c08ca27e686



Discussion:
@medariox can you check?

The issue here is that replace_extension() doesn't work properly.


Resolving patch:
diff --git a/medusa/post_processor.py b/medusa/post_processor.py
--- a/medusa/post_processor.py
+++ b/medusa/post_processor.py
@@ -27,7 +27,7 @@
 from six import text_type
 
 from . import app, common, db, failed_history, helpers, history, logger, notifiers, show_name_helpers
-from .helper.common import episode_num, remove_extension, replace_extension
+from .helper.common import episode_num, remove_extension
 from .helper.exceptions import (EpisodeNotFoundException, EpisodePostProcessingFailedException,
                                 ShowDirectoryNotFoundException)
 from .helpers import is_subtitle, verify_freespace
@@ -337,36 +337,35 @@ def _combined_file_operation(self, file_path, new_path, new_base_name, associate
         for cur_file_path in file_list:
             # remember if the extension changed
             changed_extension = None
-
             # file extension without leading dot (for example: de.srt)
-            cur_extension = cur_file_path[old_base_name_length + 1:]
-            # split the extension in two parts. E.g.: ('de', 'srt')
-            split_extension = os.path.splitext(cur_extension)
+            extension = cur_file_path[old_base_name_length + 1:]
+            # initally set current extension as new extension
+            new_extension = extension
 
+            # split the extension in two parts. E.g.: ('de', '.srt')
+            split_extension = os.path.splitext(extension)
             # check if it's a subtitle and also has a subtitle language
             if is_subtitle(cur_file_path) and all(split_extension):
-                cur_lang = split_extension[0]
-                if cur_lang:
-                    cur_lang = cur_lang.lower()
-                    if cur_lang == 'pt-br':
-                        cur_lang = 'pt-BR'
-                    cur_extension = cur_lang + split_extension[1]
-                    changed_extension = True
-
-            # replace .nfo with .nfo-orig to avoid conflicts
-            if cur_extension == 'nfo' and app.NFO_RENAME:
-                cur_extension = 'nfo-orig'
+                sub_lang = split_extension[0].lower()
+                if sub_lang == 'pt-br':
+                    sub_lang = 'pt-BR'
+                new_extension = sub_lang + split_extension[1]
+                changed_extension = True
+
+            # replace nfo with nfo-orig to avoid conflicts
+            if extension == 'nfo' and app.NFO_RENAME:
+                new_extension = 'nfo-orig'
                 changed_extension = True
 
             # rename file with new base name
             if new_base_name:
-                new_file_name = new_base_name + '.' + cur_extension
+                new_file_name = new_base_name + '.' + new_extension
             else:
                 # current file name including extension
                 new_file_name = os.path.basename(cur_file_path)
                 # if we're not renaming we still need to change the extension sometimes
                 if changed_extension:
-                    new_file_name = replace_extension(new_file_name, cur_extension)
+                    new_file_name = new_file_name.replace(extension, new_extension)
 
             if app.SUBTITLES_DIR and is_subtitle(cur_file_path):
                 subs_new_path = os.path.join(new_path, app.SUBTITLES_DIR)


Test patch: