Repository: pymedusa/Medusa

Issue:
Post-processor crashes
**Tried submitting this log through Medusa, but that feature doesn't work** (someone else already submitted that issue)

**Branch/Commit:** commit b16e0e5eb4ded727eebd2ab2cd9683ab597662f5 (HEAD -> master, origin/master, origin/HEAD)
**OS:** FreeNAS 11.0-U4
**What you did:** restarted Medusa, waited 10 minutes for the post-processor to kick in
**What happened:** exception generated; see below
**What you expected:** downloads should've been sorted into their destination directories
**Logs:**
```
2017-11-03 08:28:35 ERROR    POSTPROCESSOR :: [b16e0e5] Exception generated: 'ascii' codec can't encode character u'\u2019' in position 37: ordinal not in range(128)
Traceback (most recent call last):
  File "/usr/local/share/medusa/medusa/scheduler.py", line 93, in run
    self.action.run(self.force)
  File "/usr/local/share/medusa/medusa/auto_post_processor.py", line 57, in run
    process_tv.ProcessResult(app.TV_DOWNLOAD_DIR, app.PROCESS_METHOD).process(force=force)
  File "/usr/local/share/medusa/medusa/process_tv.py", line 162, in process
    ignore_subs=ignore_subs)
  File "/usr/local/share/medusa/medusa/process_tv.py", line 334, in process_files
    self.process_media(path, self.video_files, force, is_priority, ignore_subs)
  File "/usr/local/share/medusa/medusa/process_tv.py", line 535, in process_media
    self.result = processor.process()
  File "/usr/local/share/medusa/medusa/post_processor.py", line 1093, in process
    self._delete(cur_ep.location, associated_files=True)
  File "/usr/local/share/medusa/medusa/post_processor.py", line 330, in _delete
    file_list += self.list_associated_files(file_list[0], subfolders=True)
  File "/usr/local/share/medusa/medusa/post_processor.py", line 190, in list_associated_files
    processed_names += filter(None, (self._rar_basename(file_path, files),))
  File "/usr/local/share/medusa/medusa/post_processor.py", line 300, in _rar_basename
    for rar in rars:
  File "/usr/local/share/medusa/medusa/post_processor.py", line 298, in <genexpr>
    rars = (x for x in files if rarfile.is_rarfile(x))
  File "/usr/local/share/medusa/ext/rarfile.py", line 404, in is_rarfile
    return _get_rar_version(xfile) > 0
  File "/usr/local/share/medusa/ext/rarfile.py", line 389, in _get_rar_version
    with XFile(xfile) as fd:
  File "/usr/local/share/medusa/ext/rarfile.py", line 2401, in __init__
    self._fd = open(xfile, 'rb', bufsize)
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2019' in position 37: ordinal not in range(128)
```



Discussion:
Bulk renaming is also having issues...looks like any file with a name with non-ASCII characters is causing it to choke.  Don't know how this is supposed to work out for non-English-speakers who use those characters regularly, let alone those of us who have an episode or two with names borrowed from foreign languages.  This would appear to be a regression introduced sometime since the fork from SickRage, as SickRage didn't have this problem.
This is actually a bug with rarfile as you can see from the logs. Is the mass update issue the same as [here](https://github.com/pymedusa/Medusa/issues/3160)? If not, open a new issue with logs please. We have plenty of non-English speaking users that have no issues whatsoever.
>Is the mass update issue the same as here?

It appears to be a different problem.  Should I just attach the entire application.log (I've only had Medusa running since yesterday), or is there another file with debugging information?  Debugging would have been enabled for at least part of the log.
It would be best if you could post the debug log just after the error happened. Also please open a new issue: one problem = one issue. Thanks!

Resolving patch:
diff --git a/medusa/init/filesystem.py b/medusa/init/filesystem.py
--- a/medusa/init/filesystem.py
+++ b/medusa/init/filesystem.py
@@ -7,10 +7,12 @@
 import shutil
 import sys
 import tarfile
-
 import tempfile # noqa # pylint: disable=unused-import
+
 import certifi
 
+import rarfile
+
 from six import binary_type, text_type
 
 
@@ -126,6 +128,7 @@ def initialize():
                   'split', 'splitext'],
         shutil: ['copyfile', 'copymode', 'move', 'rmtree'],
         tarfile: ['is_tarfile'],
+        rarfile: ['is_rarfile'],
     }
 
     # pyOpenSSL 0.14-1 bug: it can't handle unicode input.


Test patch: