Ejemplo n.º 1
0
        public async Task <IEnumerable <ProgramInfo> > GetProgramsAsync(ListingsProviderInfo info, string channelNumber, string channelName, DateTime startDateUtc, DateTime endDateUtc, CancellationToken cancellationToken)
        {
            if (!await EmbyTV.EmbyTVRegistration.Instance.EnableXmlTv().ConfigureAwait(false))
            {
                var length = endDateUtc - startDateUtc;
                if (length.TotalDays > 1)
                {
                    endDateUtc = startDateUtc.AddDays(1);
                }
            }

            var path = await GetXml(info.Path, cancellationToken).ConfigureAwait(false);

            var reader = new XmlTvReader(path, GetLanguage(), null);

            var results = reader.GetProgrammes(channelNumber, startDateUtc, endDateUtc, cancellationToken);

            return(results.Select(p => new ProgramInfo()
            {
                ChannelId = p.ChannelId,
                EndDate = GetDate(p.EndDate),
                EpisodeNumber = p.Episode == null ? null : p.Episode.Episode,
                EpisodeTitle = p.Episode == null ? null : p.Episode.Title,
                Genres = p.Categories,
                Id = String.Format("{0}_{1:O}", p.ChannelId, p.StartDate), // Construct an id from the channel and start date,
                StartDate = GetDate(p.StartDate),
                Name = p.Title,
                Overview = p.Description,
                ShortOverview = p.Description,
                ProductionYear = !p.CopyrightDate.HasValue ? (int?)null : p.CopyrightDate.Value.Year,
                SeasonNumber = p.Episode == null ? null : p.Episode.Series,
                IsSeries = p.Episode != null,
                IsRepeat = p.IsRepeat,
                IsPremiere = p.Premiere != null,
                IsKids = p.Categories.Any(c => info.KidsCategories.Contains(c, StringComparer.InvariantCultureIgnoreCase)),
                IsMovie = p.Categories.Any(c => info.MovieCategories.Contains(c, StringComparer.InvariantCultureIgnoreCase)),
                IsNews = p.Categories.Any(c => info.NewsCategories.Contains(c, StringComparer.InvariantCultureIgnoreCase)),
                IsSports = p.Categories.Any(c => info.SportsCategories.Contains(c, StringComparer.InvariantCultureIgnoreCase)),
                ImageUrl = p.Icon != null && !String.IsNullOrEmpty(p.Icon.Source) ? p.Icon.Source : null,
                HasImage = p.Icon != null && !String.IsNullOrEmpty(p.Icon.Source),
                OfficialRating = p.Rating != null && !String.IsNullOrEmpty(p.Rating.Value) ? p.Rating.Value : null,
                CommunityRating = p.StarRating.HasValue ? p.StarRating.Value : (float?)null,
                SeriesId = p.Episode != null ? p.Title.GetMD5().ToString("N") : null
            }));
        }
Ejemplo n.º 2
0
        public async Task <List <ChannelInfo> > GetChannels(ListingsProviderInfo info, CancellationToken cancellationToken)
        {
            // In theory this should never be called because there is always only one lineup
            string path = await GetXml(info.Path, cancellationToken).ConfigureAwait(false);

            _logger.LogDebug("Opening XmlTvReader for {Path}", path);
            var reader  = new XmlTvReader(path, GetLanguage(info));
            var results = reader.GetChannels();

            // Should this method be async?
            return(results.Select(c => new ChannelInfo
            {
                Id = c.Id,
                Name = c.DisplayName,
                ImageUrl = c.Icon != null && !string.IsNullOrEmpty(c.Icon.Source) ? c.Icon.Source : null,
                Number = string.IsNullOrWhiteSpace(c.Number) ? c.Id : c.Number
            }).ToList());
        }
Ejemplo n.º 3
0
        public void Should_Return_The_First_Matching_With_Empty_Language()
        {
            var testFile = Path.GetFullPath(@"MultilanguageData.xml");
            var reader   = new XmlTvReader(testFile, String.Empty);

            var channel = reader.GetChannels().FirstOrDefault();

            Assert.IsNotNull(channel);

            var startDate         = new DateTime(2015, 11, 26);
            var cancellationToken = new CancellationToken();
            var programme         = reader.GetProgrammes(channel.Id, startDate, startDate.AddDays(1), cancellationToken).FirstOrDefault();

            Assert.IsNotNull(programme);
            Assert.AreEqual("Homes Under the Hammer - Empty Language", programme.Title);
            Assert.AreEqual(1, programme.Categories.Count);
            Assert.AreEqual("Property - Empty Language", programme.Categories[0]);
        }
Ejemplo n.º 4
0
        public void UK_DataTest_MultipleTitles_NoLanguage_Should_ReturnFirstValue()
        {
            var testFile = Path.GetFullPath(@"UK_Data.xml");
            var reader   = new XmlTvReader(testFile, null);

            /*
             *  <title>Oxford Street Revealed - Title 1</title>
             *  <title>Oxford Street Revealed - Title 2</title>
             *  <title>Oxford Street Revealed - Title 3</title>
             */

            var startDate         = new DateTime(2015, 11, 26);
            var cancellationToken = new CancellationToken();
            var programmes        = reader.GetProgrammes("UK_RT_2667", startDate, startDate.AddDays(1), cancellationToken).ToList();
            var programme         = programmes.SingleOrDefault(p => p.Title == "Oxford Street Revealed - Title 1");

            Assert.IsNotNull(programme);
        }
Ejemplo n.º 5
0
        public void UKDataMultipleTitlesNoLanguageFirstValueTest()
        {
            var testFile = Path.Join("Test Data", "UK_Data.xml");
            var reader   = new XmlTvReader(testFile, null);

            /*
             *  <title>Oxford Street Revealed - Title 1</title>
             *  <title>Oxford Street Revealed - Title 2</title>
             *  <title>Oxford Street Revealed - Title 3</title>
             */

            var startDate         = new DateTimeOffset(2015, 11, 26, 0, 0, 0, new TimeSpan());
            var cancellationToken = new CancellationToken();
            var programmes        = reader.GetProgrammes("UK_RT_2667", startDate, startDate.AddDays(1), cancellationToken).ToList();
            var programme         = programmes.SingleOrDefault(p => p.Title == "Oxford Street Revealed - Title 1");

            Assert.NotNull(programme);
        }
Ejemplo n.º 6
0
        public async Task <IEnumerable <ProgramInfo> > GetProgramsAsync(ListingsProviderInfo info, string channelNumber, string channelName, DateTime startDateUtc, DateTime endDateUtc, CancellationToken cancellationToken)
        {
            if (!await EmbyTV.EmbyTVRegistration.Instance.EnableXmlTv().ConfigureAwait(false))
            {
                var length = endDateUtc - startDateUtc;
                if (length.TotalDays > 1)
                {
                    endDateUtc = startDateUtc.AddDays(1);
                }
            }

            var path = await GetXml(info.Path, cancellationToken).ConfigureAwait(false);

            var reader = new XmlTvReader(path, GetLanguage());

            var results = reader.GetProgrammes(channelNumber, startDateUtc, endDateUtc, cancellationToken);

            return(results.Select(p => GetProgramInfo(p, info)));
        }
Ejemplo n.º 7
0
        public void FirstNoMatchFoundTest()
        {
            var testFile = Path.Join("Test Data", "MultilanguageData.xml");
            var reader = new XmlTvReader(testFile, "es"); // There are no titles or categories for spanish

            var channel = reader.GetChannels().FirstOrDefault();
            Assert.NotNull(channel);

            var startDate = new DateTime(2015, 11, 26);
            var cancellationToken = new CancellationToken();
            var programme = reader.GetProgrammes(channel.Id, startDate, startDate.AddDays(1), cancellationToken).Skip(1).FirstOrDefault();

            Assert.NotNull(programme);
            Assert.Equal("Homes Under the Hammer - No Language", programme.Title);

            // Should return all categories
            Assert.Equal(2, programme.Categories.Count);
            Assert.Contains("Property - English", programme.Categories);
            Assert.Contains("Property - Empty Language", programme.Categories);
        }
        public void FirstNoLanguageTest()
        {
            var testFile = Path.Join("Test Data", "MultilanguageData.xml");
            var reader   = new XmlTvReader(testFile, null);

            var channel = reader.GetChannels().FirstOrDefault();

            Assert.NotNull(channel);

            var startDate = new DateTime(2015, 11, 26);
            var programme = reader.GetProgrammes(channel !.Id, startDate, startDate.AddDays(1)).Skip(1).FirstOrDefault();

            Assert.NotNull(programme);
            Assert.Equal("Homes Under the Hammer - No Language", programme !.Title); // Should return the first in the list

            // Should return all categories
            Assert.Equal(2, programme.Categories.Count);
            Assert.Contains("Property - English", programme.Categories);
            Assert.Contains("Property - Empty Language", programme.Categories);
        }
Ejemplo n.º 9
0
        public void Should_Return_All_Languages()
        {
            var testFile          = Path.GetFullPath(@"MultilanguageData.xml");
            var reader            = new XmlTvReader(testFile);
            var cancellationToken = new CancellationToken();

            var results = reader.GetLanguages(cancellationToken);

            Assert.IsNotNull(results);

            foreach (var result in results)
            {
                Console.WriteLine("{0} - {1}", result.Name, result.Relevance);
            }

            Assert.AreEqual(2, results.Count);
            Assert.AreEqual("en", results[0].Name);
            Assert.AreEqual(11, results[0].Relevance);
            Assert.AreEqual("es", results[1].Name);
            Assert.AreEqual(3, results[1].Relevance);
        }
Ejemplo n.º 10
0
        public void Should_Return_The_First_When_NoLanguage()
        {
            var testFile = Path.GetFullPath(@"MultilanguageData.xml");
            var reader   = new XmlTvReader(testFile, null);

            var channel = reader.GetChannels().FirstOrDefault();

            Assert.IsNotNull(channel);

            var startDate         = new DateTime(2015, 11, 26);
            var cancellationToken = new CancellationToken();
            var programme         = reader.GetProgrammes(channel.Id, startDate, startDate.AddDays(1), cancellationToken).Skip(1).FirstOrDefault();

            Assert.IsNotNull(programme);
            Assert.AreEqual("Homes Under the Hammer - English", programme.Title); // Should return the first in the list

            // Should return all categories
            Assert.AreEqual(2, programme.Categories.Count);
            Assert.IsTrue(programme.Categories.Contains("Property - English"));
            Assert.IsTrue(programme.Categories.Contains("Property - Empty Language"));
        }
Ejemplo n.º 11
0
        public async Task AddMetadata(ListingsProviderInfo info, List <ChannelInfo> channels, CancellationToken cancellationToken)
        {
            // Add the channel image url
            var path = await GetXml(info.Path, cancellationToken).ConfigureAwait(false);

            var reader  = new XmlTvReader(path, GetLanguage());
            var results = reader.GetChannels().ToList();

            if (channels != null)
            {
                foreach (var c in channels)
                {
                    var channelNumber = info.GetMappedChannel(c.Number);
                    var match         = results.FirstOrDefault(r => string.Equals(r.Id, channelNumber, StringComparison.OrdinalIgnoreCase));

                    if (match != null && match.Icon != null && !String.IsNullOrEmpty(match.Icon.Source))
                    {
                        c.ImageUrl = match.Icon.Source;
                    }
                }
            }
        }
Ejemplo n.º 12
0
        public void SchedulesDirectTest()
        {
            var testFile = Path.Join("Test Data", "schedulesdirect.xml");
            var reader   = new XmlTvReader(testFile, null);

            var channels = reader.GetChannels().ToList();

            // Pick a channel to check the data for
            var channel = channels.SingleOrDefault(c => c.Id == "EPG123.10108.schedulesdirect.org"); // CTV Toronto

            Assert.NotNull(channel);

            var startDate  = new DateTimeOffset(2020, 07, 29, 0, 0, 0, new TimeSpan());
            var programmes = reader.GetProgrammes(channel !.Id, startDate, startDate.AddDays(1)).ToList();

            var programme = programmes.SingleOrDefault(p => p.Title == "Match Game");

            Assert.NotNull(programme !.Episode);
            Assert.True(programme.Credits.Count == 9);

            Assert.NotNull(programme.Icon);
            Assert.True(programme !.Icon !.Width > programme.Icon.Height);
        }
Ejemplo n.º 13
0
        public void UK_DataTest_GeneralTest()
        {
            var testFile = Path.GetFullPath(@"UK_Data.xml");
            var reader   = new XmlTvReader(testFile, null);

            var channels = reader.GetChannels().ToList();

            Assert.AreEqual(5, channels.Count);

            // Pick a channel to check the data for
            var channel = channels.SingleOrDefault(c => c.Id == "UK_RT_2056");

            Assert.IsNotNull(channel);

            var startDate         = new DateTime(2015, 11, 26);
            var cancellationToken = new CancellationToken();
            var programmes        = reader.GetProgrammes(channel.Id, startDate, startDate.AddDays(1), cancellationToken).ToList();

            Assert.AreEqual(27, programmes.Count);
            var programme = programmes.SingleOrDefault(p => p.Title == "The Secret Life of");

            Assert.IsNotNull(programme);
            Assert.AreEqual(new DateTime(2015, 11, 26, 20, 0, 0), programme.StartDate);
            Assert.AreEqual(new DateTime(2015, 11, 26, 21, 0, 0), programme.EndDate);
            Assert.AreEqual("Cameras follow the youngsters' development after two weeks apart and time has made the heart grow fonder for Alfie and Emily, who are clearly happy to be back together. And although Alfie struggled to empathise with the rest of his peers before, a painting competition proves to be a turning point for him. George takes the children's rejection of his family recipe to heart, but goes on to triumph elsewhere, and romance is in the air when newcomer Sienna captures Arthur's heart.", programme.Description);
            Assert.AreEqual("Documentary", programme.Categories.Single());
            Assert.IsNotNull(programme.Episode);
            Assert.AreEqual("The Secret Life of 5 Year Olds", programme.Episode.Title);
            Assert.AreEqual(1, programme.Episode.Series);
            Assert.IsNull(programme.Episode.SeriesCount);
            Assert.AreEqual(4, programme.Episode.Episode);
            Assert.AreEqual(6, programme.Episode.EpisodeCount);
            Assert.IsNotNull(programme.Premiere);
            //Assert.AreEqual("First showing on national terrestrial TV", programme.Premiere.Details);
            Assert.IsTrue(programme.IsNew);
        }