public async Task CreateImdbTVShowList(string listId, string listTitle) { var tvShowListParser = new MediaListParser(listId, listTitle); await tvShowListParser.GetListOfMedia(); _mediaList = await _mediaListRepository.GetBySourceAndCollectionId(Category.SOURCE_IMDB, listId, true); if (_mediaList != null) { //TODO If list exists, want size to compare with size of IMDB list //and then update if necessary Console.WriteLine("List with id {0} and title {1} already exists", listId, listTitle); return; } _mediaList = MediaList.InstanciateImdbTVShowList(tvShowListParser.ListId, tvShowListParser.ListName , tvShowListParser.ListDescription, null, null); await _mediaListRepository.Save(_mediaList); var tvShowPopulating = new TVShowPopulating(_configuration, _cache); foreach (var tvShowImdbId in tvShowListParser.MediaList) { try { await Task.Delay(200); var tvShow = await _tvShowRepository.GetByImdbId(tvShowImdbId); if (tvShow == null) { var myUrl = "https://api.themoviedb.org/3/find/" + tvShowImdbId + "?api_key=661b76973b90b91e0df214904015fd4d&external_source=imdb_id"; var client = new HttpClient(); var data = await client.GetStringAsync(myUrl); var o = JObject.Parse(data); var a = (JArray)o["tv_results"]; var tmdbId = (int)a[0]["id"]; await tvShowPopulating.AddTVShow(tmdbId); await Task.Delay(200); tvShow = await _tvShowRepository.GetByTmdbId(tmdbId); } await _relationRepository.CreateMediaListToTVShowRelationship(_mediaList, tvShow); Console.WriteLine("Show " + tvShow.Name + " added to list " + _mediaList.Name); } catch (Exception e) { Console.WriteLine("My error is " + e); } } }