Repository: pymedusa/Medusa

Issue:
Unable to read ' from file system
Medusa Info: 
Branch: master                 
Commit: b96b3ee10760ffa03a15a207841a1a2bc65798dd                 
Version: v0.1.19                 
Database: 44.8
Python Version: | 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:53:40) [MSC v.1500 64 bit (AMD64)]
SSL Version: | OpenSSL 1.0.2j  26 Sep 2016
OS: | Windows-10-10.0.14393
Locale: | nl_NL.cp1252

Coming from SickRage where I did not have this issue
When a file has a `'` in the file name Medusa generates an error.
`2017-11-29 17:26:15 WARNING  SHOWQUEUE-ADD :: [b96b3ee] Unable to scan video: C:\DATA\TVSeries\The Mayor (2017)\Season 01\The Mayor (2017) - S01E03 - Buyerâ€™s Remorse (720p.HDTV-AVS).mkv. Error: Path does not exist`
![image](https://user-images.githubusercontent.com/4103090/33386842-3050c6aa-d52c-11e7-831e-6c9b1e2370fd.png)



Discussion:
Tnx for the report, we'll look into it. 
Also getting this with other characters.
```
2018-01-06 17:42:57 WARNING  FINDSUBTITLES :: [7b9111e] Unable to scan video: C:\DATA\TVSeries\Speechless\Season 01\Speechless - S01E04 - I-N-Sâ€“ INSPIRATIONS (720p.HDTV-AVS).mkv. Error: Path does not exist
2018-01-06 17:42:55 WARNING  FINDSUBTITLES :: [7b9111e] Unable to scan video: C:\DATA\TVSeries\Speechless\Season 02\Speechless - S02E06 - S-Hâ€“SHIPPING (720p.HDTV-AVS).mkv. Error: Path does not exist
2018-01-06 17:42:55 WARNING  FINDSUBTITLES :: [7b9111e] Unable to scan video: C:\DATA\TVSeries\Speechless\Season 02\Speechless - S02E07 - B-R-Iâ€“ BRITISH I-N-Vâ€“ INVASION (720p.HDTV-AVS).mkv. Error: Path does not exist
2018-01-06 17:42:55 WARNING  FINDSUBTITLES :: [7b9111e] Unable to scan video: C:\DATA\TVSeries\Speechless\Season 01\Speechless - S01E03 - B-O-Nâ€“BONFIRE (720p.HDTV-AVS).mkv. Error: Path does not exist
2018-01-06 17:42:53 WARNING  FINDSUBTITLES :: [7b9111e] Unable to scan video: C:\DATA\TVSeries\Speechless\Season 02\Speechless - S02E02 - F-Iâ€“ FIRST S-Eâ€“ SECOND Fâ€“ FIRST DAY (720p.HDTV-AVS).mkv. Error: Path does not exist
2018-01-06 17:42:53 WARNING  FINDSUBTITLES :: [7b9111e] Unable to scan video: C:\DATA\TVSeries\Speechless\Season 02\Speechless - S02E03 - J-Jâ€™S D-Râ€“DREAM (720p.HDTV-AVS).mkv. Error: Path does not exist
2018-01-06 17:42:53 WARNING  FINDSUBTITLES :: [7b9111e] Unable to scan video: C:\DATA\TVSeries\Speechless\Season 02\Speechless - S02E01 - W-Eâ€“ WEâ€™RE B-Aâ€“ BACK! (720p.HDTV-AVS).mkv. Error: Path does not exist
2018-01-06 17:42:53 WARNING  FINDSUBTITLES :: [7b9111e] Unable to scan video: C:\DATA\TVSeries\Speechless\Season 02\Speechless - S02E05 - N-Iâ€“NIGHTMARE ON D-Iâ€“DIMEO STREET (720p.HDTV-AVS).mkv. Error: Path does not exist
2018-01-06 17:42:53 WARNING  FINDSUBTITLES :: [7b9111e] Unable to scan video: C:\DATA\TVSeries\Speechless\Season 02\Speechless - S02E04 - T-TRâ€“ TRAINING D-Aâ€“ DAY (720p.HDTV-AVS).mkv. Error: Path does not exist
```
![image](https://user-images.githubusercontent.com/4103090/34649058-619b37b0-f3a7-11e7-9ab4-098c09339615.png)
![image](https://user-images.githubusercontent.com/4103090/34649059-6f7b4a46-f3a7-11e7-89f6-3c7745a386c9.png)

I'm unable to reproduce this. Can you share relevant debug logs, please?
@medariox they are UTF-8 characters on a windows system.  Specifically the original was a right-single quote.
  
Yes, that's what I thought. I tried to name files like that and search for subs and it works just fine for me. I'm on Windows 10 as well.
@Rouzax Can you describe the steps to reproduce the issue?
I get this error for other characters as well.  #3445 
Removing duplicate tag because while its the same issue, the one i opened was for refreshing show, although it gets the same issue during scanning of the video.
Examples from my system:
```
2018-01-07 02:36:44 WARNING  SHOWQUEUE-REFRESH :: [4f6f8e8] Unable to scan video: D:\series\active\Crazy Ex-Girlfriend (2015)\Season 03\Crazy Ex-Girlfriend - S03E04 - Joshâ€™s Ex-Girlfriend is Crazy.mkv. Error: Path does not exist
2018-01-07 02:36:24 WARNING  SHOWQUEUE-REFRESH :: [4f6f8e8] Unable to scan video: D:\series\active\Crazy Ex-Girlfriend (2015)\Season 02\Crazy Ex-Girlfriend - S02E05 - Why Is Joshâ€™s Ex-Girlfriend Eating Carbs.mkv. Error: Path does not exist
2018-01-07 02:36:21 WARNING  SHOWQUEUE-REFRESH :: [4f6f8e8] Unable to scan video: D:\series\active\Crazy Ex-Girlfriend (2015)\Season 02\Crazy Ex-Girlfriend - S02E03 - All Signs Point to Joshâ€¦ or Is It Joshâ€™s Friend.mkv. Error: Path does not exist
2018-01-07 02:36:02 WARNING  SHOWQUEUE-REFRESH :: [4f6f8e8] Unable to scan video: D:\series\active\Crazy Ex-Girlfriend (2015)\Season 01\Crazy Ex-Girlfriend - S01E08 - My Mom, Gregâ€™s Mom and Joshâ€™s Sweet Dance Moves!.mp4. Error: Path does not exist
2018-01-07 02:35:56 WARNING  SHOWQUEUE-REFRESH :: [4f6f8e8] Unable to scan video: D:\series\active\Crazy Ex-Girlfriend (2015)\Season 01\Crazy Ex-Girlfriend - S01E04 - Iâ€™m Going on a Date with Joshâ€™s Friend!.mp4. Error: Path does not exist
2018-01-07 02:35:53 WARNING  SHOWQUEUE-REFRESH :: [4f6f8e8] Unable to scan video: D:\series\active\Crazy Ex-Girlfriend (2015)\Season 01\Crazy Ex-Girlfriend - S01E02 - Joshâ€™s Girlfriend is Really Cool!.mp4. Error: Path does not exist
```
Got it now. 👍 

Resolving patch:
diff --git a/medusa/subtitles.py b/medusa/subtitles.py
--- a/medusa/subtitles.py
+++ b/medusa/subtitles.py
@@ -42,6 +42,7 @@
 from medusa.subtitle_providers.utils import hash_itasa
 
 from six import iteritems, string_types, text_type
+
 from subliminal import ProviderPool, compute_score, provider_manager, refine, save_subtitles, scan_video
 from subliminal.core import search_external_subtitles
 from subliminal.score import episode_scores
@@ -593,7 +594,7 @@ def get_current_subtitles(tv_episode):
         return get_subtitles(video)
 
 
-def _encode(value, encoding='utf-8', fallback=None):
+def _encode(value, fallback=None):
     """Encode the value using the specified encoding.
 
     It fallbacks to the specified encoding or SYS_ENCODING if not defined
@@ -607,6 +608,8 @@ def _encode(value, encoding='utf-8', fallback=None):
     :return: the encoded value
     :rtype: str
     """
+    encoding = 'utf-8' if os.name != 'nt' else app.SYS_ENCODING
+
     try:
         return value.encode(encoding)
     except UnicodeEncodeError:
@@ -615,7 +618,7 @@ def _encode(value, encoding='utf-8', fallback=None):
         return value.encode(fallback or app.SYS_ENCODING)
 
 
-def _decode(value, encoding='utf-8', fallback=None):
+def _decode(value, fallback=None):
     """Decode the value using the specified encoding.
 
     It fallbacks to the specified encoding or SYS_ENCODING if not defined
@@ -629,12 +632,14 @@ def _decode(value, encoding='utf-8', fallback=None):
     :return: the decoded value
     :rtype: unicode
     """
+    encoding = 'utf-8' if os.name != 'nt' else app.SYS_ENCODING
+
     try:
-        return value.decode(encoding)
+        return text_type(value, encoding)
     except UnicodeDecodeError:
         logger.debug(u'Failed to decode to %s, falling back to %s: %r',
                      encoding, fallback or app.SYS_ENCODING, value)
-        return value.decode(fallback or app.SYS_ENCODING)
+        return text_type(value, fallback or app.SYS_ENCODING)
 
 
 def get_subtitle_description(subtitle):
@@ -1000,7 +1005,7 @@ def dhm(td):
 
             ep_num = episode_num(ep_to_sub['season'], ep_to_sub['episode']) or \
                 episode_num(ep_to_sub['season'], ep_to_sub['episode'], numbering='absolute')
-            subtitle_path = _encode(ep_to_sub['location'], encoding=app.SYS_ENCODING, fallback='utf-8')
+            subtitle_path = _encode(ep_to_sub['location'], fallback='utf-8')
             if not os.path.isfile(subtitle_path):
                 logger.debug(u'Episode file does not exist, cannot download subtitles for %s %s',
                              ep_to_sub['show_name'], ep_num)


Test patch: