diff options
| author | Alex Stevens <ads@chubbymusic.co.uk> | 2016-05-31 23:00:20 +0100 |
|---|---|---|
| committer | Alex Stevens <ads@chubbymusic.co.uk> | 2016-05-31 23:00:20 +0100 |
| commit | a3c3fff39f64c5966cb18616dcb444ee0135df87 (patch) | |
| tree | 88fa675ee53bbf1ee834d646150e14d30c4edcc7 | |
| parent | 0915d1f3836844afcb432b1a9ed8386f7d1b63c0 (diff) | |
Added first stab at a XmlTvListingsProvider
3 files changed, 96 insertions, 45 deletions
diff --git a/MediaBrowser.Server.Implementations/LiveTv/Listings/XmlTv.cs b/MediaBrowser.Server.Implementations/LiveTv/Listings/XmlTv.cs deleted file mode 100644 index ac316f9a1..000000000 --- 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<IEnumerable<ProgramInfo>> GetProgramsAsync(ListingsProviderInfo info, string channelNumber, string channelName, DateTime startDateUtc, DateTime endDateUtc, CancellationToken cancellationToken) - { - throw new NotImplementedException(); - } - - public async Task AddMetadata(ListingsProviderInfo info, List<ChannelInfo> 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<List<NameIdPair>> 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 000000000..ef596e533 --- /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<IEnumerable<ProgramInfo>> 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<ChannelInfo> 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<List<NameIdPair>> 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 385a94aa5..a27b12a89 100644 --- a/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj +++ b/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj @@ -232,7 +232,7 @@ <Compile Include="LiveTv\EmbyTV\SeriesTimerManager.cs" /> <Compile Include="LiveTv\EmbyTV\TimerManager.cs" /> <Compile Include="LiveTv\Listings\SchedulesDirect.cs" /> - <Compile Include="LiveTv\Listings\XmlTv.cs" /> + <Compile Include="LiveTv\Listings\XmlTvListingsProvider.cs" /> <Compile Include="LiveTv\LiveTvConfigurationFactory.cs" /> <Compile Include="LiveTv\LiveTvDtoService.cs" /> <Compile Include="LiveTv\LiveTvManager.cs" /> |
