public IEnumerable<MediaMetadata.Types.TVSeries> GetTVSeries(string seriesName, string language)
        {
            var tvShows = new List<MediaMetadata.Types.TVSeries>();
            var url = $"{_baseUrl}search/tv?query={System.Web.HttpUtility.UrlEncode(seriesName)}&api_key={_apiKey}";
            var searchResults = RESTHelper.Helper.GetJsonData<TVSearchResults>(new Uri(url));

            foreach (var searchResult in searchResults.results.Where(r=> r.original_name.IndexOf(seriesName, StringComparison.CurrentCultureIgnoreCase) != -1 && r.original_language.Equals(language, StringComparison.CurrentCultureIgnoreCase)))
            {
                var tvSeries = GetTVSeries(searchResult.id);

                try
                {
                    var serviceTVSeries = new MediaMetadata.Types.TVSeries
                    {
                        BackdropPath = GetImageUrl(tvSeries.backdrop_path),
                        FirstAiredDate = tvSeries.first_air_date,
                        Homepage = tvSeries.homepage,
                        Genres = tvSeries.genres.Select(genre => new MediaMetadata.Types.Genre
                        {
                            SourceId = genre.id.ToString(),
                            Name = genre.name
                        }),
                        LastAiredDate = tvSeries.last_air_date,
                        Name = tvSeries.name,
                        NumberOfEpisodes = tvSeries.number_of_episodes,
                        NumberOfSeasons = tvSeries.number_of_seasons,
                        OriginalLanguage = tvSeries.original_language,
                        OriginalName = tvSeries.original_name,
                        Overview = tvSeries.overview,
                        Popularity = tvSeries.popularity,
                        Seasons = tvSeries.seasons.Select(season => new MediaMetadata.Types.TVSeason
                        {
                            AirDate = season.air_date,
                            EpisodeCount = season.episode_count,
                            SourceId = season.id.ToString(),
                            PosterPath = GetImageUrl(season.poster_path),
                            SeasonNumber = season.season_number
                        }),
                        SortName = MakeSortable(tvSeries.name),
                        PosterPath = GetImageUrl(tvSeries.poster_path),
                        SourceId = tvSeries.id.ToString(),
                        Status = tvSeries.status,
                        Type = tvSeries.type
                    };

                    tvShows.Add(serviceTVSeries);
                }
                catch (Exception ex)
                {
                    Logger.Log(EntryType.Error, "Error loading series {0}: {1}", searchResult.name, ex.ToString());
                }
            }

            return tvShows;
        }
        public IEnumerable<TVSeries> GetTVSeries(string seriesName, string language)
        {
            var tvShows = new List<TVSeries>();

            if (_xmlMirrors.Count != 0)
            {

                string url = string.Format("{0}/api/GetSeries.php?seriesname={1}&language={2}", _xmlMirrors[0].mirrorpath, seriesName, string.IsNullOrEmpty(language) ? "en" : language);
                var searchResults = RESTHelper.Helper.GetXmlData<Series>(new Uri(url));

                foreach (var searchResult in searchResults.FoundSeries)
                {
                    var tvSeries = GetTVSeries(int.Parse(searchResult.id), searchResult.language);

                    var serviceTVSeries = new TVSeries
                    {
                        BannerPath = GetImageUrl(tvSeries.FoundSeries[0].banner),
                        SourceId = tvSeries.FoundSeries[0].id,
                        OriginalLanguage = tvSeries.FoundSeries[0].language,
                        Name = tvSeries.FoundSeries[0].SeriesName,
                        OriginalName = tvSeries.FoundSeries[0].SeriesName,
                        Overview = tvSeries.FoundSeries[0].Overview,
                        FirstAiredDate = tvSeries.FoundSeries[0].FirstAired,
                        Networks = new[] { tvSeries.FoundSeries[0].Network },
                        IMDBId = tvSeries.FoundSeries[0].IMDB_ID,
                        Zap2ItId = tvSeries.FoundSeries[0].zap2it_id,
                        Cast = tvSeries.FoundActors.SeriesActors.Select(a => new Cast
                        {
                            Name = a.Name,
                            Character = a.Role,
                            Order = int.Parse(string.IsNullOrEmpty(a.SortOrder) ? "0" : a.SortOrder),
                            ProfilePath = GetImageUrl(a.Image),
                            SourceCastId = a.id
                        }),
                        Seasons = tvSeries.FoundEpisodes
                            .GroupBy(e => e.seasonid)
                            .Select(g => g.First())
                            .Select(ge => new TVSeason
                            {
                                SeasonNumber = int.Parse(ge.SeasonNumber),
                                PosterPath = GetImageUrl(tvSeries.FoundBanners.FoundBanners
                                    .Where(b => b.Season == ge.SeasonNumber && b.Language == ge.Language && b.BannerType.Equals("season", StringComparison.CurrentCultureIgnoreCase))
                                    .FirstOrDefault().BannerPath),
                                SourceId = ge.seasonid,
                                EpisodeCount = tvSeries.FoundEpisodes.Where(e => e.seasonid == ge.seasonid).Count(),
                                Episodes = tvSeries.FoundEpisodes.Where(e => e.seasonid == ge.seasonid).Select(ep => new TVEpisode
                                {
                                    AirDate = ep.FirstAired,
                                    EpisodeNumber = int.Parse(ep.EpisodeNumber),
                                    Id = ep.id,
                                    Name = ep.EpisodeName,
                                    Overview = ep.Overview,
                                    ProductionCode = ep.ProductionCode,
                                    StillPath = GetImageUrl(ep.filename),
                                    SeasonNumber = int.Parse(string.IsNullOrEmpty(ep.SeasonNumber) ? "0" : ep.SeasonNumber),
                                    VoteAverage = double.Parse(string.IsNullOrEmpty(ep.Rating) ? "0" : ep.Rating),
                                    VoteCount = int.Parse(string.IsNullOrEmpty(ep.RatingCount) ? "0" : ep.RatingCount)
                                })
                            })
                    };

                    tvShows.Add(serviceTVSeries);
                }
            }

            return tvShows;
        }