Repository: pymedusa/Medusa

Issue:
Adding Shows from IMDB Indexer Broken
Hi, I've been attempting to add a show from the IMDB indexer specifically as the files I have match it but not the other available indexers. When either trying to add a new show or adding an existing show through IMDB, it appears to get stuck and never completes. On the "Add an existing show" page, it continues to show "Running" for the show but even after hours have passed, nothing has advanced.

Relevant debug logs, starting from choosing IMDB as the indexer to use on the Add an existing show page:
```
2022-04-19 18:28:46 DEBUG	SHOWQUEUE-ADD :: User-Agent: IMDb/8.3.1 (iPhone9,4; iOS 11.2.1)
2022-04-19 18:28:46 DEBUG	SHOWQUEUE-ADD :: GET URL: https://api.imdbws.com/title/tt0052507/versions [Status: 200]
2022-04-19 18:28:46 DEBUG	SHOWQUEUE-ADD :: User-Agent: Medusa/0.5.29 (Linux; 5.10.60-meson64; 75589d06-c00d-11ec-aa79-0242ac11000f)
2022-04-19 18:28:46 DEBUG	SHOWQUEUE-ADD :: GET URL: https://www.imdb.com/title/tt0052507/ [Status: 200]
2022-04-19 18:28:45 DEBUG	SHOWQUEUE-ADD :: User-Agent: IMDb/8.3.1 (iPhone9,4; iOS 11.2.1)
2022-04-19 18:28:45 DEBUG	SHOWQUEUE-ADD :: GET URL: https://api.imdbws.com/title/tt0052507/companies [Status: 200]
2022-04-19 18:28:45 DEBUG	SHOWQUEUE-ADD :: User-Agent: Medusa/0.5.29 (Linux; 5.10.60-meson64; 75589d06-c00d-11ec-aa79-0242ac11000f)
2022-04-19 18:28:45 DEBUG	SHOWQUEUE-ADD :: GET URL: https://www.imdb.com/title/tt0052507/ [Status: 200]
2022-04-19 18:28:45 DEBUG	SHOWQUEUE-ADD :: User-Agent: IMDb/8.3.1 (iPhone9,4; iOS 11.2.1)
2022-04-19 18:28:45 DEBUG	SHOWQUEUE-ADD :: GET URL: https://api.imdbws.com/title/tt0052507/releases [Status: 200]
2022-04-19 18:28:45 DEBUG	SHOWQUEUE-ADD :: User-Agent: Medusa/0.5.29 (Linux; 5.10.60-meson64; 75589d06-c00d-11ec-aa79-0242ac11000f)
2022-04-19 18:28:45 DEBUG	SHOWQUEUE-ADD :: GET URL: https://www.imdb.com/title/tt0052507/ [Status: 200]
2022-04-19 18:28:44 DEBUG	SHOWQUEUE-ADD :: User-Agent: IMDb/8.3.1 (iPhone9,4; iOS 11.2.1)
2022-04-19 18:28:44 DEBUG	SHOWQUEUE-ADD :: GET URL: https://api.imdbws.com/title/tt0052507/auxiliary [Status: 200]
2022-04-19 18:28:43 DEBUG	SHOWQUEUE-ADD :: User-Agent: Medusa/0.5.29 (Linux; 5.10.60-meson64; 75589d06-c00d-11ec-aa79-0242ac11000f)
2022-04-19 18:28:43 DEBUG	SHOWQUEUE-ADD :: GET URL: https://www.imdb.com/title/tt0052507/ [Status: 200]
2022-04-19 18:28:42 DEBUG	SHOWQUEUE-ADD :: Getting all show data for 52507
2022-04-19 18:28:42 DEBUG	SHOWQUEUE-ADD :: Getting all series data for 52507
2022-04-19 18:28:42 DEBUG	SHOWQUEUE-ADD :: IMDb: {'language': 'en', 'use_zip': True, 'session': <medusa.session.core.IndexerSession object at 0xffff9cb8b100>, 'cache': '/config/cache/indexers/IMDb'}
2022-04-19 18:28:42 DEBUG	SHOWQUEUE-ADD :: 52507: Unable to find the show in the database
2022-04-19 18:28:42 DEBUG	SHOWQUEUE-ADD :: 52507: Loading show info from database
2022-04-19 18:28:42 INFO	SHOWQUEUE-ADD :: Starting to add show by show_dir: /tv/The Bullwinkle Show
2022-04-19 18:28:33 DEBUG	APIv2-Thread-2 :: Using custom UI: <class 'medusa.classes.AllShowsListUI'>
2022-04-19 18:28:33 DEBUG	APIv2-Thread-2 :: User-Agent: IMDb/8.3.1 (iPhone9,4; iOS 11.2.1)
2022-04-19 18:28:33 DEBUG	APIv2-Thread-2 :: GET URL: https://v2.sg.media-imdb.com/suggests/b/bullwinkle_show.json [Status: 200]
2022-04-19 18:28:33 DEBUG	APIv2-Thread-2 :: Searching for show bullwinkle show
2022-04-19 18:28:33 DEBUG	APIv2-Thread-2 :: Using custom UI: <class 'medusa.classes.AllShowsListUI'>
2022-04-19 18:28:33 DEBUG	APIv2-Thread-2 :: User-Agent: IMDb/8.3.1 (iPhone9,4; iOS 11.2.1)
2022-04-19 18:28:33 DEBUG	APIv2-Thread-2 :: GET URL: https://v2.sg.media-imdb.com/suggests/t/the_bullwinkle_show.json [Status: 200]
2022-04-19 18:28:33 DEBUG	APIv2-Thread-2 :: Searching for show the bullwinkle show
2022-04-19 18:28:33 DEBUG	APIv2-Thread-2 :: Searching for show with search term(s): ['The Bullwinkle Show', 'Bullwinkle Show'] on indexer: imdb
2022-04-19 18:28:33 DEBUG	APIv2-Thread-2 :: Using custom UI: <class 'medusa.classes.AllShowsListUI'>
2022-04-19 18:28:33 DEBUG	APIv2-Thread-2 :: User-Agent: Medusa/0.5.29 (Linux; 5.10.60-meson64; 75589d06-c00d-11ec-aa79-0242ac11000f)
2022-04-19 18:28:33 DEBUG	APIv2-Thread-2 :: GET URL: https://api.themoviedb.org/3/search/tv?query=bullwinkle+show&language=en&page=1&api_key=edc5f123313769de83a71e157758030b [Status: 200]
2022-04-19 18:28:33 DEBUG	APIv2-Thread-2 :: Searching for show: bullwinkle show
2022-04-19 18:28:33 DEBUG	APIv2-Thread-2 :: Using custom UI: <class 'medusa.classes.AllShowsListUI'>
2022-04-19 18:28:33 DEBUG	APIv2-Thread-2 :: User-Agent: Medusa/0.5.29 (Linux; 5.10.60-meson64; 75589d06-c00d-11ec-aa79-0242ac11000f)
2022-04-19 18:28:33 DEBUG	APIv2-Thread-2 :: GET URL: https://api.themoviedb.org/3/search/tv?query=the+bullwinkle+show&language=en&page=1&api_key=edc5f123313769de83a71e157758030b [Status: 200]
2022-04-19 18:28:33 DEBUG	APIv2-Thread-2 :: Searching for show: the bullwinkle show
2022-04-19 18:28:33 DEBUG	APIv2-Thread-2 :: Searching for show with search term(s): ['The Bullwinkle Show', 'Bullwinkle Show'] on indexer: tmdb
2022-04-19 18:28:33 DEBUG	APIv2-Thread-2 :: User-Agent: Medusa/0.5.29 (Linux; 5.10.60-meson64; 75589d06-c00d-11ec-aa79-0242ac11000f)
2022-04-19 18:28:33 DEBUG	APIv2-Thread-2 :: GET URL: https://api.themoviedb.org/3/configuration?api_key=edc5f123313769de83a71e157758030b [Status: 200]
2022-04-19 18:28:32 DEBUG	APIv2-Thread-2 :: Using custom UI: <class 'medusa.classes.AllShowsListUI'>
2022-04-19 18:28:32 DEBUG	APIv2-Thread-2 :: User-Agent: Medusa/0.5.29 (Linux; 5.10.60-meson64; 75589d06-c00d-11ec-aa79-0242ac11000f)
2022-04-19 18:28:32 DEBUG	APIv2-Thread-2 :: GET URL: http://api.tvmaze.com/search/shows?q=bullwinkle%20show [Status: 200]
2022-04-19 18:28:32 DEBUG	APIv2-Thread-2 :: Searching for show bullwinkle show
2022-04-19 18:28:32 DEBUG	APIv2-Thread-2 :: Using custom UI: <class 'medusa.classes.AllShowsListUI'>
2022-04-19 18:28:32 DEBUG	APIv2-Thread-2 :: User-Agent: Medusa/0.5.29 (Linux; 5.10.60-meson64; 75589d06-c00d-11ec-aa79-0242ac11000f)
2022-04-19 18:28:32 DEBUG	APIv2-Thread-2 :: GET URL: http://api.tvmaze.com/search/shows?q=the%20bullwinkle%20show [Status: 200]
2022-04-19 18:28:32 DEBUG	APIv2-Thread-2 :: Searching for show the bullwinkle show
2022-04-19 18:28:32 DEBUG	APIv2-Thread-2 :: Searching for show with search term(s): ['The Bullwinkle Show', 'Bullwinkle Show'] on indexer: tvmaze
2022-04-19 18:28:32 DEBUG	APIv2-Thread-2 :: Using custom UI: <class 'medusa.classes.AllShowsListUI'>
2022-04-19 18:28:32 DEBUG	APIv2-Thread-2 :: User-Agent: Medusa/0.5.29 (Linux; 5.10.60-meson64; 75589d06-c00d-11ec-aa79-0242ac11000f)
2022-04-19 18:28:32 DEBUG	APIv2-Thread-2 :: GET URL: https://api.thetvdb.com/search/series?name=bullwinkle+show [Status: 200]
2022-04-19 18:28:32 DEBUG	APIv2-Thread-2 :: Searching for show: bullwinkle show
2022-04-19 18:28:32 DEBUG	APIv2-Thread-2 :: Using custom UI: <class 'medusa.classes.AllShowsListUI'>
2022-04-19 18:28:32 DEBUG	APIv2-Thread-2 :: User-Agent: Medusa/0.5.29 (Linux; 5.10.60-meson64; 75589d06-c00d-11ec-aa79-0242ac11000f)
2022-04-19 18:28:32 DEBUG	APIv2-Thread-2 :: GET URL: https://api.thetvdb.com/search/series?name=the+bullwinkle+show [Status: 200]
2022-04-19 18:28:32 DEBUG	APIv2-Thread-2 :: Searching for show: the bullwinkle show
2022-04-19 18:28:32 DEBUG	APIv2-Thread-2 :: Searching for show with search term(s): ['The Bullwinkle Show', 'Bullwinkle Show'] on indexer: tvdb
```


Discussion:

Resolving patch:
diff --git a/medusa/indexers/imdb/api.py b/medusa/indexers/imdb/api.py
--- a/medusa/indexers/imdb/api.py
+++ b/medusa/indexers/imdb/api.py
@@ -270,13 +270,16 @@ def _get_show_by_id(self, imdb_id):  # pylint: disable=unused-argument
             if companies.get('distribution'):
                 origins = self.imdb_api.get_title_versions(ImdbIdentifier(imdb_id).imdb_id)['origins'][0]
                 released_in_regions = [
-                    dist for dist in companies['distribution'] if dist.get('regions') and origins in dist['regions']
+                    dist for dist in companies['distribution']
+                    if dist.get('regions') and origins in dist['regions'] and dist['isOriginalAiring'] and dist['startYear']
                 ]
-                # Used item.get('startYear') because a startYear is not always available.
-                first_release = sorted(released_in_regions, key=lambda x: x.get('startYear'))
 
-                if first_release:
-                    mapped_results['network'] = first_release[0]['company']['name']
+                if released_in_regions:
+                    # Used item.get('startYear') because a startYear is not always available.
+                    first_release = sorted(released_in_regions, key=lambda x: x.get('startYear'))
+
+                    if first_release:
+                        mapped_results['network'] = first_release[0]['company']['name']
         except (AttributeError, LookupError, RequestException):
             log.info('No company data available for {0}, cant get a network', imdb_id)
 


Test patch: