예제 #1
0
        public FanartSeriesProvider(IServerConfigurationManager config, IHttpClient httpClient, IFileSystem fileSystem)
        {
            _config     = config;
            _httpClient = httpClient;
            _fileSystem = fileSystem;

            Current = this;
        }
        public FanartSeriesProvider(IServerConfigurationManager config, IHttpClient httpClient, IFileSystem fileSystem)
        {
            _config = config;
            _httpClient = httpClient;
            _fileSystem = fileSystem;

            Current = this;
        }
예제 #3
0
        public FanartSeriesProvider(IServerConfigurationManager config, IHttpClient httpClient, IFileSystem fileSystem, IJsonSerializer json)
        {
            _config = config;
            _httpClient = httpClient;
            _fileSystem = fileSystem;
            _json = json;

            Current = this;
        }
예제 #4
0
        public FanartSeriesProvider(IServerConfigurationManager config, IHttpClient httpClient, IFileSystem fileSystem, IJsonSerializer json)
        {
            _config     = config;
            _httpClient = httpClient;
            _fileSystem = fileSystem;
            _json       = json;

            Current = this;
        }
        /// <summary>
        /// Runs the specified progress.
        /// </summary>
        /// <param name="progress">The progress.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>Task.</returns>
        public async Task Run(IProgress <double> progress, CancellationToken cancellationToken)
        {
            var options = FanartSeriesProvider.Current.GetFanartOptions();

            if (!options.EnableAutomaticUpdates)
            {
                progress.Report(100);
                return;
            }

            var path = FanartSeriesProvider.GetSeriesDataPath(_config.CommonApplicationPaths);

            _fileSystem.CreateDirectory(path);

            var timestampFile = Path.Combine(path, "time.txt");

            var timestampFileInfo = _fileSystem.GetFileInfo(timestampFile);

            // Don't check for updates every single time
            if (timestampFileInfo.Exists && (DateTime.UtcNow - _fileSystem.GetLastWriteTimeUtc(timestampFileInfo)).TotalDays < 3)
            {
                return;
            }

            // Find out the last time we queried for updates
            var lastUpdateTime = timestampFileInfo.Exists ? _fileSystem.ReadAllText(timestampFile, Encoding.UTF8) : string.Empty;

            var existingDirectories = Directory.EnumerateDirectories(path).Select(Path.GetFileName).ToList();

            // If this is our first time, don't do any updates and just record the timestamp
            if (!string.IsNullOrEmpty(lastUpdateTime))
            {
                var seriesToUpdate = await GetSeriesIdsToUpdate(existingDirectories, lastUpdateTime, options, cancellationToken).ConfigureAwait(false);

                progress.Report(5);

                await UpdateSeries(seriesToUpdate, progress, cancellationToken).ConfigureAwait(false);
            }

            var newUpdateTime = Convert.ToInt64(DateTimeToUnixTimestamp(DateTime.UtcNow)).ToString(UsCulture);

            _fileSystem.WriteAllText(timestampFile, newUpdateTime, Encoding.UTF8);

            progress.Report(100);
        }
예제 #6
0
 private void AddImages(List<RemoteImageInfo> list, FanartSeriesProvider.RootObject obj, int seasonNumber, CancellationToken cancellationToken)
 {
     PopulateImages(list, obj.seasonposter, ImageType.Primary, 1000, 1426, seasonNumber);
     PopulateImages(list, obj.seasonbanner, ImageType.Banner, 1000, 185, seasonNumber);
     PopulateImages(list, obj.seasonthumb, ImageType.Thumb, 500, 281, seasonNumber);
     PopulateImages(list, obj.showbackground, ImageType.Backdrop, 1920, 1080, seasonNumber);
 }
예제 #7
0
        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);
        }