From a3c3fff39f64c5966cb18616dcb444ee0135df87 Mon Sep 17 00:00:00 2001 From: Alex Stevens Date: Tue, 31 May 2016 23:00:20 +0100 Subject: [PATCH 1/3] Added first stab at a XmlTvListingsProvider --- .../LiveTv/Listings/XmlTv.cs | 44 --------- .../LiveTv/Listings/XmlTvListingsProvider.cs | 95 +++++++++++++++++++ ...MediaBrowser.Server.Implementations.csproj | 2 +- 3 files changed, 96 insertions(+), 45 deletions(-) delete mode 100644 MediaBrowser.Server.Implementations/LiveTv/Listings/XmlTv.cs create mode 100644 MediaBrowser.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs diff --git a/MediaBrowser.Server.Implementations/LiveTv/Listings/XmlTv.cs b/MediaBrowser.Server.Implementations/LiveTv/Listings/XmlTv.cs deleted file mode 100644 index ac316f9a12..0000000000 --- a/MediaBrowser.Server.Implementations/LiveTv/Listings/XmlTv.cs +++ /dev/null @@ -1,44 +0,0 @@ -using MediaBrowser.Controller.LiveTv; -using MediaBrowser.Model.Dto; -using MediaBrowser.Model.LiveTv; -using System; -using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; - -namespace MediaBrowser.Server.Implementations.LiveTv.Listings -{ - public class XmlTv : IListingsProvider - { - public string Name - { - get { return "XmlTV"; } - } - - public string Type - { - get { return "xmltv"; } - } - - public Task> GetProgramsAsync(ListingsProviderInfo info, string channelNumber, string channelName, DateTime startDateUtc, DateTime endDateUtc, CancellationToken cancellationToken) - { - throw new NotImplementedException(); - } - - public async Task AddMetadata(ListingsProviderInfo info, List channels, CancellationToken cancellationToken) - { - // Might not be needed - } - - public async Task Validate(ListingsProviderInfo info, bool validateLogin, bool validateListings) - { - // Check that the path or url is valid. If not, throw a file not found exception - } - - public Task> GetLineups(ListingsProviderInfo info, string country, string location) - { - // In theory this should never be called because there is always only one lineup - throw new NotImplementedException(); - } - } -} diff --git a/MediaBrowser.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs b/MediaBrowser.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs new file mode 100644 index 0000000000..ef596e5337 --- /dev/null +++ b/MediaBrowser.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs @@ -0,0 +1,95 @@ +using MediaBrowser.Controller.LiveTv; +using MediaBrowser.Model.Dto; +using MediaBrowser.Model.LiveTv; +using System; +using System.Linq; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; + +using Emby.XmlTv.Classes; +using System.IO; + +namespace MediaBrowser.Server.Implementations.LiveTv.Listings +{ + public class XmlTvListingsProvider : IListingsProvider + { + private string _filePath = "C:\\Temp\\"; + private string _language = null; + + public string Name + { + get { return "XmlTV"; } + } + + public string Type + { + get { return "xmltv"; } + } + + // TODO: Should this method be async? + public Task> GetProgramsAsync(ListingsProviderInfo info, string channelNumber, string channelName, DateTime startDateUtc, DateTime endDateUtc, CancellationToken cancellationToken) + { + var reader = new XmlTvReader(_filePath, _language, null); + var results = reader.GetProgrammes(channelNumber, startDateUtc, endDateUtc, cancellationToken); + return Task.FromResult(results.Select(p => new ProgramInfo() + { + ChannelId = p.ChannelId, + //CommunityRating = p.Rating., + EndDate = 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 = p.StartDate, + Name = p.Title, + Overview = p.Description, + // OfficialRating = p.OfficialRating, + ShortOverview = p.Description, + ProductionYear = !p.CopyrightDate.HasValue ? (int?)null : p.CopyrightDate.Value.Year, + SeasonNumber = p.Episode == null ? null : p.Episode.Series, + IsSeries = p.IsSeries, + IsRepeat = p.IsRepeat, + IsPremiere = !p.PreviouslyShown.HasValue, + })); + } + + public async Task AddMetadata(ListingsProviderInfo info, List channels, CancellationToken cancellationToken) + { + // Add the channel image url + var reader = new XmlTvReader(_filePath, _language, null); + var results = reader.GetChannels().ToList(); + + if (channels != null && channels.Count > 0) + { + channels.ForEach(c => { + var match = results.FirstOrDefault(r => r.Id == c.Id); + if (match != null) + { + // c.ImageUrl = match.Url; + // TODO: Add support for the channel logo to the XMLTv Component + } + }); + } + } + + public async Task Validate(ListingsProviderInfo info, bool validateLogin, bool validateListings) + { + // Check that the path or url is valid. If not, throw a file not found exception + if (!File.Exists(_filePath)) + { + throw new FileNotFoundException("Could not find the XmlTv file specified", _filePath); + } + } + + public Task> GetLineups(ListingsProviderInfo info, string country, string location) + { + // In theory this should never be called because there is always only one lineup + var reader = new XmlTvReader(_filePath, _language, null); + var results = reader.GetChannels(); + + // Should this method be async? + return Task.FromResult(results.Select(c => new NameIdPair() { Id = c.Id, Name = c.DisplayName }).ToList()); + } + } +} \ No newline at end of file diff --git a/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj b/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj index 385a94aa5c..a27b12a893 100644 --- a/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj +++ b/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj @@ -232,7 +232,7 @@ - + From bd001d8c6ae58fce073db4822c706e058730d9ff Mon Sep 17 00:00:00 2001 From: Alex Stevens Date: Wed, 1 Jun 2016 19:44:19 +0100 Subject: [PATCH 2/3] Added Channel and Program Images and Category Mapping --- .../LiveTv/Listings/XmlTvListingsProvider.cs | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/MediaBrowser.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs b/MediaBrowser.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs index ef596e5337..2c56b9a997 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs @@ -2,13 +2,13 @@ using MediaBrowser.Model.Dto; using MediaBrowser.Model.LiveTv; using System; -using System.Linq; using System.Collections.Generic; +using System.IO; +using System.Linq; using System.Threading; using System.Threading.Tasks; using Emby.XmlTv.Classes; -using System.IO; namespace MediaBrowser.Server.Implementations.LiveTv.Listings { @@ -16,6 +16,12 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings { private string _filePath = "C:\\Temp\\"; private string _language = null; + private Dictionary> _categoryMappings = new Dictionary>(){ + { "Movie", new List() { "Movie", "Film" } }, + { "Sports", new List() { "Sports", "Football", "Rugby", "Soccer" } }, + { "Kids", new List() { "Childrens", "Children", "Kids", "Disney" } }, + { "News", new List() { "News", "Journalism", "Documentary", "Current Affairs" } }, + }; public string Name { @@ -51,6 +57,12 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings IsSeries = p.IsSeries, IsRepeat = p.IsRepeat, IsPremiere = !p.PreviouslyShown.HasValue, + IsKids = p.Categories.Any(_categoryMappings["Kids"].Contains), + IsMovie = p.Categories.Any(_categoryMappings["Movie"].Contains), + IsNews = p.Categories.Any(_categoryMappings["News"].Contains), + IsSports = p.Categories.Any(_categoryMappings["Sports"].Contains), + ImageUrl = p.Icon != null && !String.IsNullOrEmpty(p.Icon.Source) ? p.Icon.Source : null, + HasImage = p.Icon != null && !String.IsNullOrEmpty(p.Icon.Source), })); } @@ -64,10 +76,9 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings { channels.ForEach(c => { var match = results.FirstOrDefault(r => r.Id == c.Id); - if (match != null) + if (match != null && match.Icon != null && !String.IsNullOrEmpty(match.Icon.Source)) { - // c.ImageUrl = match.Url; - // TODO: Add support for the channel logo to the XMLTv Component + c.ImageUrl = match.Icon.Source; } }); } From 767de9aa1e8da5a7cecc7f72259559751c317c4f Mon Sep 17 00:00:00 2001 From: Alex Stevens Date: Sun, 5 Jun 2016 21:53:21 +0100 Subject: [PATCH 3/3] More updates to the XmlTVListingsProvider --- .../LiveTv/Listings/XmlTvListingsProvider.cs | 46 ++++++++++++------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/MediaBrowser.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs b/MediaBrowser.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs index 2c56b9a997..c5060944d2 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs @@ -14,13 +14,20 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings { public class XmlTvListingsProvider : IListingsProvider { - private string _filePath = "C:\\Temp\\"; private string _language = null; private Dictionary> _categoryMappings = new Dictionary>(){ { "Movie", new List() { "Movie", "Film" } }, - { "Sports", new List() { "Sports", "Football", "Rugby", "Soccer" } }, - { "Kids", new List() { "Childrens", "Children", "Kids", "Disney" } }, - { "News", new List() { "News", "Journalism", "Documentary", "Current Affairs" } }, + //{ "Sports", new List() { "Sports", "Football", "Rugby", "Soccer" } }, + //{ "Kids", new List() { "Childrens", "Children", "Kids", "Disney" } }, + //{ "News", new List() { "News", "Journalism", "Documentary", "Current Affairs" } }, + }; + + private Dictionary _channelMappings = new Dictionary(){ + { "1", "UK_RT_2667" }, + { "2", "UK_RT_116" }, + { "3", "UK_RT_2118" }, + { "4", "UK_RT_2056" }, + { "5", "UK_RT_134" } }; public string Name @@ -36,12 +43,18 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings // TODO: Should this method be async? public Task> GetProgramsAsync(ListingsProviderInfo info, string channelNumber, string channelName, DateTime startDateUtc, DateTime endDateUtc, CancellationToken cancellationToken) { - var reader = new XmlTvReader(_filePath, _language, null); - var results = reader.GetProgrammes(channelNumber, startDateUtc, endDateUtc, cancellationToken); + var reader = new XmlTvReader(info.Path, _language, null); + string mappedChannel = channelNumber; + + if (_channelMappings.ContainsKey(channelNumber)) + { + mappedChannel = _channelMappings[channelNumber]; + } + + var results = reader.GetProgrammes(mappedChannel, startDateUtc, endDateUtc, cancellationToken); return Task.FromResult(results.Select(p => new ProgramInfo() { ChannelId = p.ChannelId, - //CommunityRating = p.Rating., EndDate = p.EndDate, EpisodeNumber = p.Episode == null ? null : p.Episode.Episode, EpisodeTitle = p.Episode == null ? null : p.Episode.Title, @@ -50,26 +63,27 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings StartDate = p.StartDate, Name = p.Title, Overview = p.Description, - // OfficialRating = p.OfficialRating, ShortOverview = p.Description, ProductionYear = !p.CopyrightDate.HasValue ? (int?)null : p.CopyrightDate.Value.Year, SeasonNumber = p.Episode == null ? null : p.Episode.Series, IsSeries = p.IsSeries, IsRepeat = p.IsRepeat, - IsPremiere = !p.PreviouslyShown.HasValue, - IsKids = p.Categories.Any(_categoryMappings["Kids"].Contains), + // IsPremiere = !p.PreviouslyShown.HasValue, + IsKids = p.Categories.Any(info.KidsGenres.Contains), IsMovie = p.Categories.Any(_categoryMappings["Movie"].Contains), - IsNews = p.Categories.Any(_categoryMappings["News"].Contains), - IsSports = p.Categories.Any(_categoryMappings["Sports"].Contains), + IsNews = p.Categories.Any(info.NewsGenres.Contains), + IsSports = p.Categories.Any(info.SportsGenres.Contains), 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 })); } public async Task AddMetadata(ListingsProviderInfo info, List channels, CancellationToken cancellationToken) { // Add the channel image url - var reader = new XmlTvReader(_filePath, _language, null); + var reader = new XmlTvReader(info.Path, _language, null); var results = reader.GetChannels().ToList(); if (channels != null && channels.Count > 0) @@ -87,16 +101,16 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings public async Task Validate(ListingsProviderInfo info, bool validateLogin, bool validateListings) { // Check that the path or url is valid. If not, throw a file not found exception - if (!File.Exists(_filePath)) + if (!File.Exists(info.Path)) { - throw new FileNotFoundException("Could not find the XmlTv file specified", _filePath); + throw new FileNotFoundException("Could not find the XmlTv file specified:", info.Path); } } public Task> GetLineups(ListingsProviderInfo info, string country, string location) { // In theory this should never be called because there is always only one lineup - var reader = new XmlTvReader(_filePath, _language, null); + var reader = new XmlTvReader(info.Path, _language, null); var results = reader.GetChannels(); // Should this method be async?