Repository: pymedusa/Medusa

Issue:
[APP SUBMITTED]: 337020: Multiple entries found in show: BEATLESS 
### INFO
**Python Version**: `2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:53:40) [MSC v.1500 64 bit (AMD64)]`
**Operating System**: `Windows-10-10.0.17134`
**Locale**: `cp1252`
**Branch**: [master](../tree/master)
**Database**: `44.12`
**Commit**: pymedusa/Medusa@54da0c77d705a23f1ce67945ba4af3e1b978dcfc
**Link to Log**: https://gist.github.com/fd2472ff96ba9420f16f143bc8d0e0eb
### ERROR
<pre>
2018-11-28 20:14:38 ERROR    SEARCHQUEUE-MANUAL-337020 :: [Nyaa] :: [54da0c7] 337020: Multiple entries found in show: BEATLESS 
</pre>
---
_STAFF NOTIFIED_: @pymedusa/support @pymedusa/moderators

edit @p0psicles: had the same issue with Tokyo Goul and Black Clover.


Discussion:
I have the same issue. So I'm sure its again a messup on tvdb or thexem.
I've copied my db. You can probably fix it by re-adding the show beatless. But i'm not 100% sure. I'll know more later.
Arrrggg. Tvdb at it again.
Well this one is kinda messed up. As they are playing around with the absolute numbering.
Like episode S01E20 has absolute number 'null' (nothing) and S01E24 has 20. Because medusa doesn't get an absolute episode number it uses the season ep number (20). So we end up with two absolute numbers 20.

This messes everything up, as medusa depends on the absolute numbering for anime.
![image](https://user-images.githubusercontent.com/1331394/49208773-f2552b00-f3b8-11e8-88a6-c53fb1939412.png)

In this case I don't know what we should do here?

https://gist.github.com/p0psicles/ea656e8d093c58f9bb44c78047c376f8
@duramato @thezoggy any ideas?
connected: #5796 #5797

Resolving patch:
diff --git a/medusa/scene_numbering.py b/medusa/scene_numbering.py
--- a/medusa/scene_numbering.py
+++ b/medusa/scene_numbering.py
@@ -501,12 +501,22 @@ def xem_refresh(series_obj, force=False):
                          entry[indexerApi(indexer_id).config['xem_origin']]['season'],
                          entry[indexerApi(indexer_id).config['xem_origin']]['episode']]
                     ])
+                    # Update the absolute_number from xem, but do not set it when it has already been set by tvdb.
+                    # We want to prevent doubles and tvdb is leading in that case.
                     cl.append([
                         'UPDATE tv_episodes SET absolute_number = ? '
-                        'WHERE indexer = ? AND showid = ? AND season = ? AND episode = ? AND absolute_number = 0',
+                        'WHERE indexer = ? AND showid = ? AND season = ? AND episode = ? AND absolute_number = 0 '
+                        'AND {absolute_number} NOT IN '
+                        '(SELECT absolute_number '
+                        'FROM tv_episodes '
+                        'WHERE absolute_number = ? AND indexer = ? AND showid = ?)'.format(
+                            absolute_number=entry[indexerApi(indexer_id).config['xem_origin']]['absolute']
+                        ),
                         [entry[indexerApi(indexer_id).config['xem_origin']]['absolute'], indexer_id, series_id,
                          entry[indexerApi(indexer_id).config['xem_origin']]['season'],
-                         entry[indexerApi(indexer_id).config['xem_origin']]['episode']]
+                         entry[indexerApi(indexer_id).config['xem_origin']]['episode'],
+                         entry[indexerApi(indexer_id).config['xem_origin']]['absolute'],
+                         indexer_id, series_id]
                     ])
                 if 'scene_2' in entry:  # for doubles
                     cl.append([


Test patch: