Repository: pymedusa/Medusa

Issue:
Scene numbering seems to be ignored in searches
**Describe the bug**
There is a new show (Dexter: New Blood) which is a continuance from an older show "Dexter". On the scene these episodes are released as S09E01 but in the new show they are listed as S01E01.

Enableing the scene numbering and forcing the new numbering seems to ignore the season 9


**To Reproduce**
Steps to reproduce the behavior:
- add the show name exception "Dexter"
- enable scene numbering
- set the episode scene numbering to 9x01 or 9x1

**Expected behavior**
a Search for the show based on the show name exception and the scene numbering (both season and episode number)

**Screenshots**
![image](https://user-images.githubusercontent.com/10185229/140742567-09402154-8932-4f0b-a37a-8a8485e726b1.png)
![image](https://user-images.githubusercontent.com/10185229/140742598-9320d528-f459-4898-9a97-b25fc65873fd.png)
![image](https://user-images.githubusercontent.com/10185229/140742628-85afbbc0-a228-4ab3-a80b-4bccf9be763a.png)
![image](https://user-images.githubusercontent.com/10185229/140742662-f7489a0b-0f87-4a95-8e57-a4f6d86e9bc3.png)


**Medusa (please complete the following information):**
<html><body>
<!--StartFragment-->

Medusa Info: | Branch:                 master                  Commit:                 729ab4f066034709137edb43440dba7c84959626                  Version:                 0.5.20                  Database:                 44.18
-- | --
Python Version: | 3.7.11 (default, Aug 31 2021, 17:29:26)  [GCC 4.9.3 20150311 (prerelease)]
SSL Version: | OpenSSL 1.1.1l  24 Aug 2021
OS: | Linux-4.4.59+-x86_64-with-glibc2.2.5
Locale: | en_US.UTF-8
Timezone: | CET

<!--EndFragment-->
</body>
</html>

**Debug logs (at least 50 lines):**
General > Advanced Settings > Enable debug
<details>

```
2021-11-08 13:32:29 DEBUG	FORCEDSEARCHQUEUE-MANUAL-131927 :: [729ab4f] 131927: Formatting pattern: %SN - S%0SE01 - %EN -> Dexter New Blood - S01E01 - Cold Snap
2021-11-08 13:32:29 DEBUG	FORCEDSEARCHQUEUE-MANUAL-131927 :: Nyaa :: [729ab4f] Found 0 unique search results
2021-11-08 13:32:29 DEBUG	FORCEDSEARCHQUEUE-MANUAL-131927 :: Nyaa :: [729ab4f] Data returned from provider does not contain any confirmed torrents
2021-11-08 13:32:29 DEBUG	FORCEDSEARCHQUEUE-MANUAL-131927 :: Nyaa :: [729ab4f] User-Agent: Medusa/0.5.20 (Linux; 4.4.59+; 41483c08-3ee7-11ec-acc6-f5f3e5bf52c5)
2021-11-08 13:32:29 DEBUG	FORCEDSEARCHQUEUE-MANUAL-131927 :: Nyaa :: [729ab4f] GET URL: https://nyaa.si/?page=rss&c=1_0&f=2&q=Dexter+S01E01 [Status: 200]
2021-11-08 13:32:28 DEBUG	FORCEDSEARCHQUEUE-MANUAL-131927 :: Nyaa :: [729ab4f] Search string: Dexter S01E01
2021-11-08 13:32:28 DEBUG	FORCEDSEARCHQUEUE-MANUAL-131927 :: Nyaa :: [729ab4f] Data returned from provider does not contain any confirmed torrents
2021-11-08 13:32:28 DEBUG	FORCEDSEARCHQUEUE-MANUAL-131927 :: Nyaa :: [729ab4f] User-Agent: Medusa/0.5.20 (Linux; 4.4.59+; 41483c08-3ee7-11ec-acc6-f5f3e5bf52c5)
2021-11-08 13:32:28 DEBUG	FORCEDSEARCHQUEUE-MANUAL-131927 :: Nyaa :: [729ab4f] GET URL: https://nyaa.si/?page=rss&c=1_0&f=2&q=Dexter%3A+New+Blood+S01E01 [Status: 200]
2021-11-08 13:32:28 DEBUG	FORCEDSEARCHQUEUE-MANUAL-131927 :: Nyaa :: [729ab4f] Search string: Dexter: New Blood S01E01
2021-11-08 13:32:28 DEBUG	FORCEDSEARCHQUEUE-MANUAL-131927 :: Nyaa :: [729ab4f] Searching only confirmed torrents
2021-11-08 13:32:28 DEBUG	FORCEDSEARCHQUEUE-MANUAL-131927 :: Nyaa :: [729ab4f] Search mode: Episode
2021-11-08 13:32:28 DEBUG	FORCEDSEARCHQUEUE-MANUAL-131927 :: Nyaa :: [729ab4f] Could not find all candidates in cache, searching provider.
2021-11-08 13:32:28 INFO	FORCEDSEARCHQUEUE-MANUAL-131927 :: Nyaa :: [729ab4f] Performing episode search for Dexter: New Blood
2021-11-08 13:32:28 DEBUG	FORCEDSEARCHQUEUE-MANUAL-131927 :: Eztv :: [729ab4f] Found 0 unique search results
2021-11-08 13:32:28 DEBUG	FORCEDSEARCHQUEUE-MANUAL-131927 :: Eztv :: [729ab4f] Data returned from provider does not contain any torrents
2021-11-08 13:32:28 DEBUG	FORCEDSEARCHQUEUE-MANUAL-131927 :: Eztv :: [729ab4f] User-Agent: Medusa/0.5.20 (Linux; 4.4.59+; 41483c08-3ee7-11ec-acc6-f5f3e5bf52c5)
2021-11-08 13:32:28 DEBUG	FORCEDSEARCHQUEUE-MANUAL-131927 :: Eztv :: [729ab4f] GET URL: https://eztv.re/api/get-torrents?imdb_id=14164730 [Status: 200]
2021-11-08 13:32:28 DEBUG	FORCEDSEARCHQUEUE-MANUAL-131927 :: Eztv :: [729ab4f] Search string (IMDb ID): 14164730
2021-11-08 13:32:28 DEBUG	FORCEDSEARCHQUEUE-MANUAL-131927 :: Eztv :: [729ab4f] Data returned from provider does not contain any torrents
2021-11-08 13:32:28 DEBUG	FORCEDSEARCHQUEUE-MANUAL-131927 :: Eztv :: [729ab4f] User-Agent: Medusa/0.5.20 (Linux; 4.4.59+; 41483c08-3ee7-11ec-acc6-f5f3e5bf52c5)
2021-11-08 13:32:28 DEBUG	FORCEDSEARCHQUEUE-MANUAL-131927 :: Eztv :: [729ab4f] GET URL: https://eztv.re/api/get-torrents?imdb_id=14164730 [Status: 200]
2021-11-08 13:32:28 DEBUG	FORCEDSEARCHQUEUE-MANUAL-131927 :: Eztv :: [729ab4f] Search string (IMDb ID): 14164730
2021-11-08 13:32:28 DEBUG	FORCEDSEARCHQUEUE-MANUAL-131927 :: Eztv :: [729ab4f] Search mode: Episode
2021-11-08 13:32:28 DEBUG	FORCEDSEARCHQUEUE-MANUAL-131927 :: Eztv :: [729ab4f] Could not find all candidates in cache, searching provider.
2021-11-08 13:32:28 INFO	FORCEDSEARCHQUEUE-MANUAL-131927 :: Eztv :: [729ab4f] Performing episode search for Dexter: New Blood
2021-11-08 13:32:28 DEBUG	FORCEDSEARCHQUEUE-MANUAL-131927 :: TorrentDay :: [729ab4f] Transaction with 1 queries executed
2021-11-08 13:32:28 DEBUG	FORCEDSEARCHQUEUE-MANUAL-131927 :: TorrentDay :: [729ab4f] Mass updating cache table with manual results for provider: TorrentDay
2021-11-08 13:32:28 DEBUG	FORCEDSEARCHQUEUE-MANUAL-131927 :: TorrentDay :: [729ab4f] Updating item: Dexter.New.Blood.S01E01.1080p.Amazon.WebRip.H264.AC3.Will1869 to cache: torrentday
2021-11-08 13:32:28 DEBUG	FORCEDSEARCHQUEUE-MANUAL-131927 :: TorrentDay :: [729ab4f] Using cache item for Dexter.New.Blood.S01E01.1080p.Amazon.WebRip.H264.AC3.Will1869
2021-11-08 13:32:28 DEBUG	FORCEDSEARCHQUEUE-MANUAL-131927 :: TorrentDay :: [729ab4f] Adding to cache item found in manual search: Dexter.New.Blood.S01E01.1080p.Amazon.WebRip.H264.AC3.Will1869
2021-11-08 13:32:28 DEBUG	FORCEDSEARCHQUEUE-MANUAL-131927 :: TorrentDay :: [729ab4f] No wanted results found.
2021-11-08 13:32:28 DEBUG	FORCEDSEARCHQUEUE-MANUAL-131927 :: TorrentDay :: [729ab4f] Dexter.New.Blood.S01E01.1080p.Amazon.WebRip.H264.AC3.Will1869 is an unwanted quality, rejecting it
2021-11-08 13:32:28 INFO	FORCEDSEARCHQUEUE-MANUAL-131927 :: TorrentDay :: [729ab4f] Quality of Dexter.New.Blood.S01E01.1080p.Amazon.WebRip.H264.AC3.Will1869 is 1080p WEB-DL
2021-11-08 13:32:28 DEBUG	FORCEDSEARCHQUEUE-MANUAL-131927 :: TorrentDay :: [729ab4f] Transaction with 1 queries executed
2021-11-08 13:32:28 DEBUG	FORCEDSEARCHQUEUE-MANUAL-131927 :: TorrentDay :: [729ab4f] Found single episode result Dexter.New.Blood.S01E01.1080p.Amazon.WebRip.H264.AC3.Will1869 at https://torrentday.it/download.php/5919816/Dexter New Blood S01E01 1080p Amazon WebRip H264 AC3 Will1869.torrent
2021-11-08 13:32:28 DEBUG	FORCEDSEARCHQUEUE-MANUAL-131927 :: TorrentDay :: [729ab4f] Found result Dexter.New.Blood.S01E01.1080p.Amazon.WebRip.H264.AC3.Will1869 at https://torrentday.it/download.php/5919816/Dexter New Blood S01E01 1080p Amazon WebRip H264 AC3 Will1869.torrent
2021-11-08 13:32:28 DEBUG	FORCEDSEARCHQUEUE-MANUAL-131927 :: TorrentDay :: [729ab4f] Updating item: Dexter.New.Blood.S01E01.1080p.Amazon.WebRip.H264.AC3.Will1869 to cache: torrentday
2021-11-08 13:32:28 DEBUG	FORCEDSEARCHQUEUE-MANUAL-131927 :: TorrentDay :: [729ab4f] Adding item from search to cache: 'Dexter.New.Blood.S01E01.1080p.Amazon.WebRip.H264.AC3.Will1869'
2021-11-08 13:32:28 DEBUG	FORCEDSEARCHQUEUE-MANUAL-131927 :: TorrentDay :: [729ab4f] Using cache item for Dexter.New.Blood.S01E01.1080p.Amazon.WebRip.H264.AC3.Will1869
2021-11-08 13:32:28 DEBUG	FORCEDSEARCHQUEUE-MANUAL-131927 :: TorrentDay :: [729ab4f] Found 1 unique search results
2021-11-08 13:32:28 DEBUG	FORCEDSEARCHQUEUE-MANUAL-131927 :: TorrentDay :: [729ab4f] Found result: Dexter New Blood S01E01 1080p Amazon WebRip H264 AC3 Will1869 with 127 seeders and 0 leechers
2021-11-08 13:32:28 DEBUG	FORCEDSEARCHQUEUE-MANUAL-131927 :: TorrentDay :: [729ab4f] Found result: Dexter New Blood S01E01 1080p Amazon WebRip H264 AC3 Will1869 with 127 seeders and 0 leechers
2021-11-08 13:32:28 DEBUG	FORCEDSEARCHQUEUE-MANUAL-131927 :: TorrentDay :: [729ab4f] User-Agent: Medusa/0.5.20 (Linux; 4.4.59+; 41483c08-3ee7-11ec-acc6-f5f3e5bf52c5)
2021-11-08 13:32:28 DEBUG	FORCEDSEARCHQUEUE-MANUAL-131927 :: TorrentDay :: [729ab4f] GET URL: https://torrentday.it/t.json?q=Dexter%2BS01E01&2=1&26=1&7=1&24=1&34=1 [Status: 200]
2021-11-08 13:32:28 DEBUG	FORCEDSEARCHQUEUE-MANUAL-131927 :: TorrentDay :: [729ab4f] Search string: Dexter S01E01
2021-11-08 13:32:28 DEBUG	FORCEDSEARCHQUEUE-MANUAL-131927 :: TorrentDay :: [729ab4f] Found result: Dexter New Blood S01E01 1080p Amazon WebRip H264 AC3 Will1869 with 127 seeders and 0 leechers
2021-11-08 13:32:28 DEBUG	FORCEDSEARCHQUEUE-MANUAL-131927 :: TorrentDay :: [729ab4f] Found result: Dexter New Blood S01E01 1080p Amazon WebRip H264 AC3 Will1869 with 127 seeders and 0 leechers
2021-11-08 13:32:28 DEBUG	FORCEDSEARCHQUEUE-MANUAL-131927 :: TorrentDay :: [729ab4f] User-Agent: Medusa/0.5.20 (Linux; 4.4.59+; 41483c08-3ee7-11ec-acc6-f5f3e5bf52c5)
2021-11-08 13:32:28 DEBUG	FORCEDSEARCHQUEUE-MANUAL-131927 :: TorrentDay :: [729ab4f] GET URL: https://torrentday.it/t.json?q=Dexter%3A%2BNew%2BBlood%2BS01E01&2=1&26=1&7=1&24=1&34=1 [Status: 200]
2021-11-08 13:32:27 DEBUG	FORCEDSEARCHQUEUE-MANUAL-131927 :: TorrentDay :: [729ab4f] Search string: Dexter: New Blood S01E01
2021-11-08 13:32:27 DEBUG	FORCEDSEARCHQUEUE-MANUAL-131927 :: TorrentDay :: [729ab4f] Search mode: Episode
2021-11-08 13:32:27 DEBUG	FORCEDSEARCHQUEUE-MANUAL-131927 :: TorrentDay :: [729ab4f] Could not find all candidates in cache, searching provider.
2021-11-08 13:32:27 INFO	FORCEDSEARCHQUEUE-MANUAL-131927 :: TorrentDay :: [729ab4f] Performing episode search for Dexter: New Blood
2021-11-08 13:32:27 INFO	FORCEDSEARCHQUEUE-MANUAL-131927 :: [729ab4f] Using manual search providers
2021-11-08 13:32:27 DEBUG	FORCEDSEARCHQUEUE-MANUAL-131927 :: [729ab4f] Internal name cache for dexter new blood set to: dexter, dexter new blood
2021-11-08 13:32:27 INFO	FORCEDSEARCHQUEUE-MANUAL-131927 :: [729ab4f] Building internal name cache for Dexter: New Blood
2021-11-08 13:32:27 INFO	FORCEDSEARCHQUEUE-MANUAL-131927 :: [729ab4f] Finished processing 3828 scene exceptions.
2021-11-08 13:32:27 INFO	FORCEDSEARCHQUEUE-MANUAL-131927 :: [729ab4f] Updating exception_cache and exception_season_cache
2021-11-08 13:32:27 INFO	FORCEDSEARCHQUEUE-MANUAL-131927 :: [729ab4f] Beginning manual search for: Dexter New Blood - S01E01 - Cold Snap
2021-11-08 13:32:27 DEBUG	FORCEDSEARCHQUEUE-MANUAL-131927 :: [729ab4f] 131927: Formatting pattern: %SN - S%0SE01 - %EN -> Dexter New Blood - S01E01 - Cold Snap
```
</details>

**Additional context**
Add any other context about the problem here.



Discussion:
This manual scene numbering hasn't ever worked for me.

Resolving patch:
diff --git a/medusa/scene_numbering.py b/medusa/scene_numbering.py
--- a/medusa/scene_numbering.py
+++ b/medusa/scene_numbering.py
@@ -43,9 +43,37 @@
 log.logger.addHandler(logging.NullHandler())
 
 
+def get_scene_numbering(series_obj, season, episode):
+    """
+    Try loading a scene number mapping from the scene_numbering table and then the tv_episodes table.
+
+    The scene_numbering table is occupied through manually setting scene numbers.
+    The tv_episodes table has two columns reserved (scene_season and scene_episode) that
+        are filled through the xem integration.
+    If there are no manually configured scene number mappings, it will attempt the xem mapping.
+    :param series_obj: Show object.
+    :param season: Season number as specified by the indexer.
+    :param episode: episode number as specified by the indexer.
+    :returns: A tuple of scene_season, scene_episode
+    """
+    result = find_scene_numbering(series_obj, season, episode)
+    if result:
+        return result
+
+    result = find_xem_numbering(series_obj, season, episode)
+    if result:
+        return result
+    return (None, None)
+
+
 def find_scene_numbering(series_obj, season, episode):
     """
-    Same as get_scene_numbering(), but returns None if scene numbering is not set
+    Search for a scene season/episode given an indexer season/episode in the scene_numbering table.
+
+    :param series_obj: Show object.
+    :param season: Season number as specified by the indexer.
+    :param episode: episode number as specified by the indexer.
+    :returns: A tuple of scene_season, scene_episode or None.
     """
     if series_obj is None or season is None or episode is None:
         return season, episode
@@ -60,9 +88,38 @@ def find_scene_numbering(series_obj, season, episode):
         return int(rows[0]['scene_season']), int(rows[0]['scene_episode'])
 
 
-def get_scene_absolute_numbering(series_obj, absolute_number, fallback_to_xem=True):
+def find_xem_numbering(series_obj, season, episode):
+    """
+    Return the scene numbering, as retrieved from xem.
+
+    Refreshes/Loads as needed.
+
+    :param indexer_id: int
+    :param season: int
+    :param episode: int
+    :return: (int, int) a tuple of scene_season, scene_episode, or None if there is no special mapping.
     """
-    Returns a tuple, (season, episode), with the scene numbering (if there is one),
+    if series_obj is None or season is None or episode is None:
+        return season, episode
+
+    xem_refresh(series_obj)
+
+    main_db_con = db.DBConnection()
+    rows = main_db_con.select(
+        'SELECT scene_season, scene_episode '
+        'FROM tv_episodes '
+        'WHERE indexer = ? and showid = ? and season = ? '
+        'and episode = ? and (scene_season or scene_episode) != 0',
+        [series_obj.indexer, series_obj.series_id, season, episode]
+    )
+
+    if rows:
+        return int(rows[0]['scene_season']), int(rows[0]['scene_episode'])
+
+
+def get_scene_absolute_numbering(series_obj, absolute_number):
+    """
+    Return a tuple, (season, episode), with the scene numbering (if there is one),
     otherwise returns the xem numbering (if fallback_to_xem is set), otherwise
     returns the TVDB numbering.
 
@@ -80,10 +137,9 @@ def get_scene_absolute_numbering(series_obj, absolute_number, fallback_to_xem=Tr
     if result:
         return result
     else:
-        if fallback_to_xem:
-            xem_result = find_xem_absolute_numbering(series_obj, absolute_number)
-            if xem_result:
-                return xem_result
+        xem_result = find_xem_absolute_numbering(series_obj, absolute_number)
+        if xem_result:
+            return xem_result
         return absolute_number
 
 
@@ -140,35 +196,6 @@ def set_scene_numbering(series_obj, season=None, episode=None,
     series_obj.erase_cached_parse()
 
 
-def find_xem_numbering(series_obj, season, episode):
-    """
-    Returns the scene numbering, as retrieved from xem.
-
-    Refreshes/Loads as needed.
-
-    :param indexer_id: int
-    :param season: int
-    :param episode: int
-    :return: (int, int) a tuple of scene_season, scene_episode, or None if there is no special mapping.
-    """
-    if series_obj is None or season is None or episode is None:
-        return season, episode
-
-    xem_refresh(series_obj)
-
-    main_db_con = db.DBConnection()
-    rows = main_db_con.select(
-        'SELECT scene_season, scene_episode '
-        'FROM tv_episodes '
-        'WHERE indexer = ? and showid = ? and season = ? '
-        'and episode = ? and (scene_season or scene_episode) != 0',
-        [series_obj.indexer, series_obj.series_id, season, episode]
-    )
-
-    if rows:
-        return int(rows[0]['scene_season']), int(rows[0]['scene_episode'])
-
-
 def find_xem_absolute_numbering(series_obj, absolute_number):
     """
     Returns the scene numbering, as retrieved from xem.
@@ -196,37 +223,39 @@ def find_xem_absolute_numbering(series_obj, absolute_number):
         return int(rows[0]['scene_absolute_number'])
 
 
-def get_scene_numbering(series_obj, episode, season=None):
+def get_indexer_numbering_from_scene(series_obj, scene_episode, scene_season=None):
+    """Match an episode in the library with a passed (scene) season / episode."""
     xem_refresh(series_obj)
     main_db_con = db.DBConnection()
 
-    if season is None:
+    if scene_season is None:
         rows = main_db_con.select(
             'SELECT season, episode FROM tv_episodes '
             'WHERE indexer = ? AND showid = ? AND scene_absolute_number = ?',
-            [series_obj.indexer, series_obj.series_id, episode]
+            [series_obj.indexer, series_obj.series_id, scene_episode]
         )
     else:
         rows = main_db_con.select(
             'SELECT season, episode FROM tv_episodes '
             'WHERE indexer = ? AND showid = ? '
             'AND scene_season = ? AND scene_episode = ?',
-            [series_obj.indexer, series_obj.series_id, season, episode]
+            [series_obj.indexer, series_obj.series_id, scene_season, scene_episode]
         )
 
     if not rows:
         return None, None
 
     (new_sea, new_ep) = int(rows[0]['season']), int(rows[0]['episode'])
-    log.debug('Found numbering {new} from scene for show {show} {old}', {
-        'new': episode_num(new_sea, new_ep),
+    log.debug('Found local numbering {local} from scene {scene} for show {show}', {
+        'local': episode_num(new_sea, new_ep),
         'show': series_obj.name,
-        'old': episode_num(season, episode)
+        'scene': episode_num(scene_season, scene_episode)
     })
     return new_sea, new_ep
 
 
-def get_scene_abs_number(series_obj, episode, season=None):
+def get_abs_number_from_scene(series_obj, episode, season=None):
+    """Return the shows absolute episode number from scene scene absolute episode or else scene season/episode."""
     xem_refresh(series_obj)
     main_db_con = db.DBConnection()
 
@@ -254,36 +283,42 @@ def get_scene_abs_number(series_obj, episode, season=None):
         return absolute_number
 
 
-def get_custom_numbering(series_obj, episode, season=None):
+def get_custom_numbering_from_scene(series_obj, scene_episode, scene_season=None):
+    """Match a scene season and episode to a manually configured scene episode in the scene_numbering table."""
     main_db_con = db.DBConnection()
 
-    if season is None:
+    if scene_season is None:
         rows = main_db_con.select(
             'SELECT season, episode FROM scene_numbering '
             'WHERE indexer = ? AND indexer_id = ? AND scene_absolute_number = ?',
-            [series_obj.indexer, series_obj.series_id, episode]
+            [series_obj.indexer, series_obj.series_id, scene_episode]
         )
     else:
         rows = main_db_con.select(
             'SELECT season, episode FROM scene_numbering '
             'WHERE indexer = ? AND indexer_id = ? '
             'AND scene_season = ? AND scene_episode = ?',
-            [series_obj.indexer, series_obj.series_id, season, episode]
+            [series_obj.indexer, series_obj.series_id, scene_season, scene_episode]
         )
 
     if not rows:
         return None, None
 
     (new_sea, new_ep) = int(rows[0]['season']), int(rows[0]['episode'])
-    log.debug('Found numbering {new} from scene for show {show} {old}', {
-        'new': episode_num(new_sea, new_ep),
+    log.debug('Found local numbering {local} from scene {scene} for show {show}', {
+        'local': episode_num(new_sea, new_ep),
         'show': series_obj.name,
-        'old': episode_num(season, episode)
+        'scene': episode_num(scene_season, scene_episode)
     })
     return new_sea, new_ep
 
 
 def get_custom_abs_number(series_obj, episode, season=None):
+    """
+    Get the custom absolute number from scene_numbering table using the scene absolute ep.
+
+    Or if a season passed from the scene season + scene episode.
+    """
     main_db_con = db.DBConnection()
 
     if season is None:
@@ -310,37 +345,45 @@ def get_custom_abs_number(series_obj, episode, season=None):
         return absolute_number
 
 
-def get_indexer_numbering(series_obj, episode, season=None):
-    """Find the numbering for a show episode and season.
+def get_indexer_numbering(series_obj, scene_episode, scene_season=None):
+    """Match an episode in the library to a parsed scene season or scene episode.
+
+    This function is used by Guessit to match a parsed episode/season to indexer.
+    This works like a reverse of get_scene_numbering
 
     :param series_obj: Show object
     :param episode: Episode number
     :param season: Season number (optional)
     :return: Tuple, (season, episode) or (None, None)
     """
-    numbering = get_custom_numbering(series_obj, episode, season)
-    if all(number is not None for number in numbering):
-        return numbering
+    # Try to get a mapping from scene_numbering.
+    season, episode = get_custom_numbering_from_scene(series_obj, scene_episode, scene_season)
+    if all(season, episode):
+        return season, episode
 
     if series_obj.is_scene:
-        numbering = get_scene_numbering(series_obj, episode, season)
-        if all(number is not None for number in numbering):
-            return numbering
-
-    if season is not None:
-        log.debug('Found numbering {new} from parser for show {show} {old}', {
-            'new': episode_num(season, episode),
-            'show': series_obj.name,
-            'old': episode_num(season, episode)
+        # Try to get a mapping from tv_episodes.
+        season, episode = get_indexer_numbering_from_scene(series_obj, scene_episode, scene_season)
+        if all(season, episode):
+            return season, episode
+
+    if scene_season is not None:
+        # We didn't get back a mapping from scene_numbering (custom) or tv_episodes (xem)
+        # But we did pass a scene_season. Meaning we can just return the scene_season / scene_episode.
+        log.debug('No mapping found, returning passed season and episode {episode} for show {show}', {
+            'episode': episode_num(scene_season, scene_episode),
+            'show': series_obj.name
         })
-        return season, episode
+        return scene_season, scene_episode
 
+    # At this point a scene_season was not passed. Meaning we are going to try to resolve
+    # by absolute number.
     main_db_con = db.DBConnection()
     rows = main_db_con.select(
         'SELECT season, episode FROM tv_episodes '
         'WHERE indexer = ? AND showid = ? '
         'AND absolute_number = ?',
-        [series_obj.indexer, series_obj.series_id, episode]
+        [series_obj.indexer, series_obj.series_id, scene_episode]
     )
 
     if not rows:
@@ -370,7 +413,7 @@ def get_indexer_abs_numbering(series_obj, episode, season=None):
         return abs_number
 
     if series_obj.is_scene:
-        abs_number = get_scene_abs_number(series_obj, episode, season)
+        abs_number = get_abs_number_from_scene(series_obj, episode, season)
         if abs_number:
             return abs_number
 
diff --git a/medusa/server/web/home/handler.py b/medusa/server/web/home/handler.py
--- a/medusa/server/web/home/handler.py
+++ b/medusa/server/web/home/handler.py
@@ -908,16 +908,15 @@ def manualSearchSubtitles(self, showslug=None, season=None, episode=None, releas
         })
 
     # Move to apiv2 (used by display-show.vue)
-    def setSceneNumbering(self, showslug=None, forSeason=None, forEpisode=None, forAbsolute=None, sceneSeason=None,
-                          sceneEpisode=None, sceneAbsolute=None):
-
+    def setSceneNumbering(self, showslug=None, for_season=None, for_episode=None, for_absolute=None,
+                          scene_season=None, scene_episode=None, scene_absolute=None):
         # sanitize:
-        forSeason = None if forSeason in ['null', ''] else forSeason
-        forEpisode = None if forEpisode in ['null', ''] else forEpisode
-        forAbsolute = None if forAbsolute in ['null', ''] else forAbsolute
-        sceneSeason = None if sceneSeason in ['null', ''] else sceneSeason
-        sceneEpisode = None if sceneEpisode in ['null', ''] else sceneEpisode
-        sceneAbsolute = None if sceneAbsolute in ['null', ''] else sceneAbsolute
+        for_season = None if for_season in ['null', ''] else for_season
+        for_episode = None if for_episode in ['null', ''] else for_episode
+        for_absolute = None if for_absolute in ['null', ''] else for_absolute
+        scene_season = None if scene_season in ['null', ''] else scene_season
+        scene_episode = None if scene_episode in ['null', ''] else scene_episode
+        scene_absolute = None if scene_absolute in ['null', ''] else scene_absolute
 
         identifier = SeriesIdentifier.from_slug(showslug)
         series_obj = Series.find_by_identifier(identifier)
@@ -929,7 +928,7 @@ def setSceneNumbering(self, showslug=None, forSeason=None, forEpisode=None, forA
             })
 
         # Check if this is an anime, because we can't set the Scene numbering for anime shows
-        if series_obj.is_anime and forAbsolute is None:
+        if series_obj.is_anime and for_absolute is None:
             return json.dumps({
                 'success': False,
                 'errorMessage': "You can't use the Scene numbering for anime shows. "
@@ -937,7 +936,7 @@ def setSceneNumbering(self, showslug=None, forSeason=None, forEpisode=None, forA
                 'sceneSeason': None,
                 'sceneAbsolute': None,
             })
-        elif not series_obj.is_anime and (forSeason is None or forEpisode is None):
+        elif not series_obj.is_anime and (for_season is None or for_episode is None):
             return json.dumps({
                 'success': False,
                 'errorMessage': "You can't use the Scene Absolute for non-anime shows. "
@@ -948,20 +947,20 @@ def setSceneNumbering(self, showslug=None, forSeason=None, forEpisode=None, forA
         elif series_obj.is_anime:
             result = {
                 'success': True,
-                'forAbsolute': forAbsolute,
+                'forAbsolute': for_absolute,
             }
         else:
             result = {
                 'success': True,
-                'forSeason': forSeason,
-                'forEpisode': forEpisode,
+                'forSeason': for_season,
+                'forEpisode': for_episode,
             }
 
         # retrieve the episode object and fail if we can't get one
         if series_obj.is_anime:
-            ep_obj = series_obj.get_episode(absolute_number=forAbsolute)
+            ep_obj = series_obj.get_episode(absolute_number=for_absolute)
         else:
-            ep_obj = series_obj.get_episode(forSeason, forEpisode)
+            ep_obj = series_obj.get_episode(for_season, for_episode)
 
         if not ep_obj:
             result.update({
@@ -970,36 +969,36 @@ def setSceneNumbering(self, showslug=None, forSeason=None, forEpisode=None, forA
             })
         elif series_obj.is_anime:
             logger.log(u'Set absolute scene numbering for {show} from {absolute} to {scene_absolute}'.format
-                       (show=series_obj.slug, absolute=forAbsolute, scene_absolute=sceneAbsolute), logger.DEBUG)
+                       (show=series_obj.slug, absolute=for_absolute, scene_absolute=scene_absolute), logger.DEBUG)
 
-            forAbsolute = int(forAbsolute)
-            if sceneAbsolute is not None:
-                sceneAbsolute = int(sceneAbsolute)
+            for_absolute = int(for_absolute)
+            if scene_absolute is not None:
+                scene_absolute = int(scene_absolute)
 
-            set_scene_numbering(series_obj, absolute_number=forAbsolute, scene_absolute=sceneAbsolute)
+            set_scene_numbering(series_obj, absolute_number=for_absolute, scene_absolute=scene_absolute)
         else:
             logger.log(u'setEpisodeSceneNumbering for {show} from {season}x{episode} to {scene_season}x{scene_episode}'.format
-                       (show=series_obj.indexerid, season=forSeason, episode=forEpisode,
-                        scene_season=sceneSeason, scene_episode=sceneEpisode), logger.DEBUG)
+                       (show=series_obj.indexerid, season=for_season, episode=for_episode,
+                        scene_season=scene_season, scene_episode=scene_episode), logger.DEBUG)
 
-            forSeason = int(forSeason)
-            forEpisode = int(forEpisode)
-            if sceneSeason is not None:
-                sceneSeason = int(sceneSeason)
-            if sceneEpisode is not None:
-                sceneEpisode = int(sceneEpisode)
+            for_season = int(for_season)
+            for_episode = int(for_episode)
+            if scene_season is not None:
+                scene_season = int(scene_season)
+            if scene_episode is not None:
+                scene_episode = int(scene_episode)
 
             set_scene_numbering(
-                series_obj, season=forSeason, episode=forEpisode,
-                scene_season=sceneSeason, scene_episode=sceneEpisode
+                series_obj, season=for_season, episode=for_episode,
+                scene_season=scene_season, scene_episode=scene_episode
             )
 
         if series_obj.is_anime:
-            sn = get_scene_absolute_numbering(series_obj, forAbsolute)
+            sn = get_scene_absolute_numbering(series_obj, for_absolute)
             result['sceneAbsolute'] = sn
         else:
-            sn = get_scene_numbering(series_obj, forEpisode, forSeason)
-            (result['sceneSeason'], result['sceneEpisode']) = sn
+            sn = get_scene_numbering(series_obj, for_season, for_episode)
+            result['sceneSeason'], result['sceneEpisode'] = sn
 
         return json.dumps(result)
 
diff --git a/medusa/tv/episode.py b/medusa/tv/episode.py
--- a/medusa/tv/episode.py
+++ b/medusa/tv/episode.py
@@ -724,14 +724,20 @@ def load_from_db(self, season, episode):
                     self.absolute_number
                 )
 
-            if self.scene_season is None or self.scene_episode == 0:
-                self.scene_season, self.scene_episode = get_scene_numbering(
-                    self.series, self.episode, self.season
-                )
+            if self.series.is_scene:
+                self._load_scene_numbering()
 
             self.reset_dirty()
             return True
 
+    def _load_scene_numbering(self):
+        scene_mapping = get_scene_numbering(
+            self.series, self.season, self.episode
+        )
+        if all(scene_mapping):
+            self.scene_season = scene_mapping[0]
+            self.scene_episode = scene_mapping[1]
+
     def set_indexer_data(self, season=None, indexer_api=None):
         """Set episode information from indexer.
 
@@ -865,9 +871,7 @@ def load_from_indexer(self, season=None, episode=None, tvapi=None, cached_season
 
         # TODO: Just me not understanding. If we're getting the show info from the indexer.
         # Why are we trying to get the scene_season and scene_episode from the db?
-        self.scene_season, self.scene_episode = get_scene_numbering(
-            self.series, self.episode, self.season
-        )
+        self._load_scene_numbering()
 
         self.description = getattr(my_ep, 'overview', '')
 
@@ -1045,9 +1049,7 @@ def __load_from_nfo(self, location):
                         self.absolute_number
                     )
 
-                    self.scene_season, self.scene_episode = get_scene_numbering(
-                        self.series, self.episode, self.season
-                    )
+                    self._load_scene_numbering()
 
                     self.description = ep_details.findtext('plot')
                     if self.description is None:


Test patch: