Repository: pymedusa/Medusa

Issue:
[APP SUBMITTED]: AttributeError: 'NoneType' object has no attribute 'lower'

### INFO
**Python Version**: `2.7.14 (default, Dec 14 2017, 15:51:29) [GCC 6.4.0]`
**Operating System**: `Linux-4.9.0-8-amd64-x86_64-with`
**Locale**: `None`
**Branch**: [master](../tree/master)
**Database**: `44.12`
**Commit**: pymedusa/Medusa@f5973b28465246e67465d7d86bdc8aa74d13e659
**Link to Log**: https://gist.github.com/fc5b49522882a34aa5c6c23b8ea16c36
### ERROR
<pre>
2018-08-21 22:50:35 ERROR    SHOWQUEUE-REFRESH :: [f5973b2] 71863: Error while refreshing show Lupin III. Error: 'NoneType' object has no attribute 'lower'
Traceback (most recent call last):
  File "/app/medusa/<a href="../blob/f5973b28465246e67465d7d86bdc8aa74d13e659/medusa/show_queue.py#L686">medusa/show_queue.py</a>", line 686, in run
    self.show.refresh_dir()
  File "/app/medusa/<a href="../blob/f5973b28465246e67465d7d86bdc8aa74d13e659/medusa/tv/series.py#L1718">medusa/tv/series.py</a>", line 1718, in refresh_dir
    self.load_episodes_from_dir()
  File "/app/medusa/<a href="../blob/f5973b28465246e67465d7d86bdc8aa74d13e659/medusa/tv/series.py#L1006">medusa/tv/series.py</a>", line 1006, in load_episodes_from_dir
    parse_result = NameParser(series=self, try_indexers=True).parse(ep_file_name)
  File "/app/medusa/<a href="../blob/f5973b28465246e67465d7d86bdc8aa74d13e659/medusa/name_parser/parser.py#L366">medusa/name_parser/parser.py</a>", line 366, in parse
    result = self._parse_string(name)
  File "/app/medusa/<a href="../blob/f5973b28465246e67465d7d86bdc8aa74d13e659/medusa/name_parser/parser.py#L297">medusa/name_parser/parser.py</a>", line 297, in _parse_string
    new_episode_numbers, new_season_numbers, new_absolute_numbers = self._parse_anime(result)
  File "/app/medusa/<a href="../blob/f5973b28465246e67465d7d86bdc8aa74d13e659/medusa/name_parser/parser.py#L189">medusa/name_parser/parser.py</a>", line 189, in _parse_anime
    scene_season = scene_exceptions.get_scene_exceptions_by_name(result.series_name)[0][1]
  File "/app/medusa/<a href="../blob/f5973b28465246e67465d7d86bdc8aa74d13e659/medusa/scene_exceptions.py#L173">medusa/scene_exceptions.py</a>", line 173, in get_scene_exceptions_by_name
    if show_name.lower() in show_names:
AttributeError: 'NoneType' object has no attribute 'lower'
</pre>
---
_STAFF NOTIFIED_: @pymedusa/support @pymedusa/moderators



Discussion:
Happening on file re-scan and full update on Lupin III and another show with season folder and episodes copied manually (named S\**E**.mkv)

Scene exceptions were populated automatically on Lupin III and empty on the other one.
Fyi disabling the anime flag and re-scanning seems to fix it. Even after re-enabling the flag and adding a new episode it works.
@medariox the guesit parse cant match a local show object. We should make sure we dont run the lower on a none object. But also look at the root cause here. 

Resolving patch:
diff --git a/medusa/name_parser/parser.py b/medusa/name_parser/parser.py
--- a/medusa/name_parser/parser.py
+++ b/medusa/name_parser/parser.py
@@ -186,7 +186,8 @@ def _parse_anime(result):
         # "diamond is unbreakable" exception back to season 4 of it's "master" table. This will be used later
         # to translate it to an absolute number, which in turn can be translated to an indexer SxEx.
         # For example Diamond is unbreakable - 26 -> Season 4 -> Absolute number 100 -> tvdb S03E26
-        scene_season = scene_exceptions.get_scene_exceptions_by_name(result.series_name)[0][1]
+        scene_season = scene_exceptions.get_scene_exceptions_by_name(
+            result.series_name or result.series.name)[0][1]
 
         if result.ab_episode_numbers:
             for absolute_episode in result.ab_episode_numbers:
@@ -198,7 +199,8 @@ def _parse_anime(result):
                 #
                 # Don't assume that scene_exceptions season is the same as indexer season.
                 # E.g.: [HorribleSubs] Cardcaptor Sakura Clear Card - 08 [720p].mkv thetvdb s04, thexem s02
-                if result.series.is_scene or (result.season_number is None and scene_season > 0):
+                if result.series.is_scene or (result.season_number is None and
+                                              scene_season is not None and scene_season > 0):
                     a = scene_numbering.get_indexer_absolute_numbering(
                         result.series, absolute_episode, True, scene_season
                     )
@@ -206,7 +208,7 @@ def _parse_anime(result):
                 # Translate the absolute episode number, back to the indexers season and episode.
                 (season, episode) = helpers.get_all_episodes_from_absolute_number(result.series, [a])
 
-                if result.season_number is None and scene_season > 0:
+                if result.season_number is None and scene_season is not None and scene_season > 0:
                     log.debug(
                         'Detected a season scene exception [{series_name} -> {scene_season}] without a '
                         'season number in the title, '
diff --git a/medusa/scene_exceptions.py b/medusa/scene_exceptions.py
--- a/medusa/scene_exceptions.py
+++ b/medusa/scene_exceptions.py
@@ -140,6 +140,10 @@ def get_scene_exceptions_by_name(show_name):
     # TODO: Rewrite to use exceptions_cache since there is no need to hit db.
     # TODO: Make the query more linient. For example. `Jojo's Bizarre Adventure Stardust Crusaders` will not match
     # while `Jojo's Bizarre Adventure - Stardust Crusaders` is available.
+    if show_name is None:
+        logger.debug('Scene exception lookup failed because no show name was provided')
+        return [(None, None, None)]
+
     # Try the obvious case first
     cache_db_con = db.DBConnection('cache.db')
     scene_exceptions = cache_db_con.select(


Test patch: