public OmdbEpisodeProvider(IJsonSerializer jsonSerializer, IHttpClient httpClient, ILogger logger, ILibraryManager libraryManager, IFileSystem fileSystem, IServerConfigurationManager configurationManager) { _jsonSerializer = jsonSerializer; _httpClient = httpClient; _fileSystem = fileSystem; _configurationManager = configurationManager; _itemProvider = new OmdbItemProvider(jsonSerializer, httpClient, logger, libraryManager, fileSystem, configurationManager); }
public static Task<Model.Epg> GetMetadata(Model.Epg epg, CancellationToken cancellationToken) { return Task.Run(async () => { var movieItem = new MediaBrowser.Controller.Entities.Movies.Movie(); try { var movieInfo = new MovieInfo { Name = epg.Title, MetadataLanguage = "en", }; if (Cache[epg.Title] == null) { MetadataResult<MediaBrowser.Controller.Entities.Movies.Movie> omdbMovie; var omdbItemProvider = new OmdbItemProvider(LiveTvService.JsonSerializer, LiveTvService.HttpClient, LiveTvService.Logger, LiveTvService.LibraryManager, LiveTvService.FileSystem, LiveTvService.Config); omdbMovie = await omdbItemProvider.GetMetadata(movieInfo, cancellationToken); var imdbId = omdbMovie.Item.GetProviderId(MetadataProviders.Imdb); Cache.Add(epg.Title, movieItem, DateTimeOffset.Now.AddDays(1)); } else movieItem = Cache[epg.Title] as MediaBrowser.Controller.Entities.Movies.Movie; } catch (Exception exception) { epg = null; //Logger.Error("Series provider error: " + exception.Message); //Logger.ErrorException("Movie provider error", exception); } return epg; }); }
public static Task<Model.Epg> GetMetadata(Model.Epg epg, CancellationToken cancellationToken) { return Task.Run(async () => { var seriesItem = new MediaBrowser.Controller.Entities.TV.Series(); var seriesDataPath = ""; var seriesId = ""; var language = String.IsNullOrWhiteSpace(Plugin.Instance.Configuration.Provider) ? "en" : "pt"; var country = String.IsNullOrWhiteSpace(Plugin.Instance.Configuration.Provider) ? "us" : "br"; if (Plugin.Instance.Configuration.Provider == "CLARO" && (epg.IsMovie || epg.IsShopping || epg.IsSports || epg.IsNews)) return epg; try { var seriesInfo = new SeriesInfo { Name = epg.Title, ParentIndexNumber = epg.SeasonNumber, IndexNumber = epg.EpisodeNumber, MetadataLanguage = language, MetadataCountryCode = country }; if (Cache[epg.Title] == null) { MetadataResult<MediaBrowser.Controller.Entities.TV.Series> omdbSeries; var omdbItemProvider = new OmdbItemProvider(LiveTvService.JsonSerializer, LiveTvService.HttpClient, LiveTvService.Logger, LiveTvService.LibraryManager, LiveTvService.FileSystem, LiveTvService.Config); omdbSeries = await omdbItemProvider.GetMetadata(seriesInfo, cancellationToken); var imdbId = omdbSeries.Item.GetProviderId(MetadataProviders.Imdb); if (!String.IsNullOrWhiteSpace(imdbId)) { using (var result = await LiveTvService.HttpClient.Get(new HttpRequestOptions { Url = "http://www.thetvdb.com/api/GetSeriesByRemoteID.php?imdbid=" + imdbId + "&language=" + language, ResourcePool = new SemaphoreSlim(2, 2), CancellationToken = cancellationToken }).ConfigureAwait(false)) { var doc = new XmlDocument(); doc.Load(result); if (doc.HasChildNodes) { var node = doc.SelectSingleNode("//Series/seriesid"); if (node != null) { seriesId = node.InnerText; } } } seriesInfo.ProviderIds = new Dictionary<string, string> { { MetadataProviders.Tvdb.ToString(), seriesId }, { MetadataProviders.Imdb.ToString(), imdbId } }; } var tvdbSeries = await TvdbSeriesProvider.Current.GetMetadata(seriesInfo, cancellationToken); seriesItem = tvdbSeries.Item; Cache.Add(epg.Title, seriesItem, DateTimeOffset.Now.AddDays(1)); } else seriesItem = Cache[epg.Title] as MediaBrowser.Controller.Entities.TV.Series; seriesId = seriesItem.GetProviderId(MetadataProviders.Tvdb); seriesDataPath = TvdbSeriesProvider.GetSeriesDataPath( LiveTvService.Config.ApplicationPaths, new Dictionary<string, string> { { MetadataProviders.Tvdb.ToString(), seriesId } }); Logger.Debug("seriesDataPath: " + seriesDataPath); foreach (var providerId in seriesItem.ProviderIds) { Logger.Debug("providerId: " + providerId); } epg.EpisodeId = seriesItem.Id.ToString(); epg.Etag = seriesItem.ExternalEtag; epg.Name = !String.IsNullOrEmpty(seriesItem.Name) ? seriesItem.Name : epg.Title; epg.Name = !String.IsNullOrEmpty(seriesItem.OriginalTitle) ? seriesItem.OriginalTitle : epg.Name; epg.OriginalAirDate = seriesItem.PremiereDate; epg.ProductionYear = seriesItem.ProductionYear; epg.SeriesId = seriesId; epg.Overview = seriesItem.Overview; epg.Genres = seriesItem.Genres; epg.OfficialRating = seriesItem.OfficialRating; epg.CommunityRating = seriesItem.CommunityRating; epg.ProviderIds = seriesItem.ProviderIds; epg.IsSeries = true; epg.IsMovie = false; epg.IsSports = false; epg.IsNews = false; epg.IsKids = seriesItem.Genres.Any(a => a.Contains(Constant.Genre.Kids) || a.Contains(Constant.Genre.Children)); epg.IsSports = seriesItem.Genres.Any(a => a.Contains(Constant.Genre.Sports)); epg.IsRepeat = seriesItem.PremiereDate == null || seriesItem.PremiereDate < DateTime.UtcNow.AddDays(-7); } catch (Exception exception) { //Logger.Error("Series provider error: " + exception.Message); //Logger.ErrorException("Series provider error", exception); } try { if (seriesItem != null && epg != null && epg.SeasonNumber > 0 && epg.EpisodeNumber > 0) { var episodeInfo = new EpisodeInfo { ParentIndexNumber = epg.SeasonNumber, IndexNumber = epg.EpisodeNumber, SeriesProviderIds = seriesItem.ProviderIds, MetadataLanguage = seriesItem.GetPreferredMetadataLanguage(), MetadataCountryCode = seriesItem.GetPreferredMetadataCountryCode() }; var tvdbEpisode = await TvdbEpisodeProvider.Current.GetMetadata(episodeInfo, cancellationToken); var episode = tvdbEpisode.Item; if (episode != null) { epg.EpisodeId = episode.Id.ToString(); epg.Etag = episode.ExternalEtag; epg.EpisodeTitle = episode.Name; epg.OriginalAirDate = episode.PremiereDate; epg.Overview = episode.Overview; epg.ProviderIds = episode.ProviderIds; epg.IsRepeat = episode.PremiereDate == null || episode.PremiereDate < DateTime.UtcNow.AddDays(-7); } else { Logger.Debug("episode null"); } } } catch (Exception exception) { //Logger.Error("Series episode error: " + exception.Message); //Logger.ErrorException("Series episode provider error", exception); } try { if (seriesItem != null && epg != null && !String.IsNullOrWhiteSpace(seriesId)) { var imageProvider = new FanartSeriesProvider(LiveTvService.Config, LiveTvService.HttpClient, LiveTvService.FileSystem, LiveTvService.JsonSerializer); var images = await imageProvider.GetImages(seriesItem, cancellationToken); if (images.Count(c => c.Type == ImageType.Primary) == 0) { var tvdbSeriesImageProvider = new TvdbSeriesImageProvider(LiveTvService.Config, LiveTvService.HttpClient, LiveTvService.FileSystem); images = await tvdbSeriesImageProvider.GetImages(seriesItem, cancellationToken); } var image = images.OrderByDescending(o => o.VoteCount).FirstOrDefault(q => q.Type == ImageType.Primary && q.Language == language); epg.ImageUrl = image != null ? image.Url : null; } } catch (Exception exception) { //Logger.Error("Series image error: " + exception.Message); //Logger.ErrorException("Series image provider error", exception); } return epg; }, cancellationToken); }
public OmdbEpisodeProvider(IJsonSerializer jsonSerializer, IHttpClient httpClient, ILogger logger, ILibraryManager libraryManager) { _jsonSerializer = jsonSerializer; _httpClient = httpClient; _itemProvider = new OmdbItemProvider(jsonSerializer, httpClient, logger, libraryManager); }